Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map system from "darwin" to "macos" when parsing triple #3296

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions rust/platform/platform.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ _SUPPORTED_CPU_ARCH = [

_SUPPORTED_SYSTEMS = [
"android",
"darwin",
"macos",
"freebsd",
"ios",
"linux",
Expand All @@ -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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd probably be best to add an additional alias.

# 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
Expand Down Expand Up @@ -115,7 +115,7 @@ def declare_config_settings():
name = "unix",
match_any = [
":android",
":darwin",
":macos",
":freebsd",
":linux",
":nto",
Expand Down
3 changes: 3 additions & 0 deletions rust/platform/triple.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
5 changes: 5 additions & 0 deletions rust/platform/triple_mappings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ _SYSTEM_TO_BUILTIN_SYS_SUFFIX = {
"android": "android",
"bitrig": None,
"darwin": "osx",
"macos": "osx",
"dragonfly": None,
"eabi": "none",
"eabihf": "none",
Expand All @@ -160,6 +161,7 @@ _SYSTEM_TO_BUILTIN_SYS_SUFFIX = {
_SYSTEM_TO_BINARY_EXT = {
"android": "",
"darwin": "",
"macos": "",
"eabi": "",
"eabihf": "",
"emscripten": ".js",
Expand All @@ -183,6 +185,7 @@ _SYSTEM_TO_BINARY_EXT = {
_SYSTEM_TO_STATICLIB_EXT = {
"android": ".a",
"darwin": ".a",
"macos": ".a",
"eabi": ".a",
"eabihf": ".a",
"emscripten": ".js",
Expand All @@ -203,6 +206,7 @@ _SYSTEM_TO_STATICLIB_EXT = {
_SYSTEM_TO_DYLIB_EXT = {
"android": ".so",
"darwin": ".dylib",
"macos": ".dylib",
"eabi": ".so",
"eabihf": ".so",
"emscripten": ".js",
Expand Down Expand Up @@ -231,6 +235,7 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
# I am not sure which is the common configuration or how we encode it as a link flag.
"cloudabi": ["-lunwind", "-lc", "-lcompiler_rt"],
"darwin": ["-lSystem", "-lresolv"],
"macos": ["-lSystem", "-lresolv"],
"dragonfly": ["-lpthread"],
"eabi": [],
"eabihf": [],
Expand Down
4 changes: 2 additions & 2 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions rust/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions test/unit/native_deps/native_deps_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 ""

Expand Down
2 changes: 1 addition & 1 deletion test/unit/platform_triple/platform_triple_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading