Use `target_compatible_with` to make `macos` with `Xcode` happy (#1391)
Bazel's default toolchain configuration does not support dynamic linking when the Xcode toolchain is used on `macos`. Some tests that target dynamic linking caused `bazel build //...` to fail for `rules_rust` developers that have Xcode installed.
This PR adds `target_compatible_with` to the relevant targets so that they are skipped on `macos`.
diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml
index 5c848a5..60131d4 100644
--- a/.bazelci/presubmit.yml
+++ b/.bazelci/presubmit.yml
@@ -9,8 +9,6 @@
default_macos_targets: &default_macos_targets
- "--"
- "//..."
- # TODO: CI toolchain does not support dynamic linking.
- - "-//test/linker_inputs_propagation/..."
default_windows_targets: &default_windows_targets
- "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245
- "//..."
diff --git a/test/linker_inputs_propagation/BUILD.bazel b/test/linker_inputs_propagation/BUILD.bazel
index d305ffb..5ff0945 100644
--- a/test/linker_inputs_propagation/BUILD.bazel
+++ b/test/linker_inputs_propagation/BUILD.bazel
@@ -20,6 +20,9 @@
"foo_shared.cc",
],
hdrs = ["foo_shared.h"],
+ target_compatible_with = [
+ "@platforms//os:linux",
+ ],
)
cc_binary(
@@ -30,6 +33,9 @@
],
features = ["windows_export_all_symbols"],
linkshared = True,
+ target_compatible_with = [
+ "@platforms//os:windows",
+ ],
)
filegroup(
@@ -44,16 +50,23 @@
output_group = "interface_library",
)
+filegroup(
+ name = "empty",
+ srcs = ["empty.so"],
+)
+
cc_import(
name = "import_foo_shared",
hdrs = ["foo_shared.h"],
interface_library = select({
+ "@platforms//os:linux": "shared_library_file",
"@platforms//os:windows": "interface_library_file",
- "//conditions:default": "shared_library_file",
+ "//conditions:default": ":empty",
}),
shared_library = select({
+ "@platforms//os:linux": "shared_library_file",
"@platforms//os:windows": "foo_shared.dll",
- "//conditions:default": "shared_library_file",
+ "//conditions:default": ":empty",
}),
)
@@ -61,6 +74,10 @@
name = "staticlib_uses_foo",
srcs = ["bar_uses_foo.rs"],
edition = "2018",
+ target_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//os:windows",
+ ],
deps = [":foo"],
)
@@ -68,6 +85,10 @@
name = "sharedlib_uses_foo",
srcs = ["bar_uses_foo.rs"],
edition = "2018",
+ target_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//os:windows",
+ ],
deps = [":foo"],
)
@@ -75,6 +96,10 @@
name = "staticlib_uses_shared_foo",
srcs = ["bar_uses_shared_foo.rs"],
edition = "2018",
+ target_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//os:windows",
+ ],
deps = [":import_foo_shared"],
)
@@ -82,29 +107,49 @@
name = "sharedlib_uses_shared_foo",
srcs = ["bar_uses_shared_foo.rs"],
edition = "2018",
+ target_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//os:windows",
+ ],
deps = [":import_foo_shared"],
)
cc_test(
name = "depends_on_foo_via_staticlib",
srcs = ["baz.cc"],
+ target_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//os:windows",
+ ],
deps = [":staticlib_uses_foo"],
)
cc_test(
name = "depends_on_foo_via_sharedlib",
srcs = ["baz.cc"],
+ target_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//os:windows",
+ ],
deps = [":sharedlib_uses_foo"],
)
cc_test(
name = "depends_on_shared_foo_via_sharedlib",
srcs = ["baz.cc"],
+ target_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//os:windows",
+ ],
deps = [":sharedlib_uses_shared_foo"],
)
cc_test(
name = "depends_on_shared_foo_via_staticlib",
srcs = ["baz.cc"],
+ target_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//os:windows",
+ ],
deps = [":staticlib_uses_shared_foo"],
)
diff --git a/test/linker_inputs_propagation/empty.so b/test/linker_inputs_propagation/empty.so
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/test/linker_inputs_propagation/empty.so
@@ -0,0 +1 @@
+