diff --git a/rust/platform/platform.bzl b/rust/platform/platform.bzl index f59eb0d155..0a5c4e12d6 100644 --- a/rust/platform/platform.bzl +++ b/rust/platform/platform.bzl @@ -23,7 +23,7 @@ _SUPPORTED_CPU_ARCH = [ _SUPPORTED_SYSTEMS = [ "android", - "darwin", + "macos", "freebsd", "ios", "linux", @@ -46,17 +46,17 @@ def declare_config_settings(): constraint_values = system_to_constraints(system), ) - # Add alias for OSX to "darwin" to match what users will be expecting. + # Add alias for OSX to "macos" to match what users will be expecting. native.alias( name = "osx", - actual = ":darwin", + actual = ":macos", ) - # Add alias for OSX to "macos" to be consistent with the long-term - # direction of `@platforms` in using the OS's modern name. + # Add alias for darwin to maintain backwards compatibility. native.alias( - name = "macos", - actual = ":darwin", + name = "darwin", + actual = ":macos", + deprecation = "Use `@rules_rust//rust/platform:macos` instead.", ) all_supported_triples = ALL_PLATFORM_TRIPLES @@ -115,7 +115,7 @@ def declare_config_settings(): name = "unix", match_any = [ ":android", - ":darwin", + ":macos", ":freebsd", ":linux", ":nto", diff --git a/rust/platform/triple.bzl b/rust/platform/triple.bzl index 096ec5ef41..28be805a4c 100644 --- a/rust/platform/triple.bzl +++ b/rust/platform/triple.bzl @@ -59,6 +59,9 @@ def triple(triple): system = "android" abi = "eabi" + if system == "darwin": + system = "macos" + if len(component_parts) == 4: abi = component_parts[3] diff --git a/rust/platform/triple_mappings.bzl b/rust/platform/triple_mappings.bzl index ded8608b24..692000d90b 100644 --- a/rust/platform/triple_mappings.bzl +++ b/rust/platform/triple_mappings.bzl @@ -143,6 +143,7 @@ _SYSTEM_TO_BUILTIN_SYS_SUFFIX = { "fuchsia": "fuchsia", "ios": "ios", "linux": "linux", + "macos": "osx", "nacl": None, "netbsd": None, "nixos": "nixos", @@ -167,6 +168,7 @@ _SYSTEM_TO_BINARY_EXT = { "fuchsia": "", "ios": "", "linux": "", + "macos": "", "nixos": "", "none": "", "nto": "", @@ -190,6 +192,7 @@ _SYSTEM_TO_STATICLIB_EXT = { "fuchsia": ".a", "ios": ".a", "linux": ".a", + "macos": ".a", "nixos": ".a", "none": ".a", "nto": ".a", @@ -210,6 +213,7 @@ _SYSTEM_TO_DYLIB_EXT = { "fuchsia": ".so", "ios": ".dylib", "linux": ".so", + "macos": ".dylib", "nixos": ".so", "none": ".so", "nto": ".a", @@ -253,6 +257,7 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = { "ios": ["-lSystem", "-lobjc", "-Wl,-framework,Security", "-Wl,-framework,Foundation", "-lresolv"], # TODO: This ignores musl. Longer term what does Bazel think about musl? "linux": ["-ldl", "-lpthread"], + "macos": ["-lSystem", "-lresolv"], "nacl": [], "netbsd": ["-lpthread", "-lrt"], "nixos": ["-ldl", "-lpthread"], # Same as `linux`. diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 2df648ba24..07f45a91f2 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -1339,7 +1339,7 @@ def rustc_compile_action( if toolchain.target_os == "windows" and compilation_mode.strip_level == "none": pdb_file = ctx.actions.declare_file(crate_info.output.basename[:-len(crate_info.output.extension)] + "pdb", sibling = crate_info.output) action_outputs.append(pdb_file) - elif toolchain.target_os == "darwin": + elif toolchain.target_os in ["macos", "darwin"]: dsym_folder = ctx.actions.declare_directory(crate_info.output.basename + ".dSYM", sibling = crate_info.output) action_outputs.append(dsym_folder) @@ -1844,7 +1844,7 @@ def _compute_rpaths(toolchain, output_dir, dep_info, use_pic): # without a version of Bazel that includes # https://github.com/bazelbuild/bazel/pull/13427. This is known to not be # included in Bazel 4.1 and below. - if toolchain.target_os not in ["linux", "darwin", "android"]: + if toolchain.target_os not in ["linux", "darwin", "macos", "android"]: fail("Runtime linking is not supported on {}, but found {}".format( toolchain.target_os, dep_info.transitive_noncrates, diff --git a/rust/repositories.bzl b/rust/repositories.bzl index 7b636859be..cb41a7de34 100644 --- a/rust/repositories.bzl +++ b/rust/repositories.bzl @@ -40,11 +40,11 @@ load_arbitrary_tool = _load_arbitrary_tool # Note: Code in `.github/workflows/crate_universe.yaml` looks for this line, if you remove it or change its format, you will also need to update that code. DEFAULT_TOOLCHAIN_TRIPLES = { - "aarch64-apple-darwin": "rust_darwin_aarch64", + "aarch64-apple-darwin": "rust_macos_aarch64", "aarch64-pc-windows-msvc": "rust_windows_aarch64", "aarch64-unknown-linux-gnu": "rust_linux_aarch64", "s390x-unknown-linux-gnu": "rust_linux_s390x", - "x86_64-apple-darwin": "rust_darwin_x86_64", + "x86_64-apple-darwin": "rust_macos_x86_64", "x86_64-pc-windows-msvc": "rust_windows_x86_64", "x86_64-unknown-freebsd": "rust_freebsd_x86_64", "x86_64-unknown-linux-gnu": "rust_linux_x86_64", diff --git a/test/unit/native_deps/native_deps_test.bzl b/test/unit/native_deps/native_deps_test.bzl index 6ed7cb09df..ab97be6598 100644 --- a/test/unit/native_deps/native_deps_test.bzl +++ b/test/unit/native_deps/native_deps_test.bzl @@ -141,7 +141,7 @@ def _bin_has_native_dep_and_alwayslink_test_impl(ctx): compilation_mode = ctx.var["COMPILATION_MODE"] workspace_prefix = _get_workspace_prefix(ctx) link_args = _extract_linker_args(action.argv) - if toolchain.target_os == "darwin": + if toolchain.target_os in ["macos", "darwin"]: darwin_component = _get_darwin_component(link_args[-1]) want = [ "-lstatic=native_dep", @@ -195,7 +195,7 @@ def _cdylib_has_native_dep_and_alwayslink_test_impl(ctx): compilation_mode = ctx.var["COMPILATION_MODE"] workspace_prefix = _get_workspace_prefix(ctx) pic_suffix = _get_pic_suffix(ctx, compilation_mode) - if toolchain.target_os == "darwin": + if toolchain.target_os in ["macos", "darwin"]: darwin_component = _get_darwin_component(linker_args[-1]) want = [ "-lstatic=native_dep{}".format(pic_suffix), @@ -237,7 +237,7 @@ def _cdylib_has_native_dep_and_alwayslink_test_impl(ctx): def _get_pic_suffix(ctx, compilation_mode): toolchain = _get_toolchain(ctx) - if toolchain.target_os == "darwin" or toolchain.target_os == "windows": + if toolchain.target_os in ["darwin", "macos", "windows"]: return "" return ".pic" if compilation_mode == "opt" else "" diff --git a/test/unit/platform_triple/platform_triple_test.bzl b/test/unit/platform_triple/platform_triple_test.bzl index c437cd82f7..e6da3d6c8e 100644 --- a/test/unit/platform_triple/platform_triple_test.bzl +++ b/test/unit/platform_triple/platform_triple_test.bzl @@ -119,7 +119,7 @@ def _assert_parts(env, triple, arch, vendor, system, abi): def _construct_known_triples_test_impl(ctx): env = unittest.begin(ctx) - _assert_parts(env, triple("aarch64-apple-darwin"), "aarch64", "apple", "darwin", None) + _assert_parts(env, triple("aarch64-apple-darwin"), "aarch64", "apple", "macos", None) _assert_parts(env, triple("aarch64-fuchsia"), "aarch64", "unknown", "fuchsia", None) _assert_parts(env, triple("aarch64-unknown-linux-musl"), "aarch64", "unknown", "linux", "musl") _assert_parts(env, triple("thumbv7em-none-eabi"), "thumbv7em", None, "none", "eabi")