Skip to content

Commit 4442ea4

Browse files
committed
Merge branch 'mr/leger/master/fix-build-with-graalvm-24-and-secure-control-plane' into 'master'
Fix build with secure control plane Closes #549 See merge request eng/libadalang/langkit-query-language!544
2 parents 4cd2576 + 63c7e45 commit 4442ea4

File tree

1 file changed

+45
-23
lines changed

1 file changed

+45
-23
lines changed

lkql_jit/standalone/make_native.py

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""----------------------------------------------------------------------------
22
-- L K Q L J I T --
33
-- --
4-
-- Copyright (C) 2023, AdaCore --
4+
-- Copyright (C) 2023-2025, AdaCore --
55
-- --
66
-- This library is free software; you can redistribute it and/or modify it --
77
-- under terms of the GNU General Public License as published by the Free --
@@ -41,13 +41,16 @@
4141
"""
4242

4343
import os
44-
import os.path as P
4544
import subprocess
4645
import sys
4746

47+
from pathlib import Path
48+
4849
sys.path.append("..")
50+
# noinspection PyUnresolvedReferences
4951
from utils import GraalManager, parse_args, is_windows
5052

53+
5154
def look_for_files_in_env(files: list[str], env_var_name: str) -> dict[str, str] | None:
5255
"""
5356
Look for required `files` in directories listed in the value of the
@@ -56,19 +59,20 @@ def look_for_files_in_env(files: list[str], env_var_name: str) -> dict[str, str]
5659
cannot be retrieved this function returns `None` and displays error message
5760
about file not being found.
5861
"""
59-
res = {f: None for f in files}
60-
for dir in os.environ.get(env_var_name, "").split(os.pathsep):
62+
res: dict[str, str | None] = {f: None for f in files}
63+
for directory in os.environ.get(env_var_name, "").split(os.pathsep):
6164
for file in files:
62-
if os.path.isfile(os.path.join(dir, file)):
63-
res[file] = dir
65+
if Path(directory, file).is_file():
66+
res[file] = directory
6467
break
6568
one_not_found = False
66-
for file, dir in res.items():
67-
if dir is None:
69+
for file, directory in res.items():
70+
if directory is None:
6871
one_not_found = True
69-
print(f"Cannot find \"{file}\" in {env_var_name}")
72+
print(f'Cannot find "{file}" in {env_var_name}')
7073
return None if one_not_found else res
7174

75+
7276
if __name__ == "__main__":
7377
# Create utils
7478
graal = GraalManager()
@@ -93,31 +97,49 @@ def look_for_files_in_env(files: list[str], env_var_name: str) -> dict[str, str]
9397

9498
# We also need to provide rpath-links to the compiler to allow it to
9599
# find libraries during linking phase.
96-
ld_library_path = os.environ.get('LD_LIBRARY_PATH')
100+
ld_library_path = os.environ.get("LD_LIBRARY_PATH")
97101
rpaths = (
98102
[f"-Wl,-rpath-link={p}" for p in ld_library_path.split(os.pathsep)]
99-
if ld_library_path else
100-
[]
103+
if ld_library_path
104+
else []
101105
)
102106

103-
os_specific_options.extend([
104-
# The G1 garbage collector is only supported on Linux for now
105-
"--gc=G1",
106-
107-
# Then we add additional options for the C compiler
108-
*[f"--native-compiler-options=-I{dir}" for dir in headers_paths.values()],
109-
*[f"--native-compiler-options=-L{dir}" for dir in libs_paths.values()],
110-
*[f"--native-compiler-options={rp}" for rp in rpaths],
111-
])
107+
os_specific_options.extend(
108+
[
109+
# The G1 garbage collector is only supported on Linux for now
110+
"--gc=G1",
111+
# Then we add additional options for the C compiler
112+
*[
113+
f"--native-compiler-options=-I{header_dir}"
114+
for header_dir in headers_paths.values()
115+
],
116+
*[
117+
f"--native-compiler-options=-L{lib_dir}"
118+
for lib_dir in libs_paths.values()
119+
],
120+
*[f"--native-compiler-options={rp}" for rp in rpaths],
121+
]
122+
)
112123

113124
# Run the Native-Image compiler if required by the build process
114125
if "lkql_cli" in args.native_components:
126+
# Get the buildspace tmp dir to set the polyglot cache path. When
127+
# built in docker images (where only the buildspace is writable), the
128+
# build crashes because it tries to create $HOME/.cache. This behavior
129+
# may be overridden by the polyglot.engine.userResourceCache value.
130+
# There is nothing in args (build_mode, classpath native_components) to
131+
# give a clue about buildspace location, guess it from this file's path.
132+
buildspace: Path = Path(__file__).parents[3]
133+
tmp_path: Path = Path(buildspace, "tmp")
134+
115135
# Create the base Native-Image command
116136
cmd = [
117137
graal.native_image,
118-
"-cp", args.classpath,
138+
"-cp",
139+
args.classpath,
119140
"--no-fallback",
120141
"--initialize-at-build-time",
142+
f"-Dpolyglot.engine.userResourceCache={tmp_path.as_posix()}",
121143
*os_specific_options,
122144
]
123145

@@ -145,7 +167,7 @@ def look_for_files_in_env(files: list[str], env_var_name: str) -> dict[str, str]
145167
# Finally specify the main class name and the output file
146168
final_cmd = cmd + [
147169
"com.adacore.lkql_jit.cli.LKQLMain",
148-
P.join("target", "lkql"),
170+
str(Path("target", "lkql")),
149171
]
150172

151173
# Debug print and run

0 commit comments

Comments
 (0)