|
1 | 1 | fn main() { |
2 | | - // When the `zlob` feature is enabled (Zig-compiled C library): |
3 | | - // On Windows MSVC, explicitly link the C runtime libraries. |
4 | | - // Zig-compiled static libraries don't emit /DEFAULTLIB directives for the |
5 | | - // MSVC CRT, so symbols like strcmp, memcpy etc. would be unresolved. |
6 | 2 | if std::env::var("CARGO_FEATURE_ZLOB").is_ok() { |
| 3 | + if !zig_available() { |
| 4 | + panic!( |
| 5 | + "The `zlob` feature is enabled but Zig is not installed. \ |
| 6 | + Install Zig (https://ziglang.org/download/) or build without \ |
| 7 | + `--features zlob`." |
| 8 | + ); |
| 9 | + } |
| 10 | + |
7 | 11 | let target = std::env::var("TARGET").unwrap_or_default(); |
8 | 12 | if target.contains("windows") && target.contains("msvc") { |
9 | 13 | println!("cargo:rustc-link-lib=msvcrt"); |
10 | 14 | println!("cargo:rustc-link-lib=ucrt"); |
11 | 15 | println!("cargo:rustc-link-lib=vcruntime"); |
12 | 16 | } |
13 | | - } else if std::env::var("CI").is_ok() { |
14 | | - // CI must always build with zlob for production-quality binaries. |
15 | | - if !zig_available() { |
16 | | - panic!( |
17 | | - "CI detected but Zig is not installed. \ |
18 | | - Please install Zig and build with `--features zlob`." |
19 | | - ); |
20 | | - } |
21 | | - panic!( |
22 | | - "CI detected but `zlob` feature is not enabled. \ |
23 | | - Build with `--features zlob`." |
24 | | - ); |
25 | | - } else { |
| 17 | + } else if std::env::var("CARGO_PRIMARY_PACKAGE").is_ok() && zig_available() { |
26 | 18 | // Hint: if Zig is available but the zlob feature wasn't enabled, |
27 | 19 | // let the developer know they can get faster glob matching. |
28 | | - if zig_available() { |
29 | | - println!( |
30 | | - "cargo:warning=Zig detected but `zlob` feature is not enabled. \ |
31 | | - Build with `--features zlob` for faster glob matching." |
32 | | - ); |
33 | | - } |
| 20 | + // Only emit this hint when this crate is the primary package to |
| 21 | + // avoid noisy warnings for downstream consumers. |
| 22 | + println!( |
| 23 | + "cargo:warning=Zig detected but `zlob` feature is not enabled. \ |
| 24 | + Build with `--features zlob` for faster glob matching." |
| 25 | + ); |
34 | 26 | } |
35 | 27 | } |
36 | 28 |
|
|
0 commit comments