-
Notifications
You must be signed in to change notification settings - Fork 25
Add Windows static CRT support and CI test #47
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| use std::env; | ||
| use std::path::{Path, PathBuf}; | ||
|
|
||
| fn target_has_feature(feature: &str) -> bool { | ||
| env::var("CARGO_CFG_TARGET_FEATURE") | ||
| .unwrap_or_default() | ||
| .split(',') | ||
| .any(|enabled_feature| enabled_feature == feature) | ||
| } | ||
|
|
||
| /// Used to exclude autogenerated files in the output dir from `cargo:rerun-if-changed` directives. | ||
| #[derive(Debug)] | ||
| pub struct CustomCargoCallbacks { | ||
|
|
@@ -86,6 +93,7 @@ fn build() -> bool { | |
| let target = env::var("TARGET").unwrap(); | ||
| let emscripten = target.contains("emscripten"); | ||
| let mut dst = Config::new("HiGHS"); | ||
| let crt_static = target_has_feature("crt-static"); | ||
|
|
||
| if cfg!(feature = "ninja") { | ||
| dst.generator("Ninja"); | ||
|
|
@@ -109,7 +117,14 @@ fn build() -> bool { | |
| let dst = dst | ||
| .define("FAST_BUILD", "ON") | ||
| .define("BUILD_SHARED_LIBS", "OFF") | ||
| .define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreadedDLL") | ||
| .define( | ||
| "CMAKE_MSVC_RUNTIME_LIBRARY", | ||
| if crt_static { | ||
| "MultiThreaded" | ||
| } else { | ||
| "MultiThreadedDLL" | ||
| }, | ||
| ) | ||
| .define("CMAKE_INTERPROCEDURAL_OPTIMIZATION", "FALSE") | ||
| .define("ZLIB", if cfg!(feature = "libz") { "ON" } else { "OFF" }) | ||
| .build(); | ||
|
|
@@ -164,6 +179,10 @@ fn discover() -> bool { | |
| } | ||
|
|
||
| fn main() { | ||
| println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_FEATURE"); | ||
|
|
||
| let crt_static = target_has_feature("crt-static"); | ||
|
|
||
| if cfg!(all( | ||
| any( | ||
| feature = "highs_release", | ||
|
|
@@ -173,11 +192,18 @@ fn main() { | |
| not(feature = "build") | ||
| )) { | ||
| panic!( | ||
| "You have enabled features that control how HiGHS is built, but have not enabled the 'build' feature.\n\ | ||
| "You have enabled features that control how HiGHS is built, but have not enabled the 'build' feature. | ||
| \ | ||
| Thus, your features will never have any effect. Please enable the 'build' feature on highs-sys if you want to build HiGHS or disable the 'libz', 'ninja' and 'highs_release' features." | ||
| ); | ||
| } | ||
|
|
||
| if cfg!(feature = "discover") && crt_static { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This guard now panics for every Useful? React with 👍 / 👎. |
||
| println!( | ||
| "cargo::warning=You have enabled Rust's 'crt-static' target feature, but also enabled the 'discover' feature. Discovering a system-installed HiGHS bypasses the bundled build, so highs-sys cannot ensure that HiGHS uses the same MSVC runtime. Please disable 'discover' when using '-C target-feature=+crt-static'." | ||
| ); | ||
| } | ||
|
|
||
| if !discover() && !build() { | ||
| panic!("Could neither discover nor build HiGHS"); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crt-staticwhendiscoverbypasses the bundled buildThis flag is only consumed inside
build()here, butmain()still only treatshighs_release,libz, andninjaas build-only and it callsdiscover()beforebuild(). In configurations like--no-default-features --features discover,crt-static(or addingdiscoveron top of defaults), the new feature is silently ignored and callers link whatever CRT their pkg-config HiGHS was built with, even though they explicitly requested a static-CRT build. The other build-only knobs already hard-fail in this situation, socrt-staticneeds the same protection.Useful? React with 👍 / 👎.