Skip to content

Commit

Permalink
Add feature flags for static builds (#4691)
Browse files Browse the repository at this point in the history
  • Loading branch information
masa-koz authored Dec 17, 2024
1 parent 5801a8b commit f8e9cec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-xlarge]
features: ["", "--features static"]
runs-on: ${{ matrix.os }}
name: Cargo
steps:
Expand All @@ -41,8 +42,8 @@ jobs:
if: runner.os == 'Linux'
run: curl https://sh.rustup.rs -sSf | sh -s -- -y
- name: Cargo build
run: cargo build --all
run: cargo build --all ${{ matrix.features }}
- name: Cargo test
run: cargo test --all
run: cargo test --all ${{ matrix.features }}
- name: Cargo Publish (dry run)
run: cargo publish --dry-run --allow-dirty
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ include = [
"/THIRD-PARTY-NOTICES",
]

[features]
default = []
static = []

[build-dependencies]
cmake = "0.1"

Expand Down
23 changes: 22 additions & 1 deletion scripts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ fn main() {
}

let target = env::var("TARGET").unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
// The output directory for the native MsQuic library.
let quic_output_dir = Path::new(&out_dir).join("lib");

// Builds the native MsQuic and installs it into $OUT_DIR.
let mut config = Config::new(".");
config
.define("QUIC_ENABLE_LOGGING", logging_enabled)
.define("QUIC_TLS", "openssl")
.define("QUIC_OUTPUT_DIR", "../lib");
.define("QUIC_OUTPUT_DIR", quic_output_dir.to_str().unwrap());
if cfg!(feature = "static") {
config.define("QUIC_BUILD_SHARED", "off");
}

// macos-latest's cargo automatically specify --target=${ARCH}-apple-macosx14.5
// which conflicts with -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}.
Expand All @@ -38,4 +44,19 @@ fn main() {
let dst = config.build();
let lib_path = Path::join(Path::new(&dst), Path::new(path_extra));
println!("cargo:rustc-link-search=native={}", lib_path.display());
if cfg!(feature = "static") {
if cfg!(target_os = "linux") {
let numa_lib_path = match target.as_str() {
"x86_64-unknown-linux-gnu" => "/usr/lib/x86_64-linux-gnu",
"aarch64-unknown-linux-gnu" => "/usr/lib/aarch64-linux-gnu",
_ => panic!("Unsupported target: {}", target),
};
println!("cargo:rustc-link-search=native={}", numa_lib_path);
println!("cargo:rustc-link-lib=static:+whole-archive=numa");
} else if cfg!(target_os = "macos") {
println!("cargo:rustc-link-lib=framework=CoreFoundation");
println!("cargo:rustc-link-lib=framework=Security");
}
println!("cargo:rustc-link-lib=static=msquic");
}
}

0 comments on commit f8e9cec

Please sign in to comment.