Open nlfiedler opened 5 months ago
That would be very handy!
The MSYS instructions worked! What a timing, just as I started to try to compile it on windows and have issues, you added the instructions. Thanks!
Hi,
In #114 I chose mingw64 environment, but we should switch to ucrt64 as it causes fewer compatibility issues. Please see this commit. Most unit tests in v0.19 except test_set_background_color
will pass.
one of the bindings unit tests fails (size of long double)
Which one is it?
Regarding to clang, LLVM is preinstalled in the GitHub Actions runner image so it is already usable.
Never come across any problems related to mm_malloc.h
.
can we possibly build this crate on Windows without introducing a Unix-like environment?
Of course we can. I believe MSYS2 support was added to address this use case: Some application needs to be released on multiple platforms, and may require a custom build of ImageMagick. Unfortunately ImageMagick uses separate instructions to build natively on Windows and it looks complicated, in this case, using MSYS2 is preferable.
The following may be helpful for someone trying to build this crate against MSYS2.
As other Unix-like environments, there are two approaches for MSYS2:
Set up everything manually:
$env:PATH = "C:\msys64\usr\bin;C:\msys64\ucrt64\bin;$env:Path"
$env:IMAGE_MAGICK_DIR = "C:\msys64\ucrt64"
$env:IMAGE_MAGICK_INCLUDE_DIRS = "C:\msys64\ucrt64\include\ImageMagick-7"
$env:IMAGE_MAGICK_LIB_DIRS = "C:\msys64\ucrt64\lib"
$env:IMAGE_MAGICK_LIBS = "libMagickCore-7.Q16.dll.a;libMagickWand-7.Q16.dll.a"
Just rely on pkg-config
to resolve the configuration:
$env:PATH = "C:\msys64\usr\bin;C:\msys64\ucrt64\bin;$env:Path"
$env:IMAGE_MAGICK_LIBS = "libMagickCore-7.Q16.dll.a;libMagickWand-7.Q16.dll.a"
Please note that the order in $env:PATH
is important. C:\msys64\usr\bin
appears first to make sure MSYS2's sh
takes precedence over other sh.exe
installed in the system. C:\msys64\ucrt64\bin
introduces essential commands like pkg-config
and MagickCore-config
.
Also, after I built a rust project with this library, it works fine when its run from the MSYS2 MINGW64 shell. But running a compiled executable directly without the mingw64 envirenment (just running it from CMD.exe for example) causes NoDecodeDelegateForThisImageFormat 'PNG' @ error/constitute.c/ReadImage/746
error to appear. That makes me think image magick maybe relies on some env variables to find the libraries. Not sure what I could do.
Maybe something about shipping the executable on windows should be added to INSTALL.md, since you cannot just ask users to "sudo apt install libeverthing-thats-needed", windows has a funny way of installing software :) and just putting all dlls in the same folder as the .exe doesn't seem to work (it gives errors like the one I have with PNGs not opening)
@5ohue The env variable is MAGICK_CODER_MODULE_PATH
. Without it ImageMagick will try to read coder path from the registry. However, if you're willing to build ImageMagick from scratch, coder modules can be disabled by passing --without-modules
to configure.
@nlfiedler I think I found a way to compile, run and destribute an application that uses magick-rust. It requires using MSYS2 to compile, but the final executable doesn't require users to install anything additional. Here's how it worked for me:
mingw-w64-x86_64-imagemagick
, mingw-w64-x86_64-rust
and probably some more. I can try to get a nice list of packages later.$env:PATH = "C:\msys64\usr\bin;C:\msys64\mingw64\bin;$env:Path"
$env:IMAGE_MAGICK_DIR = "C:\msys64\mingw64"
$env:IMAGE_MAGICK_INCLUDE_DIRS = "C:\msys64\mingw64\include\ImageMagick-7"
$env:IMAGE_MAGICK_LIB_DIRS = "C:\msys64\mingw64\lib"
$env:IMAGE_MAGICK_LIBS = "libMagickCore-7.Q16HDRI.dll.a;libMagickWand-7.Q16HDRI.dll.a"
cd
ed into the crate's directory and built the project (cargo build --release
or cargo install --path .
or any other way to build a crate). It compiles fine here for me.ldd <PATH TO EXECUTABLE>.exe | awk '{print ($3)}' | grep "^/mingw64" | xargs -I FILE cp FILE lib/
. The lib
folder now contains all the DLL files.<APP NAME>\
bin\
*.dll
<EXECUTABLE>.exe
lib\
ImageMagick-7.1.1\
So basically I copied all the DLL files and executable to bin\
folder (and also some additional DLLs for extra file formats, like libjpeg-8.dll
file for example. The application isn't directly linked to that, so ldd
cannot know about it).
To bin\
folder I copied the ImageMagick-7.1.1
folder from C:\msys64\mingw64\lib
.
<APP NAME>
can now be packaged and shared to other computers, and the executable can be run without problems.Using The Windows-specific repo for ImageMagick and going through the process to see the eventual build scripts may help us get to a static lib. That'd solve most if not all of the issues here I think?
The existing instructions are not adequate to build this crate on Windows. I will soon submit a change that helps, but still isn't completely satisfying because one of the bindings unit tests fails (size of long double). I'm hoping someone like @gyk can offer some insight. Questions I have:
IMAGE_MAGICK_INCLUDE_DIRS
to include the path tomm_malloc.h
because without that, the build fails to find that header file. This is unlike on other platforms, which is why I wonder if I'm doing something wrong.INSTALL.md
file, if those need fixing, please let me know.Hoping someone who knows Windows better than I (who only really uses it for video games) can help.
Other concerns I have: can we possibly build this crate on Windows without introducing a Unix-like environment? For instance, using the Visual Studio Installer should suffice, but it installs a 32-bit version of Clang, which is like WTF. Hard to image how people use Windows for anything other than C# development.