Add assembly library to rule_based_toolchain example
Copybara Import from https://github.com/bazelbuild/rules_cc/pull/361
BEGIN_PUBLIC
Add assembly library to rule_based_toolchain example (#361)
Adds a cc_library that compiles a tiny assembly file to provide some coverage for assembly actions in the rule_based_toolchain example.
Closes #361
END_PUBLIC
COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_cc/pull/361 from armandomontanez:add_asm_to_toolchain_example d8ff1b7fc7fe03fbc53fed9d13b79bb5e1ac2351
PiperOrigin-RevId: 726085163
Change-Id: I86b0e47f59328b73f09c05c3208713fc4f279c73
diff --git a/examples/rule_based_toolchain/BUILD.bazel b/examples/rule_based_toolchain/BUILD.bazel
index bc09fb2..77be6bd 100644
--- a/examples/rule_based_toolchain/BUILD.bazel
+++ b/examples/rule_based_toolchain/BUILD.bazel
@@ -20,6 +20,7 @@
name = "quick_test",
srcs = ["quick_test.cc"],
deps = [
+ "//asm_answer",
"//dynamic_answer",
"//static_answer",
"@googletest//:gtest",
diff --git a/examples/rule_based_toolchain/asm_answer/BUILD.bazel b/examples/rule_based_toolchain/asm_answer/BUILD.bazel
new file mode 100644
index 0000000..7c47fe2
--- /dev/null
+++ b/examples/rule_based_toolchain/asm_answer/BUILD.bazel
@@ -0,0 +1,25 @@
+# Copyright 2025 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("@rules_cc//cc:cc_library.bzl", "cc_library")
+
+licenses(["notice"])
+
+cc_library(
+ name = "asm_answer",
+ srcs = ["asm_answer.S"],
+ hdrs = ["public/asm_answer.h"],
+ strip_include_prefix = "public",
+ visibility = ["//visibility:public"],
+)
diff --git a/examples/rule_based_toolchain/asm_answer/asm_answer.S b/examples/rule_based_toolchain/asm_answer/asm_answer.S
new file mode 100644
index 0000000..0455dee
--- /dev/null
+++ b/examples/rule_based_toolchain/asm_answer/asm_answer.S
@@ -0,0 +1,17 @@
+// Copyright 2025 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+.global asm_answer
+asm_answer:
+.int 0xFE4B67C4
diff --git a/examples/rule_based_toolchain/asm_answer/public/asm_answer.h b/examples/rule_based_toolchain/asm_answer/public/asm_answer.h
new file mode 100644
index 0000000..ba0c80c
--- /dev/null
+++ b/examples/rule_based_toolchain/asm_answer/public/asm_answer.h
@@ -0,0 +1,20 @@
+// Copyright 2025 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef ASM_ANSWER_PUBLIC_DYNAMIC_ANSWER_H_
+#define ASM_ANSWER_PUBLIC_DYNAMIC_ANSWER_H_
+
+extern "C" int asm_answer;
+
+#endif // asm_ANSWER_PUBLIC_DYNAMIC_ANSWER_H_
diff --git a/examples/rule_based_toolchain/quick_test.cc b/examples/rule_based_toolchain/quick_test.cc
index 80737dd..a50fded 100644
--- a/examples/rule_based_toolchain/quick_test.cc
+++ b/examples/rule_based_toolchain/quick_test.cc
@@ -14,6 +14,7 @@
#include <gtest/gtest.h>
+#include "asm_answer.h"
#include "dynamic_answer.h"
#include "static_answer.h"
@@ -24,3 +25,7 @@
TEST(Dynamic, ProperlyLinked) {
EXPECT_EQ(dynamic_answer(), 24);
}
+
+TEST(Asm, ProperlyLinked) {
+ EXPECT_EQ(asm_answer, 0xFE4B67C4);
+}