Skip to content

Commit 58f7fee

Browse files
authored
Use relocatable folders for the scripts (#56)
1 parent a3335e7 commit 58f7fee

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ObjectFile = "d8793406-e978-5875-9003-1fc021f44a92"
1111
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
1212
Patchelf_jll = "f2cf89d6-2bfd-5c44-bd2c-068eea195c0c"
1313
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
14+
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00"
1415
StructIO = "53d494c1-5632-5724-8f4c-31dff12d585f"
1516

1617
[compat]
@@ -21,6 +22,7 @@ ObjectFile = "0.5"
2122
PackageCompiler = "2"
2223
Patchelf_jll = "0.18"
2324
Pkg = "1"
25+
RelocatableFolders = "1"
2426
StructIO = "0.3"
2527
julia = "1.10"
2628

src/JuliaC.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
module JuliaC
22

3-
@static if VERSION >= v"1.12.0-rc1"
43
using Pkg
54
using PackageCompiler
65
using LazyArtifacts
6+
using RelocatableFolders
7+
8+
@static if VERSION >= v"1.12.0-rc1"
79

810
include("JuliaConfig.jl")
11+
const SCRIPTS_DIR = @path joinpath(@__DIR__, "scripts")
912

1013
Base.@kwdef mutable struct ImageRecipe
1114
# codegen options

src/compiling.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function compile_products(recipe::ImageRecipe)
100100
for a in recipe.julia_args
101101
cmd = `$cmd $a`
102102
end
103-
cmd = `$cmd $(joinpath(@__DIR__, "scripts", "juliac-buildscript.jl")) --source $(abspath(recipe.file)) $(recipe.output_type)`
103+
cmd = `$cmd $(joinpath(JuliaC.SCRIPTS_DIR, "juliac-buildscript.jl")) --scripts-dir $(JuliaC.SCRIPTS_DIR) --source $(abspath(recipe.file)) $(recipe.output_type)`
104104
if recipe.add_ccallables
105105
cmd = `$cmd --compile-ccallable`
106106
end

src/scripts/juliac-buildscript.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ end
2727
# --output-<type> : One of: exe | lib | sysimage | o | bc. Controls entrypoint setup.
2828
# --compile-ccallable : Export ccallable entrypoints (for shared libraries).
2929
# --use-loaded-libs : Enable Libdl.dlopen override to reuse existing loads.
30-
source_path, output_type, add_ccallables, use_loaded_libs = let
30+
# --scripts-dir <path> : Directory containing build helper scripts.
31+
source_path, output_type, add_ccallables, use_loaded_libs, scripts_dir = let
3132
source_path = ""
3233
output_type = ""
3334
add_ccallables = false
3435
use_loaded_libs = false
36+
scripts_dir = abspath(dirname(PROGRAM_FILE))
3537
it = Iterators.Stateful(ARGS)
3638
for arg in it
3739
if startswith(arg, "--source=")
@@ -40,6 +42,12 @@ source_path, output_type, add_ccallables, use_loaded_libs = let
4042
nextarg = popfirst!(it)
4143
nextarg === nothing && error("Missing value for --source")
4244
source_path = nextarg
45+
elseif startswith(arg, "--scripts-dir=")
46+
scripts_dir = split(arg, "=", limit=2)[2]
47+
elseif arg == "--scripts-dir"
48+
nextarg = popfirst!(it)
49+
nextarg === nothing && error("Missing value for --scripts-dir")
50+
scripts_dir = nextarg
4351
elseif arg == "--output-exe" || arg == "--output-lib" || arg == "--output-sysimage" || arg == "--output-o" || arg == "--output-bc"
4452
output_type = arg
4553
elseif arg == "--compile-ccallable" || arg == "--add-ccallables"
@@ -49,7 +57,7 @@ source_path, output_type, add_ccallables, use_loaded_libs = let
4957
end
5058
end
5159
source_path == "" && error("Missing required --source <path>")
52-
(source_path, output_type, add_ccallables, use_loaded_libs)
60+
(source_path, output_type, add_ccallables, use_loaded_libs, scripts_dir)
5361
end
5462

5563
# Load user code
@@ -135,13 +143,13 @@ end
135143
Core.Compiler._verify_trim_world_age[] = Base.get_world_counter()
136144

137145
if Base.JLOptions().trim != 0
138-
include(joinpath(@__DIR__, "juliac-trim-base.jl"))
139-
include(joinpath(@__DIR__, "juliac-trim-stdlib.jl"))
146+
include(joinpath(scripts_dir, "juliac-trim-base.jl"))
147+
include(joinpath(scripts_dir, "juliac-trim-stdlib.jl"))
140148
end
141149

142150
# Optionally install Libdl overrides to reuse existing loaded libs on absolute dlopen
143151
if use_loaded_libs
144-
include(joinpath(@__DIR__, "juliac-libdl-overrides.jl"))
152+
include(joinpath(scripts_dir, "juliac-libdl-overrides.jl"))
145153
end
146154

147155
empty!(Core.ARGS)

0 commit comments

Comments
 (0)