-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for passing a custom target specification. (#836)
* Add support for passing a custom target specification. * Pass the target spec ias a dependency. * Created a target_flag_value toolchain info field to avoid recalculating the value. * Prevent passing both target_triple and target_json simultaneously. * Streamline checks for None. * Added unit tests for rust_toolchain rules. * Rename test target spec to avoid collisions with the builtin. * Regenerate documentation * Rename the triple used in unit tests. Co-authored-by: UebelAndre <github@uebelandre.com> Co-authored-by: Marcel Hlopko <hlopko@google.com>
- Loading branch information
1 parent
4da6858
commit 37982c5
Showing
8 changed files
with
137 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
load(":toolchain_test.bzl", "toolchain_test_suite") | ||
|
||
toolchain_test_suite(name = "toolchain_test_suite") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"arch": "x86_64", | ||
"cpu": "x86-64", | ||
"crt-static-respected": true, | ||
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", | ||
"dynamic-linking": true, | ||
"env": "gnu", | ||
"executables": true, | ||
"has-elf-tls": true, | ||
"has-rpath": true, | ||
"llvm-target": "x86_64-unknown-linux-gnu", | ||
"max-atomic-width": 64, | ||
"os": "linux", | ||
"position-independent-executables": true, | ||
"pre-link-args": { | ||
"gcc": [ | ||
"-m64" | ||
] | ||
}, | ||
"relro-level": "full", | ||
"stack-probes": { | ||
"kind": "call" | ||
}, | ||
"supported-sanitizers": [ | ||
"address", | ||
"leak", | ||
"memory", | ||
"thread" | ||
], | ||
"target-family": [ | ||
"unix" | ||
], | ||
"target-pointer-width": "64" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
"""Unit tests for rust toolchains.""" | ||
|
||
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") | ||
load("//rust:toolchain.bzl", "rust_stdlib_filegroup", "rust_toolchain") | ||
|
||
def _toolchain_specifies_target_triple_test_impl(ctx): | ||
env = analysistest.begin(ctx) | ||
toolchain_info = analysistest.target_under_test(env)[platform_common.ToolchainInfo] | ||
|
||
asserts.equals(env, None, toolchain_info.target_json) | ||
asserts.equals(env, "toolchain-test-triple", toolchain_info.target_flag_value) | ||
asserts.equals(env, "toolchain-test-triple", toolchain_info.target_triple) | ||
|
||
return analysistest.end(env) | ||
|
||
def _toolchain_specifies_target_json_test_impl(ctx): | ||
env = analysistest.begin(ctx) | ||
toolchain_info = analysistest.target_under_test(env)[platform_common.ToolchainInfo] | ||
|
||
asserts.equals(env, "toolchain-test-triple.json", toolchain_info.target_json.basename) | ||
asserts.equals(env, "test/unit/toolchain/toolchain-test-triple.json", toolchain_info.target_flag_value) | ||
asserts.equals(env, "", toolchain_info.target_triple) | ||
|
||
return analysistest.end(env) | ||
|
||
toolchain_specifies_target_triple_test = analysistest.make(_toolchain_specifies_target_triple_test_impl) | ||
toolchain_specifies_target_json_test = analysistest.make(_toolchain_specifies_target_json_test_impl) | ||
|
||
def _toolchain_test(): | ||
rust_stdlib_filegroup( | ||
name = "std_libs", | ||
srcs = [], | ||
) | ||
|
||
native.filegroup( | ||
name = "target_json", | ||
srcs = ["toolchain-test-triple.json"], | ||
) | ||
|
||
rust_toolchain( | ||
name = "rust_triple_toolchain", | ||
binary_ext = "", | ||
dylib_ext = ".so", | ||
os = "linux", | ||
rust_lib = ":std_libs", | ||
staticlib_ext = ".a", | ||
stdlib_linkflags = [], | ||
target_triple = "toolchain-test-triple", | ||
) | ||
|
||
rust_toolchain( | ||
name = "rust_json_toolchain", | ||
binary_ext = "", | ||
dylib_ext = ".so", | ||
os = "linux", | ||
rust_lib = ":std_libs", | ||
staticlib_ext = ".a", | ||
stdlib_linkflags = [], | ||
target_json = ":target_json", | ||
) | ||
|
||
toolchain_specifies_target_triple_test( | ||
name = "toolchain_specifies_target_triple_test", | ||
target_under_test = ":rust_triple_toolchain", | ||
) | ||
toolchain_specifies_target_json_test( | ||
name = "toolchain_specifies_target_json_test", | ||
target_under_test = ":rust_json_toolchain", | ||
) | ||
|
||
def toolchain_test_suite(name): | ||
_toolchain_test() | ||
|
||
native.test_suite( | ||
name = name, | ||
tests = [ | ||
":toolchain_specifies_target_triple_test", | ||
":toolchain_specifies_target_json_test", | ||
], | ||
) |