Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature flags for static builds #4691

Merged
merged 6 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
Loading