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

Removed rust_toolchain.os in favor of rust_toolchain.exec_triple. #1960

Merged
merged 2 commits into from
May 8, 2023

Conversation

UebelAndre
Copy link
Collaborator

@UebelAndre UebelAndre commented May 6, 2023

rust_toolchain.exec_triple has been a mandatory field for years (f1b8fd3) but by maintaining legacy behavior, there's now an opportunity for users to define misleading toolchains where rust_toolchain.os is ambiguous and/or doesn't match rust_toolchain.exec_triple.

Changes:

  • Delete the os attribute from rust_toolchain
  • Add target_os to the toolchain provider which is derived from the target_triple or target_json attributes.
  • Replace the os field on the toolchain provider with target_os as it's clearer and more matches prior art with Cargo custom targets.

Note that all uses of toolchain.os have been replaced with toolchain.target_os to avoid a change in behavior. rust_toolchain.os was near universally set to the target triple (see repository_utils.bzl) unless users defined their own toolchains without using rules_rust repository rules. That said, the use of target_os may not be correct in all it's uses today.

@UebelAndre UebelAndre marked this pull request as draft May 6, 2023 22:29
@UebelAndre UebelAndre force-pushed the toolchain-triple branch 2 times, most recently from c156ca8 to 76946eb Compare May 6, 2023 23:21
@@ -1822,10 +1818,10 @@ def _add_native_link_flags(args, dep_info, linkstamp_outs, ambiguous_libs, crate

use_pic = _should_use_pic(cc_toolchain, feature_configuration, crate_type, compilation_mode)

if toolchain.os == "windows":
if toolchain.target_os == "windows":
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could be wrong but I think this section has a mixed use of the "os". The formatting of the link flags would be dependent on what tools are being used (MSVC's link.exe vs gcc). This may be something to address in #1958 but worth considering in this change as well.

exec_os = exec_triple.system

if not exec_os:
if not exec_triple.system:
fail("No system was provided for the execution platform. Please update {}".format(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this fail could probably be removed but not entirely sure.

@UebelAndre UebelAndre marked this pull request as ready for review May 6, 2023 23:37
@UebelAndre UebelAndre requested review from krasimirgg and illicitonion and removed request for krasimirgg May 6, 2023 23:37
@rickvanprim
Copy link
Contributor

rickvanprim commented May 7, 2023

What's the benefit to introducing target_os instead of just relying on target_triple (which seems more explicit and a superset of target_os)?

@UebelAndre
Copy link
Collaborator Author

What's the benefit to introducing target_os instead of just relying on target_triple (which seems more explicit and a superset of target_os)?

target_triple is not always set, the target platform might be represented by target_json. We only attempt to parse the platform info from each but it might be missing. The new field represents the result attempt and saves users from having to check more things than necessary.

Copy link
Collaborator

@krasimirgg krasimirgg left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you!

@UebelAndre UebelAndre merged commit 0f25cb4 into bazelbuild:main May 8, 2023
@UebelAndre UebelAndre deleted the toolchain-triple branch May 8, 2023 16:51
Silcet pushed a commit to Silcet/rules_rust that referenced this pull request Jul 10, 2023
…bazelbuild#1960)

* Removed `rust_toolchain.os` in favor of `rust_toolchain.exec_triple`.

* Regenerate documentation
Silcet pushed a commit to Silcet/rules_rust that referenced this pull request Jul 10, 2023
…bazelbuild#1960)

* Removed `rust_toolchain.os` in favor of `rust_toolchain.exec_triple`.

* Regenerate documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants