Skip to content

Commit 6153ba1

Browse files
Add support for optional cc_toolchain (#3665)
Changes: - Moved `rust_allocator_libraries` rule implementation into it's own file - Updated all rules to set `mandatory = False` for `@bazel_tools//tools/cpp:toolchain_type` toolchains. - Refactored rules_rust internals to work in cases where `find_cc_toolchain` returns `None` - Added `linker` as an optional attribute to `rust_toolchain`. This is expected to be `rust-lld` for now. - Added a new setting `@rules_rust//rust/settings:toolchain_linker_preference` which in the event `rust_toolchain.linker` and a `cc_toolchain` are present, chooses the linker to use. (Defaults to `cc`). - Introduce `--@rules_rust//settings:default_allocator_library` as a flag to globally control this value. --------- Co-authored-by: Daniel Wagner-Hall <[email protected]>
1 parent 431f6b2 commit 6153ba1

File tree

48 files changed

+2257
-334
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2257
-334
lines changed

.bazelci/presubmit.yml

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -723,19 +723,43 @@ tasks:
723723
working_directory: examples/compile_opt
724724
build_targets:
725725
- "//..."
726-
# TODO: https://github.com/bazelbuild/rules_rust/issues/2075
727-
# cross_compile_zig:
728-
# name: Cross compile example with Zig
726+
# TODO: This test requires musl or for rustc to provide necessary gnu libraries for
727+
# linking gnu libraries.
728+
# https://github.com/bazelbuild/rules_rust/issues/390
729+
# cross_compile_linux:
730+
# name: Cross compile example on Linux without cc_toolchain
729731
# platform: ubuntu2204
730-
# working_directory: examples/cross_compile_zig
731-
# build_targets:
732+
# working_directory: examples/cross_compile
733+
# shell_commands:
734+
# - sed -i 's/_FORCE_DISABLE_CC_TOOLCHAIN = False/_FORCE_DISABLE_CC_TOOLCHAIN = True/' ../../rust/private/utils.bzl
735+
# test_flags:
736+
# - "--keep_going"
737+
# test_targets:
732738
# - "//..."
739+
cross_compile_macos:
740+
name: Cross compile example on MacOS without cc_toolchain
741+
platform: macos_arm64
742+
working_directory: examples/cross_compile
743+
shell_commands:
744+
- sed -i '' 's/_FORCE_DISABLE_CC_TOOLCHAIN = False/_FORCE_DISABLE_CC_TOOLCHAIN = True/' ../../rust/private/utils.bzl
745+
test_flags:
746+
- "--keep_going"
747+
test_targets:
748+
- "//..."
749+
cross_compile_windows:
750+
name: Cross compile example on Windows without cc_toolchain
751+
platform: windows
752+
working_directory: examples/cross_compile
753+
batch_commands:
754+
- powershell -Command "(Get-Content rust/private/utils.bzl) -replace '_FORCE_DISABLE_CC_TOOLCHAIN = False', '_FORCE_DISABLE_CC_TOOLCHAIN = True' | Set-Content ../../rust/private/utils.bzl"
755+
test_flags:
756+
- "--keep_going"
757+
test_targets:
758+
- "//..."
733759
cross_compile_musl_macos_to_linux:
734760
name: Cross compile example Musl from macOS to Linux
735761
platform: macos_arm64
736762
working_directory: examples/cross_compile_musl
737-
build_targets:
738-
- "//..."
739763
test_targets:
740764
- "//..."
741765
cross_compile_musl_linux_to_linux:
@@ -775,6 +799,13 @@ tasks:
775799
- "//:all"
776800
test_targets:
777801
- "//..."
802+
# TODO: https://github.com/bazelbuild/rules_rust/issues/2075
803+
# cross_compile_zig:
804+
# name: Cross compile example with Zig
805+
# platform: ubuntu2204
806+
# working_directory: examples/cross_compile_zig
807+
# build_targets:
808+
# - "//..."
778809
example_ffi_linux:
779810
platform: ubuntu2204
780811
working_directory: examples/ffi

.bazelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ build:unpretty --output_groups=+rust_unpretty
4949
# https://github.com/rust-lang/rust/issues/43364
5050
build:unpretty --config=nightly
5151

52+
# Disable cc toolchains to test rust targets can be built without one.
53+
build:no_cc_toolchain --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
54+
build:no_cc_toolchain --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1
55+
5256
###############################################################################
5357
## Incompatibility flags
5458
###############################################################################

0 commit comments

Comments
 (0)