Skip to content
This repository was archived by the owner on Mar 4, 2019. It is now read-only.
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
44 changes: 28 additions & 16 deletions juliac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
s_file = "lib" * file_name * ".$(Libdl.dlext)"
e_file = file_name * (is_windows() ? ".exe" : "")

# TODO: these should probably be emitted from julia-config also:
julia_pkglibdir = joinpath(dirname(Pkg.dir()), "lib", basename(Pkg.dir()))
shlibdir = is_windows() ? JULIA_HOME : abspath(JULIA_HOME, Base.LIBDIR)
private_shlibdir = abspath(JULIA_HOME, Base.PRIVATE_LIBDIR)

if is_windows()
julia_program = replace(julia_program, "\\", "\\\\")
Expand All @@ -146,12 +149,18 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v

delete_object = false
if object || shared || executable
command = `"$(Base.julia_cmd())" "--startup-file=no" "--output-o" "$o_file" "-e"
"include(\"$julia_program\"); push!(Base.LOAD_CACHE_PATH, \"$julia_pkglibdir\"); empty!(Base.LOAD_CACHE_PATH)"`
command = `$(Base.julia_cmd()) --startup-file=no -e "
VERSION >= v\"0.7+\" && Base.init_load_path($(repr(JULIA_HOME))) # initialize location of site-packages
empty!(Base.LOAD_CACHE_PATH) # reset / remove any builtin paths
push!(Base.LOAD_CACHE_PATH, abspath(\"ji$VERSION\")) #$(repr(julia_pkglibdir))) # enable usage of precompile files
include($(repr(julia_program)))
empty!(Base.LOAD_CACHE_PATH) # reset / remove build-system-relative paths
"`
if verbose
println("Build object file \"$o_file\":\n$command")
end
run(command)
run(command) # first populate the .ji cache (when JULIA_HOME is defined)
run(`$command --output-o $o_file`) # then output the combined file
if !object
delete_object = true
end
Expand All @@ -167,7 +176,9 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v

if shared || executable
command = `$cc -m64 -shared -o $s_file $o_file $cflags $ldflags $ldlibs`
if is_windows()
if is_apple()
command = `$command -Wl,-install_name,@rpath/lib$file_name.dylib`
elseif is_windows()
command = `$command -Wl,--export-all-symbols`
end
if verbose
Expand All @@ -178,7 +189,9 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v

if executable
command = `$cc -m64 -o $e_file $c_program $s_file $cflags $ldflags $ldlibs`
if is_unix()
if is_apple()
command = `$command -Wl,-rpath,@executable_path`
elseif is_unix()
command = `$command -Wl,-rpath,\$ORIGIN`
end
if verbose
Expand All @@ -198,15 +211,14 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
if verbose
println("Sync Julia libraries:")
end
if is_windows()
dir = JULIA_HOME
libfiles = joinpath.(dir, filter(x -> ismatch(r".+\.dll$", x), readdir(dir)))
else
dir = joinpath(JULIA_HOME, "..", "lib")
libfiles1 = joinpath.(dir, filter(x -> ismatch(r"^lib.*\.so(?:$|\.)", x), readdir(dir)))
dir = joinpath(JULIA_HOME, "..", "lib", "julia")
libfiles2 = joinpath.(dir, filter(x -> ismatch(r"^lib.*\.so(?:$|\.)", x), readdir(dir)))
libfiles = vcat(libfiles1, libfiles2)
libfiles = String[]
dlext = "." * Libdl.dlext
for dir in (shlibdir, private_shlibdir)
if is_windows() || is_apple()
append!(libfiles, joinpath.(dir, filter(x -> endswith(x, dlext), readdir(dir))))
else
append!(libfiles, joinpath.(dir, filter(x -> ismatch(r"^lib.+\.so(?:\.\d+)*$", x), readdir(dir))))
end
end
sync = false
for src in libfiles
Expand All @@ -218,11 +230,11 @@ function julia_compile(julia_program, c_program=nothing, build_dir="builddir", v
if verbose
println(" $dst")
end
cp(src, dst, remove_destination=true)
cp(src, dst, remove_destination=true, follow_symlinks=false)
sync = true
end
end
if !sync
if verbose && !sync
println(" none")
end
end
Expand Down
6 changes: 5 additions & 1 deletion program.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "uv.h"
#include "julia.h"

#ifdef JULIA_DEFINE_FAST_TLS // only available in Julia 0.7+
JULIA_DEFINE_FAST_TLS()
#endif

// Declare C prototype of a function defined in Julia
extern void julia_main();

Expand All @@ -19,7 +23,7 @@ int main(int argc, char *argv[])
uv_setup_args(argc, argv); // no-op on Windows
libsupport_init();
jl_options.image_file = "libhello";
julia_init(JL_IMAGE_CWD);
julia_init(JL_IMAGE_JULIA_HOME);

// Do some work
julia_main();
Expand Down
8 changes: 6 additions & 2 deletions program2.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "uv.h"
#include "julia.h"

#ifdef JULIA_DEFINE_FAST_TLS // only available in Julia 0.7+
JULIA_DEFINE_FAST_TLS()
#endif

// Declare C prototype of a function defined in Julia
extern int julia_main(jl_array_t*);

Expand Down Expand Up @@ -37,8 +41,8 @@ int wmain(int argc, wchar_t *wargv[], wchar_t *envp[])
// initialization
libsupport_init();
// jl_options.compile_enabled = JL_OPTIONS_COMPILE_OFF;
jl_options.image_file = "libhello.so";
julia_init(JL_IMAGE_CWD);
jl_options.image_file = "libhello";
julia_init(JL_IMAGE_JULIA_HOME);

// build arguments array: `String[ unsafe_string(argv[i]) for i in 1:argc ]`
jl_array_t *ARGS = jl_alloc_array_1d(jl_apply_array_type(jl_string_type, 1), 0);
Expand Down