Skip to content

Commit fdcaa88

Browse files
Be-ingBe
authored and
Be
committed
cxx-build: symlink headers to GENERATED_HEADER_DIR
Symlink (or copy on Windows) generated headers to a directory specified by the GENERATED_HEADER_DIR environment variable, if this variable is set. This makes cxx-build usable by C++ build systems if they set GENERATED_HEADER_DIR before calling cargo and add it to their include paths. This is a better solution than the CLI tool for several reasons: * Don't need to build/distribute/install a separate program * Saves build time because cxx crates are not built redundantly for the CLI tool and the macro * No risk of version mismatches between CLI tool and cxx macro crate * One library crate that uses cxx can be usable in applications built either with Cargo or a C++ build system Fixes dtolnay#462
1 parent c7060d4 commit fdcaa88

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

gen/build/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,16 @@ fn generate_bridge(prj: &Project, build: &mut Build, rust_source_file: &Path) ->
424424
let shared_cc = prj.shared_dir.join(&prj.include_prefix).join(rel_path_cc);
425425
let _ = out::symlink_file(header_path, shared_h);
426426
let _ = out::symlink_file(implementation_path, shared_cc);
427+
428+
if let Ok(export_path) = env::var("GENERATED_HEADER_DIR") {
429+
out::symlink_file(
430+
header_path,
431+
PathBuf::from(export_path)
432+
.join(&prj.include_prefix)
433+
.join(rel_path_h),
434+
)?;
435+
}
436+
427437
Ok(())
428438
}
429439

0 commit comments

Comments
 (0)