Skip to content

Commit bbe1aae

Browse files
authored
Merge pull request #114 from gyk/fix/msys2
Support building with ImageMagick from MSYS2
2 parents c9d8488 + 1d6c19d commit bbe1aae

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

.github/workflows/test-msys2.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Run tests on Windows
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
IMAGE_MAGICK_LIBS: "libMagickCore-7.Q16HDRI.dll.a;libMagickWand-7.Q16HDRI.dll.a"
8+
9+
jobs:
10+
build:
11+
runs-on: windows-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Install dependencies
15+
shell: C:\msys64\usr\bin\bash.exe --login '{0}'
16+
run: |
17+
export PATH="/mingw64/bin:$PATH"
18+
pacman --noconfirm -S mingw-w64-x86_64-imagemagick mingw-w64-x86_64-pkg-config
19+
- uses: Swatinem/rust-cache@v2
20+
with:
21+
cache-on-failure: true
22+
- name: Test
23+
run: |
24+
$env:PATH = "C:\msys64\usr\bin;C:\msys64\mingw64\bin;$env:PATH"
25+
cargo test -- --skip background --skip negate_image

build.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ use std::process::Command;
2626
const MIN_VERSION: &str = "7.0";
2727
const MAX_VERSION: &str = "7.2";
2828

29+
#[cfg(windows)]
30+
static HEADER: &str = r#"
31+
#if !defined(ssize_t) && !defined(__MINGW32__)
32+
#if defined(_WIN64)
33+
typedef __int64 ssize_t;
34+
#else
35+
typedef long ssize_t;
36+
#endif
37+
#endif
38+
39+
#include <MagickWand/MagickWand.h>
40+
"#;
41+
#[cfg(not(windows))]
2942
static HEADER: &str = "#include <MagickWand/MagickWand.h>\n";
3043

3144
//on windows path env always contain : like c:
@@ -35,7 +48,18 @@ pub const PATH_SEPARATOR: &str = match cfg!(target_os = "windows") {
3548
};
3649

3750
fn main() {
38-
let check_cppflags = Command::new("MagickCore-config").arg("--cppflags").output();
51+
let check_cppflags = if cfg!(target_os = "windows") {
52+
// Resolve bash from directories listed in the PATH environment variable in the
53+
// order they appear.
54+
Command::new("cmd")
55+
.arg("/C")
56+
.arg("bash")
57+
.arg("MagickCore-config")
58+
.arg("--cppflags")
59+
.output()
60+
} else {
61+
Command::new("MagickCore-config").arg("--cppflags").output()
62+
};
3963
if let Ok(ok_cppflags) = check_cppflags {
4064
let cppflags = ok_cppflags.stdout;
4165
let cppflags = String::from_utf8(cppflags).unwrap();
@@ -236,6 +260,11 @@ fn determine_mode<T: AsRef<str>>(libdirs: &Vec<PathBuf>, libs: &[T]) -> &'static
236260
(true, false) => return "static",
237261
(false, true) => return "dylib",
238262
(false, false) => {
263+
let can_static_verbatim = libs.iter().all(|l| files.contains(l.as_ref()));
264+
if can_static_verbatim {
265+
return "static:+verbatim";
266+
}
267+
239268
panic!(
240269
"ImageMagick libdirs at `{:?}` do not contain the required files \
241270
to either statically or dynamically link ImageMagick",

0 commit comments

Comments
 (0)