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

General build and init fixes and improvements #92

Closed
wants to merge 5 commits into from

Conversation

Allardvm
Copy link
Contributor

@Allardvm Allardvm commented Jun 3, 2017

This PR provides a more resilient build process.

  • The OSX Homebrew scripts no longer relies on Homebrew.jl's imagemagick@6 prefix. This should prevent issues when Homebrew changes the installed version of imagemagick@6 outside of the ImageMagick.jl build script.
  • ImageMagick.libversion is now set during __init__() to make sure it always reflects the library's version—even when the library is updated post-build.
  • deps.jl no longer defines an init_deps() function. The initialization of the library is handled in __init__(). This function sets the environment variables using the init_envs dictionary that is set on-demand during the build process (to allow precompilation), and then calls ccall((:MagickWandGenesis, libwand), Void, ()). As far as I can see, the fix in Re-fixes issue #12, reintroduced due to 286138d #91 is no longer necessary with this setup.

ccall((:MagickWandGenesis, libwand), Void, ())
p = ccall((:MagickQueryConfigureOption, libwand), Ptr{UInt8}, (Ptr{UInt8}, ),
"LIB_VERSION_NUMBER")
global const libversion = VersionNumber(join(split(unsafe_string(p), ',')[1:3], '.'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global const?
does this really need to be done at run-time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's global in the module's namespace, so only accessible with ImageMagick.libversion—not with libversion. I would expect users to interpret it as reflecting the version of the library that's currently loaded, which suggests that we should define it at run-time.

Nevertheless, the check at https://github.com/JuliaIO/ImageMagick.jl/blob/master/src/ImageMagick.jl#L155 is still precompiled, so that still won't reflect the real library version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is precompile friendly i.e. global const within __init__

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JuliaLang/julia#12010 indeed suggests that it's better not to use this. We could define it at compile-time, but I don't think it'll be clear to users that libversion might not reflect the actual version of the library.

We could also follow PyCall's solution: https://github.com/JuliaPy/PyCall.jl/blob/1d755f27fd440a43b9a792919fee0531495754e0/src/pyinit.jl#L50, where the version number seems to be defined at compile time, but checked at runtime.

Another alternative is to declare libversion = Ref{VersionNumber}() and update its value during __init__. This would mean that users have to call ImageMagick.libversion[] to get the version number.

Or maybe you have some other alternative?

Copy link
Contributor Author

@Allardvm Allardvm Jun 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make the last case a bit more user-friendly with:

const _libversion = Ref{VersionNumber}()

function __init__()
    _libversion[] = ...
end

libversion() = _libversion[]

Copy link
Member

@musm musm Jun 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global const Ref +1
const _libversion = Ref{VersionNumber}()

@Allardvm
Copy link
Contributor Author

Allardvm commented Jun 3, 2017

Alright, I have used a Ref to avoid using a global const in __init__(), but this doesn't fix the Windows build. I'm having some issues figuring out what's going on, even with access to a Windows machine.

For some reason, the tests don't pass when I call Pkg.test("ImageMagick") immediately, but they do pass when I call using ImageMagick first—even though runtests.jl includes using ImageMagick.
The issue has to do with when the environment variables get set. If I alter the first lines of runtests.jl to start with

ENV["MAGICK_CONFIGURE_PATH"] = [my system's path]
ENV["MAGICK_CODER_MODULE_PATH"] = [my system's path] 
using ImageMagick

then the tests always pass, but setting the environment variables after using ImageMagick doesn't make them pass. I also noticed that omitting every ccall to libwand in __init__() makes the tests pass, but it's not the ccalls themselves that make the tests fail otherwise, because the version number call returns valid information. Apparently, it just messes things up for future calls. I checked that the call to __init__() actually sets the environment variables—and it does. I'm a bit at a loss. Considering the amount of discussion this issue has had in the past (even back when this was part of Images.jl), the root cause must be quite obscure. I'll give this another shot tomorrow.

@Allardvm
Copy link
Contributor Author

Allardvm commented Jun 5, 2017

Closing this in favor of #93.

@Allardvm Allardvm closed this Jun 5, 2017
@Allardvm Allardvm deleted the osx-build-fix branch June 7, 2017 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants