-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rust test for /usr/bin/ld symlink
This test will fail if the symlink from `/usr/bin/ld` to the llvm toolchain directory is not made.
- Loading branch information
Showing
8 changed files
with
244 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
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,13 @@ | ||
load("@rules_rust//rust:rust.bzl", "rust_binary", "rust_test") | ||
load("@rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script") | ||
|
||
cargo_build_script( | ||
name = "build_script", | ||
srcs = ["build.rs"], | ||
) | ||
|
||
rust_test( | ||
name = "rust_test", | ||
srcs = ["src/rust_test.rs"], | ||
deps = [":build_script"], | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
*This example project is used to test Rust's compatibility (on Mac) with a custom llvm_toolchain.* | ||
|
||
Rust's `rustc` expects to find the `ld` executable in the same directory as the compiler executable, which is not (currently) the case for Mac compilation with `llvm_toolchain` as LLVM's `ld.lld` linker is still experimental on MacOS and therefore the default linker at `/usr/bin/ld` is used. When compiling Rust code we encounter an `executable "ld" doesn't exist` error. The current fix is to manually symlink `/usr/bin/ld` into the llvm toolchain's `bin` directory to ensure it is found. This is necessary to make compilation work for both normal rust crates and crates which use build scripts (`build.rs`). | ||
|
||
This project contains a simple build script and rust executable to test that both work well with `/usr/bin/ld` into the llvm toolchain's `bin` directory. If the build succeeds it means `rustc` found `ld` both in the build script and rust binary invocations. |
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,17 @@ | ||
use std::env; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
fn main() { | ||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
let out = Path::new(&out_dir).join("hello.rs"); | ||
|
||
let _ = fs::write( | ||
&out, | ||
"pub fn hello() -> &'static str { | ||
\"Hello, world!\" | ||
} | ||
"); | ||
|
||
println!("cargo:rerun-if-changed=build.rs"); | ||
} |
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,11 @@ | ||
include!(concat!(env!("OUT_DIR"), "/hello.rs")); | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::hello; | ||
|
||
#[test] | ||
fn test_hello() { | ||
assert_eq!("Hello, world!", hello()); | ||
} | ||
} |
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