Skip to content

Commit 812034f

Browse files
authored
Fix Windows build (#3)
1 parent 0b9959e commit 812034f

File tree

7 files changed

+41
-34
lines changed

7 files changed

+41
-34
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.'cfg(target_family = "windows")']
2+
rustflags = ["-Ctarget-feature=+crt-static"]

.devcontainer/devcontainer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"image": "mcr.microsoft.com/devcontainers/universal:2",
3+
"features": {
4+
"ghcr.io/lee-orr/rusty-dev-containers/rust_windows_msvc:0": {},
5+
"ghcr.io/devcontainers/features/rust:1": {}
6+
}
7+
}

.github/workflows/test-build.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
os: [windows-latest]
15+
os: [macos-14, macos-latest, ubuntu-latest, windows-latest]
1616
include:
17-
# - os: macos-14
18-
# name: "macOS ARM"
19-
# - os: macos-latest
20-
# name: "macOS x86"
21-
# - os: ubuntu-latest
22-
# name: "Linux"
17+
- os: macos-14
18+
name: "macOS ARM"
19+
- os: macos-latest
20+
name: "macOS x86"
21+
- os: ubuntu-latest
22+
name: "Linux"
2323
- os: windows-latest
2424
name: "Windows"
2525

@@ -30,5 +30,8 @@ jobs:
3030
with:
3131
submodules: recursive
3232

33+
- name: Build
34+
run: cargo build
35+
3336
- name: Run tests
34-
run: cargo test --verbose
37+
run: cargo test

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,3 @@ target/
1919
# Mac
2020
.DS_Store
2121

22-
# Cargo
23-
.cargo/
24-

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ serde = { version = "1.0.217", features = ["derive"] }
1414
autocxx-build = "0.27.1"
1515
cmake = "0.1.54"
1616
miette = { version = "5", features = ["fancy"] }
17-
vcpkg = "0.2.15"
1817

1918
[dev-dependencies]
2019
pretty_assertions = "1.4.1"

build.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ const WITH_LIBXML: &str = "OFF";
2828
/// Whether to build with Expat XML parser support
2929
const WITH_EXPAT: &str = "ON";
3030

31-
/// Whether to use static runtime libraries (enabled on Windows only)
32-
const WITH_STATIC_RUNTIME: &str = "ON";
33-
3431
/// Main build script function that orchestrates the build process
3532
///
3633
/// This function:
@@ -68,8 +65,8 @@ fn main() -> miette::Result<()> {
6865
// Build the C++ wrapper code and bindings
6966
let mut b = autocxx_build::Builder::new(rs_file, &[lib_root, &sbml_include]).build()?;
7067

71-
// Ensure C++17 is used for compilation
72-
b.flag_if_supported("-std=c++17").compile("libsbml");
68+
// Ensure C++20 is used for compilation
69+
b.flag_if_supported("-std=c++17").compile("sbmlrs");
7370

7471
Ok(())
7572
}
@@ -87,13 +84,15 @@ fn main() -> miette::Result<()> {
8784
/// * `miette::Result<String>` - Build directory path on success, error on failure
8885
fn build_and_link_libsbml(dep_build: &str) -> miette::Result<String> {
8986
let dst = if cfg!(target_os = "windows") {
87+
println!("cargo:warning=Building libSBML for Windows");
9088
// In order to build for windows, we need to carefully tell CMake
9189
// where to find the libraries and headers for libexpat and zlib.
9290
// This is necessary because the libraries are not installed in the
9391
// system directories by default. Unlinke MacOS and Linux kernels
9492
cmake::Config::new(LIBSBML_PATH)
95-
.define("CMAKE_BUILD_TYPE", "Release")
96-
.define("WITH_STATIC_RUNTIME", WITH_STATIC_RUNTIME)
93+
.static_crt(true)
94+
.profile("Release")
95+
.define("WITH_STATIC_RUNTIME", "ON")
9796
.define("WITH_LIBXML", WITH_LIBXML)
9897
.define("WITH_EXPAT", WITH_EXPAT)
9998
//
@@ -118,12 +117,13 @@ fn build_and_link_libsbml(dep_build: &str) -> miette::Result<String> {
118117
.define("BUILD_SHARED_LIBS", "OFF")
119118
.build()
120119
} else {
120+
println!("cargo:warning=Building libSBML for MacOS/Linux");
121121
// When building for MacOS and Linux, we can just use the system libraries
122122
cmake::Config::new(LIBSBML_PATH)
123-
.define("WITH_STATIC_RUNTIME", WITH_STATIC_RUNTIME)
123+
.profile("Release")
124+
.define("WITH_STATIC_RUNTIME", "OFF")
124125
.define("WITH_LIBXML", WITH_LIBXML)
125126
.define("WITH_EXPAT", WITH_EXPAT)
126-
.define("LIBSBML_USE_STRICT_INCLUDES", "True")
127127
.build()
128128
};
129129

@@ -151,16 +151,22 @@ fn build_and_link_libsbml(dep_build: &str) -> miette::Result<String> {
151151
/// # Returns
152152
/// * `miette::Result<String>` - Build directory path on success, error on failure
153153
fn build_and_link_sbml_deps() -> miette::Result<String> {
154+
println!("cargo:warning=Building libSBML dependencies");
155+
154156
// Build the dependencies for libSBML
155157
// We hard-code to EXPAT and ZLIB for now, but in the future this should
156158
// be made more flexible.
157159
let dst = cmake::Config::new(LIBSBML_DEPENDENCY_DIR)
158-
.define("WITH_EXPAT", "True")
159-
.define("WITH_LIBXML", "False")
160-
.define("WITH_ZLIB", "True")
161-
.define("WITH_BZIP2", "False")
162-
.define("WITH_CHECK", "False")
163-
.define("BUILD_SHARED_LIBS", "False")
160+
.static_crt(true)
161+
.profile("Release")
162+
.define("WITH_STATIC_RUNTIME", "ON")
163+
.define("EXPAT_MSVC_STATIC_CRT", "ON")
164+
.define("WITH_EXPAT", "ON")
165+
.define("WITH_LIBXML", "OFF")
166+
.define("WITH_ZLIB", "ON")
167+
.define("WITH_BZIP2", "OFF")
168+
.define("WITH_CHECK", "OFF")
169+
.define("BUILD_SHARED_LIBS", "OFF")
164170
.build();
165171

166172
// Configure cargo to link against the built libraries

0 commit comments

Comments
 (0)