Skip to content

Commit

Permalink
Add compile_for_everything() that produces cargo:rustc-link-arg=
Browse files Browse the repository at this point in the history
Closes: #69
  • Loading branch information
nabijaczleweli committed Sep 26, 2024
1 parent a59c9b5 commit ed238e6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub fn compile_for<T: AsRef<Path>, J: Display, I: IntoIterator<Item = J>, Ms: As
}
}

/// Likewise, but only link the resource to test binaries.
/// Likewise, but only link the resource to test binaries (select types only. unclear which (and likely to change). you may prefer [`compile_for_everything()`]).
///
/// Only available since rustc 1.60.0, does nothing before.
pub fn compile_for_tests<T: AsRef<Path>, Ms: AsRef<OsStr>, Mi: IntoIterator<Item = Ms>>(resource_file: T, macros: Mi) {
Expand All @@ -259,6 +259,15 @@ pub fn compile_for_examples<T: AsRef<Path>, Ms: AsRef<OsStr>, Mi: IntoIterator<I
}
}

/// Likewise, but link the resource into *every* artifact: binaries, cdylibs, examples, tests (`[[test]]`/`#[test]`/doctest), benchmarks, &c.
///
/// Only available since rustc 1.50.0, does nothing before.
pub fn compile_for_everything<T: AsRef<Path>, Ms: AsRef<OsStr>, Mi: IntoIterator<Item = Ms>>(resource_file: T, macros: Mi) {
if let Some((_, _, out_file)) = compile_impl(resource_file.as_ref(), macros) {
println!("cargo:rustc-link-arg={}", out_file);
}
}

fn compile_impl<Ms: AsRef<OsStr>, Mi: IntoIterator<Item = Ms>>(resource_file: &Path, macros: Mi) -> Option<(&str, String, String)> {
let comp = ResourceCompiler::new();
if comp.is_supported() {
Expand Down

0 comments on commit ed238e6

Please sign in to comment.