-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Add a julia-config script for configuration of externals #10069
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
Conversation
end | ||
|
||
function libDir() | ||
@windows_only dir = joinpath(Base.JULIA_HOME, "julia"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't right - there's no julia
subdirectory of JULIA_HOME
, on Windows the executables and shared libraries are all in bin. Except that sys.ji
and sys.dll
are in the same lib/julia
location everywhere.
Also please use 4-space indents for consistency with the rest of base.
You're right, the windows args are generally incorrect. Will fix both. Otherwise, what about -I and -L, is that correct on windows? Is gcc used there? Or is the like /L and /I? I have a system to test with, but need a little help getting started, are the embedding docs generally correct? How about MSVC? |
I don't know whether anyone has tried embedding Julia within an MSVC application recently. If you use MinGW gcc then link flags will be |
Updated, and tested on Linux and OS/X and Windows. I'm not sure what's up with AppVeyor; I couldn't check the error because the website timed out -- maybe that's what's up. |
You hit #10045 on win32, not your fault. I restarted the build. I think we should get some other people who've been embedding Julia in various different environments to have a look at this and try it out. |
Ok! How shall we let them know? |
Notifications should work. I think @armgong has been embedding Julia in R, and several people have been working on pyjulia, maybe just searching the issues list for "embedding" would give a good sense of who might find this useful. |
thanks a alot, I will try it. could make this be a standalone execute file not a script? |
I think you mean run it without having to do julia julia-config.jl? Yea it can be done. I have not tested this everywhere, but it illustrates the point... copy it
then edit it to define the interpreter -- apparently you don't have to explicitly qualify
make it executable
then run it (Windows example)
|
Right, but on Windows that'll only work inside a posix environment like Cygwin or MSYS. Nothing wrong with adding the shebang or making the file executable, but please keep the .jl extension. |
The shebang line should probably be |
works, I like it. Also tested it you use a julia not in path explicitly, it overrides the default which is nice. will update. |
and how about change function libDir()
@unix_only return match(r"(.*)(sys.ji)",imagePath()).captures[1];
@windows_only return Base.JULIA_HOME;
end to function libDir()
return abspath(dirname(Sys.dlpath("libjulia"));
end
) |
Hmm, sure; more correct anyway. I think abspath elsewhere rather than replace too. |
updated. I had to keep the replace, though. |
What's the status here, is this useful enough to merge? We should get more people who might want to use it to look it over. |
Well it works in all of the cases I've tried. I can start searching various issues for anything to do with this and include people. Jere are a few @tknopp @twadleigh @staticfloat @nalimilan |
Also pyjulia @jakebolewski |
I don't do any embedding, but this looks good to me. Thanks for taking the time to send out this PR, Jeff. |
hey thanks! but you totally know how this is all put together even if you don't spend time doing embedding directly, and this is part of the solution #8757, which your are interested in. |
So should this be adjusting https://github.com/JuliaLang/julia/blob/master/doc/manual/embedding.rst if we want to recommend using this method? |
Hmm, well it could certainly makes things easier. It could be like "here, cut and paste this, it always works," kind of documentation, which is easy to follow. There could be created an example Makefile that uses it (here download this and mod to to suit your needs) -- I could add that. OTOH, it's been tested by me and probably @armgong, but no one else. Maybe something like give this new thing a try, but here's the historical documentation too? |
I like that idea.
Sure, no need to completely replace the existing documentation if it's still accurate, but now we can add this new method to it. |
Modified and re-tested on OS/X, Linux. Windows. I changed the behavior to better cooperate with makefiles, especially the the default makefile rules. This required me to change the command line approach to using xargs, but it turns out that makes it even simpler. Also updated the embedding documentation to more-or-less track the comments below. On the command line (same for all 3 platforms)
In a Makefile (same for all 3 platforms)
Results in:
|
Very nice. Are there any other concerns pending, or is this good to merge? It looks like we've got a windows x64 failure, but that isn't due to these changes, I don't think. |
The only thing that changed from the version that passed and the one that did not is documentation. The Appveyor has something to do with linalg3. I don't have anything more with specifically this PR right now. Maybe someone want's to check the doc changes? |
Nice. If this uses |
rebase, my nemesis... kk checking it. |
Ok, updated, replaced compileropts() with JLOptions(), rechecked, verified and ... |
Looks like something went wonky with a merge commit. Try running |
that's essentially how this started. However, just in case, I (re)-tried that, but it failed horribly. |
took a guess and: rebase -i master, removed half of the commits (they are all duplicated) and then forced a push. Looks like it fixed things. |
end | ||
|
||
function ldlibs() | ||
@unix_only return replace("""-Wl,-rpath $(libDir()) -ljulia""","\\","\\\\"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be -Wl,-rpath,$(libDir())
the comma is important.
After the comma is addressed, this looks good to me. Tested it out on my OSX laptop and it seemed to work just fine. |
I remember reading the ld page thinking where did the comma go and left it out because of it, but now I see it's because of the compiler that it needs to be in -- updated. |
Yep, even more confusingly, omitting it will only break things sometimes, depending on where Julia gets installed. I'ma go ahead and merge now. Thanks for all your effort! |
Add a julia-config script for configuration of externals
First step, related to #8757. This script is styled after various other frameworks
configuration scripts such as pg_config and python-config. Currently
there are only 2 arguments --ldflags and --cflags to allow embedding applications
to automatically have the necessary compiler flags set.
A workaround for current issue with jl_init as described in #9981 is provided for
by a compiler flag -DJULIA_INIT_DIR which can be used as an argument for jl_init,
however, both can work together and this approach is currently incomplete especially
w.r.t. Windows. Tested on Linux and OS/X. Uses compileropts(),
For exmaple if an embedding program embed.cpp contains the following
it can be compiled using the following on OS/X
and on Linux (note how the command has to be split as gcc fails when libraries come before source files).
and then run
also on windows (using the msys2 environment for example)
and then run (a.exe instead of a.out)
Though the shortened form also works on Windows gcc because rpath is not used
Also, running directly not as an argument to julia is possible