Skip to content

Commit

Permalink
Update embeding flags (#17454)
Browse files Browse the repository at this point in the history
* Include threading flags. Fix #16868
* Add document about exporting symbols from main executable. Fix #17451
  • Loading branch information
yuyichao authored and vtjnash committed Jul 18, 2016
1 parent 04f1092 commit b390d66
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions contrib/julia-config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const options =
"--ldlibs"
];

threadingOn() = ccall(:jl_threading_enabled, Cint, ()) != 0

function imagePath()
opts = Base.JLOptions()
unsafe_string(opts.image_file)
Expand Down Expand Up @@ -57,10 +59,11 @@ end
function cflags()
arg1 = replace(initDir(),"\\","\\\\\\\\")
arg2 = replace(includeDir(),"\\","\\\\")
threading_def = threadingOn() ? "-DJULIA_ENABLE_THREADING=1 " : ""
if is_unix()
return """-fPIC -DJULIA_INIT_DIR=\\"$arg1\\" -I$arg2"""
return """$(threading_def)-fPIC -DJULIA_INIT_DIR=\\"$arg1\\" -I$arg2"""
else
return """-DJULIA_INIT_DIR=\\"$arg1\\" -I$arg2"""
return """$(threading_def)-DJULIA_INIT_DIR=\\"$arg1\\" -I$arg2"""
end
end

Expand Down
4 changes: 4 additions & 0 deletions doc/manual/embedding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Before the program terminates, it is strongly recommended to call ``jl_atexit_ho
>>> julia.jl_init('.')
250593296

.. note::

If the julia program needs to access symbols from the main executable, it may be necessary to add ``-Wl,--export-dynamic`` linker flag at compile time on Linux in addition to the ones generated by ``julia-config.jl`` described below. This is not necessary when compiling a shared library.

Using julia-config to automatically determine build parameters
--------------------------------------------------------------

Expand Down
9 changes: 9 additions & 0 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,15 @@ JL_DLLEXPORT size_t jl_maxrss(void)
#endif
}

JL_DLLEXPORT int jl_threading_enabled(void)
{
#ifdef JULIA_ENABLE_THREADING
return 1;
#else
return 0;
#endif
}

#ifdef __cplusplus
}
#endif
9 changes: 9 additions & 0 deletions test/threads.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,12 @@ let async = Base.AsyncCondition(), t
@test_throws EOFError wait(t)
@test_throws EOFError wait(async)
end

# Compare the two ways of checking if threading is enabled.
# `jl_tls_states` should only be defined on non-threading build.
if ccall(:jl_threading_enabled, Cint, ()) == 0
@test nthreads() == 1
cglobal(:jl_tls_states) != C_NULL
else
@test_throws ErrorException cglobal(:jl_tls_states)
end

0 comments on commit b390d66

Please sign in to comment.