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

Support building with ImageMagick from MSYS2 #114

Merged
merged 3 commits into from
Dec 1, 2023
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
25 changes: 25 additions & 0 deletions .github/workflows/test-msys2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Run tests on Windows

on:
workflow_dispatch:

env:
IMAGE_MAGICK_LIBS: "libMagickCore-7.Q16HDRI.dll.a;libMagickWand-7.Q16HDRI.dll.a"

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
shell: C:\msys64\usr\bin\bash.exe --login '{0}'
run: |
export PATH="/mingw64/bin:$PATH"
pacman --noconfirm -S mingw-w64-x86_64-imagemagick mingw-w64-x86_64-pkg-config
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Test
run: |
$env:PATH = "C:\msys64\usr\bin;C:\msys64\mingw64\bin;$env:PATH"
cargo test -- --skip background --skip negate_image
31 changes: 30 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ use std::process::Command;
const MIN_VERSION: &str = "7.0";
const MAX_VERSION: &str = "7.2";

#[cfg(windows)]
static HEADER: &str = r#"
#if !defined(ssize_t) && !defined(__MINGW32__)
#if defined(_WIN64)
typedef __int64 ssize_t;
#else
typedef long ssize_t;
#endif
#endif

#include <MagickWand/MagickWand.h>
"#;
#[cfg(not(windows))]
static HEADER: &str = "#include <MagickWand/MagickWand.h>\n";

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

fn main() {
let check_cppflags = Command::new("MagickCore-config").arg("--cppflags").output();
let check_cppflags = if cfg!(target_os = "windows") {
// Resolve bash from directories listed in the PATH environment variable in the
// order they appear.
Command::new("cmd")
.arg("/C")
.arg("bash")
.arg("MagickCore-config")
.arg("--cppflags")
.output()
} else {
Command::new("MagickCore-config").arg("--cppflags").output()
};
if let Ok(ok_cppflags) = check_cppflags {
let cppflags = ok_cppflags.stdout;
let cppflags = String::from_utf8(cppflags).unwrap();
Expand Down Expand Up @@ -236,6 +260,11 @@ fn determine_mode<T: AsRef<str>>(libdirs: &Vec<PathBuf>, libs: &[T]) -> &'static
(true, false) => return "static",
(false, true) => return "dylib",
(false, false) => {
let can_static_verbatim = libs.iter().all(|l| files.contains(l.as_ref()));
if can_static_verbatim {
return "static:+verbatim";
}

panic!(
"ImageMagick libdirs at `{:?}` do not contain the required files \
to either statically or dynamically link ImageMagick",
Expand Down