mirror of
https://github.com/openharmony/third_party_rust_cc-rs.git
synced 2026-07-01 23:04:09 -04:00
c7c1ec636e
* Perform CUDA --device-link.
This allows to perform the final link with system linker.
* Add 'cudart' method mimicking the '--cudart' nvcc command-line option.
Try to locate the library in standard location relative to nvcc command.
If it fails, user is held responsible for specifying one in RUSTFLAGS.
* Add dummy CUDA test to cc-test.
Execution is bound to fail without card, but the failure is ignored.
It's rather a compile-n-link test. The test is suppressed if 'nvcc'
is not found on the $PATH.
* Add dummy CUDA CI test.
* Harmonize CUDA support with NVCC default --cudart static.
This can interfere with current deployments in the wild, in which
case some adjustments might be required. Most notably one might
have to add .cuda("none") to the corresponding Builder instantiation
to restore the original behaviour.
107 lines
3.2 KiB
Rust
107 lines
3.2 KiB
Rust
use std::env;
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
let out = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
|
fs::remove_dir_all(&out).unwrap();
|
|
fs::create_dir(&out).unwrap();
|
|
|
|
cc::Build::new()
|
|
.file("src/foo.c")
|
|
.flag_if_supported("-Wall")
|
|
.flag_if_supported("-Wfoo-bar-this-flag-does-not-exist")
|
|
.define("FOO", None)
|
|
.define("BAR", "1")
|
|
.compile("foo");
|
|
|
|
cc::Build::new()
|
|
.file("src/bar1.c")
|
|
.file("src/bar2.c")
|
|
.include("src/include")
|
|
.compile("bar");
|
|
|
|
let target = std::env::var("TARGET").unwrap();
|
|
let file = target.split("-").next().unwrap();
|
|
let file = format!(
|
|
"src/{}.{}",
|
|
file,
|
|
if target.contains("msvc") { "asm" } else { "S" }
|
|
);
|
|
cc::Build::new().file(file).compile("asm");
|
|
|
|
cc::Build::new()
|
|
.file("src/baz.cpp")
|
|
.cpp(true)
|
|
.compile("baz");
|
|
|
|
if env::var("CARGO_FEATURE_TEST_CUDA").is_ok() {
|
|
// Detect if there is CUDA compiler and engage "cuda" feature.
|
|
let nvcc = match env::var("NVCC") {
|
|
Ok(var) => which::which(var),
|
|
Err(_) => which::which("nvcc"),
|
|
};
|
|
if nvcc.is_ok() {
|
|
cc::Build::new()
|
|
.cuda(true)
|
|
.cudart("static")
|
|
.file("src/cuda.cu")
|
|
.compile("libcuda.a");
|
|
|
|
// Communicate [cfg(feature = "cuda")] to test/all.rs.
|
|
println!("cargo:rustc-cfg=feature=\"cuda\"");
|
|
}
|
|
}
|
|
|
|
if target.contains("windows") {
|
|
cc::Build::new().file("src/windows.c").compile("windows");
|
|
}
|
|
|
|
// Test that the `windows_registry` module will set PATH by looking for
|
|
// nmake which runs vanilla cl, and then also test it after we remove all
|
|
// the relevant env vars from our own process.
|
|
if target.contains("msvc") {
|
|
let out = out.join("tmp");
|
|
fs::create_dir(&out).unwrap();
|
|
println!("nmake 1");
|
|
let status = cc::windows_registry::find(&target, "nmake.exe")
|
|
.unwrap()
|
|
.env_remove("MAKEFLAGS")
|
|
.arg("/fsrc/NMakefile")
|
|
.env("OUT_DIR", &out)
|
|
.status()
|
|
.unwrap();
|
|
assert!(status.success());
|
|
|
|
fs::remove_dir_all(&out).unwrap();
|
|
fs::create_dir(&out).unwrap();
|
|
|
|
env::remove_var("PATH");
|
|
env::remove_var("VCINSTALLDIR");
|
|
env::remove_var("INCLUDE");
|
|
env::remove_var("LIB");
|
|
println!("nmake 2");
|
|
let status = cc::windows_registry::find(&target, "nmake.exe")
|
|
.unwrap()
|
|
.env_remove("MAKEFLAGS")
|
|
.arg("/fsrc/NMakefile")
|
|
.env("OUT_DIR", &out)
|
|
.status()
|
|
.unwrap();
|
|
assert!(status.success());
|
|
println!("cargo:rustc-link-lib=msvc");
|
|
println!("cargo:rustc-link-search={}", out.display());
|
|
}
|
|
|
|
// This tests whether we can build a library but not link it to the main
|
|
// crate. The test module will do its own linking.
|
|
cc::Build::new()
|
|
.cargo_metadata(false)
|
|
.file("src/opt_linkage.c")
|
|
.compile("OptLinkage");
|
|
|
|
let out = cc::Build::new().file("src/expand.c").expand();
|
|
let out = String::from_utf8(out).unwrap();
|
|
assert!(out.contains("hello world"));
|
|
}
|