-
Notifications
You must be signed in to change notification settings - Fork 24
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
Open
lovasoa
wants to merge
2
commits into
master
Choose a base branch
from
codex/add-support-for-windows-static-binaries
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,20 @@ 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 { | ||
| panic!( | ||
| "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'." | ||
| ); | ||
| } | ||
|
|
||
|
Comment on lines
+202
to
+208
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. I think using warning would make more sense here. We do not know which runtime configuration users are using, and if the build passes successfully, that should be fine. |
||
| if !discover() && !build() { | ||
| panic!("Could neither discover nor build HiGHS"); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This guard now panics for every
discover+crt-staticbuild, butcrt-staticis also used on non-MSVC targets (for example static Linux/musl builds) where the MSVC runtime mismatch described here does not apply. Because the panic runs beforediscover()/build(), it also blocks validdiscover+buildfallback configurations that could still safely build the bundled HiGHS library. Restricting this check to MSVC contexts (or to cases where discovery is actually used) would avoid breaking those legitimate builds.Useful? React with 👍 / 👎.