Pass linker path to build script
authorHenrik Laxhuber <henrik@laxhuber.com>
Fri, 20 Apr 2018 15:04:14 +0000 (17:04 +0200)
committerHenrik Laxhuber <henrik@laxhuber.com>
Fri, 20 Apr 2018 15:04:14 +0000 (17:04 +0200)
This change adds the environment variable LINKER to pass the path
of the linker used by cargo to the build script. This ammends the
variable RUSTC (the rustc binary used) to give the build script
full knowledge of its environment.

A specific usage example would be automatically generating bindings
to system headers in cross compilation, e.g. by locating jni.h for
android targets.

src/cargo/core/compiler/custom_build.rs

index a219ddab5cd51f7f34459514f52d7f40aff2ae90..e1e5ce92a63807a43946a227a46da4731c65d218 100644 (file)
@@ -144,6 +144,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
         .env("HOST", &cx.build_config.host_triple())
         .env("RUSTC", &cx.build_config.rustc.path)
         .env("RUSTDOC", &*cx.config.rustdoc()?)
+        .env("LINKER", &cx.build_config.target.linker.as_ref().unwrap_or(&PathBuf::new()))
         .inherit_jobserver(&cx.jobserver);
 
     if let Some(links) = unit.pkg.manifest().links() {