Skip to content

Commit 90d080e

Browse files
committed
Omit cargo-specific prints with non-cargo feature
1 parent 22e359a commit 90d080e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

zstd-safe/zstd-sys/build.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ fn compile_zstd() {
131131
env::var("TARGET").ok() == Some("wasm32-unknown-unknown".into());
132132

133133
if is_wasm_unknown_unknown {
134-
println!("cargo:rerun-if-changed=wasm-shim/stdlib.h");
135-
println!("cargo:rerun-if-changed=wasm-shim/string.h");
134+
cargo_print("cargo:rerun-if-changed=wasm-shim/stdlib.h");
135+
cargo_print("cargo:rerun-if-changed=wasm-shim/string.h");
136136

137137
config.include("wasm-shim/");
138138
config.define("XXH_STATIC_ASSERT", Some("0"));
@@ -158,6 +158,7 @@ fn compile_zstd() {
158158

159159
#[cfg(feature = "thin")]
160160
{
161+
// Here we try to build a lib as thin/small as possible.
161162
config.define("HUF_FORCE_DECOMPRESS_X1", Some("1"));
162163
config.define("ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT", Some("1"));
163164
config.define("ZSTD_NO_INLINE ", Some("1"));
@@ -207,19 +208,26 @@ fn compile_zstd() {
207208
.unwrap();
208209
#[cfg(feature = "zdict_builder")]
209210
fs::copy(src.join("zdict.h"), include.join("zdict.h")).unwrap();
210-
println!("cargo:root={}", dst.display());
211+
cargo_print(&format!("cargo:root={}", dst.display()));
211212
}
212213

213-
fn main() {
214+
/// Print a line for cargo.
215+
///
216+
/// If non-cargo is set, do not print anything.
217+
fn cargo_print(content: &str) {
214218
#[cfg(not(feature = "non-cargo"))]
215-
println!("cargo:rerun-if-env-changed=ZSTD_SYS_USE_PKG_CONFIG");
219+
println!("{content}");
220+
}
221+
222+
fn main() {
223+
cargo_print("cargo:rerun-if-env-changed=ZSTD_SYS_USE_PKG_CONFIG");
216224

217225
let target_arch =
218226
std::env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
219227
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
220228

221229
if target_arch == "wasm32" || target_os == "hermit" {
222-
println!("cargo:rustc-cfg=feature=\"std\"");
230+
cargo_print("cargo:rustc-cfg=feature=\"std\"");
223231
}
224232

225233
// println!("cargo:rustc-link-lib=zstd");
@@ -245,7 +253,7 @@ fn main() {
245253
.iter()
246254
.map(|p| p.display().to_string())
247255
.collect();
248-
println!("cargo:include={}", includes.join(";"));
256+
cargo_print(&format!("cargo:include={}", includes.join(";")));
249257

250258
generate_bindings(defs, headerpaths);
251259
}

0 commit comments

Comments
 (0)