Skip to content

Commit a57427c

Browse files
committed
Add LLVM_TOOLS_INSTALL_DIR to configure
1 parent e9c2cc3 commit a57427c

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

Tools/jit/_llvm.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,16 @@ async def _get_brew_llvm_prefix(llvm_version: str, *, echo: bool = False) -> str
7171

7272

7373
@_async_cache
74-
async def _find_tool(tool: str, llvm_version: str, *, echo: bool = False) -> str | None:
74+
async def _find_tool(
75+
tool: str,
76+
llvm_version: str,
77+
llvm_tools_install_dir: str | None,
78+
*,
79+
echo: bool = False,
80+
) -> str | None:
7581
# Explicitly defined LLVM installation location
76-
if llvm_tools_dir := os.getenv("LLVM_TOOLS_INSTALL_DIR"):
77-
path = os.path.join(llvm_tools_dir, tool)
82+
if llvm_tools_install_dir:
83+
path = os.path.join(llvm_tools_install_dir, tool)
7884
if await _check_tool_version(path, llvm_version, echo=echo):
7985
return path
8086
# Unversioned executables:
@@ -110,10 +116,11 @@ async def maybe_run(
110116
args: typing.Iterable[str],
111117
echo: bool = False,
112118
llvm_version: str = _LLVM_VERSION,
119+
llvm_tools_install_dir: str | None = None,
113120
) -> str | None:
114121
"""Run an LLVM tool if it can be found. Otherwise, return None."""
115122

116-
path = await _find_tool(tool, llvm_version, echo=echo)
123+
path = await _find_tool(tool, llvm_version, llvm_tools_install_dir, echo=echo)
117124
return path and await _run(path, args, echo=echo)
118125

119126

@@ -122,10 +129,17 @@ async def run(
122129
args: typing.Iterable[str],
123130
echo: bool = False,
124131
llvm_version: str = _LLVM_VERSION,
132+
llvm_tools_install_dir: str | None = None,
125133
) -> str:
126134
"""Run an LLVM tool if it can be found. Otherwise, raise RuntimeError."""
127135

128-
output = await maybe_run(tool, args, echo=echo, llvm_version=llvm_version)
136+
output = await maybe_run(
137+
tool,
138+
args,
139+
echo=echo,
140+
llvm_version=llvm_version,
141+
llvm_tools_install_dir=llvm_tools_install_dir,
142+
)
129143
if output is None:
130144
raise RuntimeError(f"Can't find {tool}-{llvm_version}!")
131145
return output

Tools/jit/_targets.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class _Target(typing.Generic[_S, _R]):
5151
verbose: bool = False
5252
cflags: str = ""
5353
llvm_version: str = _llvm._LLVM_VERSION
54+
llvm_tools_install_dir: str | None = None
5455
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
5556
pyconfig_dir: pathlib.Path = pathlib.Path.cwd().resolve()
5657

@@ -83,7 +84,11 @@ async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup:
8384
group = _stencils.StencilGroup()
8485
args = ["--disassemble", "--reloc", f"{path}"]
8586
output = await _llvm.maybe_run(
86-
"llvm-objdump", args, echo=self.verbose, llvm_version=self.llvm_version
87+
"llvm-objdump",
88+
args,
89+
echo=self.verbose,
90+
llvm_version=self.llvm_version,
91+
llvm_tools_install_dir=self.llvm_tools_install_dir,
8792
)
8893
if output is not None:
8994
# Make sure that full paths don't leak out (for reproducibility):
@@ -103,7 +108,11 @@ async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup:
103108
f"{path}",
104109
]
105110
output = await _llvm.run(
106-
"llvm-readobj", args, echo=self.verbose, llvm_version=self.llvm_version
111+
"llvm-readobj",
112+
args,
113+
echo=self.verbose,
114+
llvm_version=self.llvm_version,
115+
llvm_tools_install_dir=self.llvm_tools_install_dir,
107116
)
108117
# --elf-output-style=JSON is only *slightly* broken on Mach-O...
109118
output = output.replace("PrivateExtern\n", "\n")
@@ -177,14 +186,22 @@ async def _compile(
177186
*shlex.split(self.cflags),
178187
]
179188
await _llvm.run(
180-
"clang", args_s, echo=self.verbose, llvm_version=self.llvm_version
189+
"clang",
190+
args_s,
191+
echo=self.verbose,
192+
llvm_version=self.llvm_version,
193+
llvm_tools_install_dir=self.llvm_tools_install_dir,
181194
)
182195
self.optimizer(
183196
s, label_prefix=self.label_prefix, symbol_prefix=self.symbol_prefix
184197
).run()
185198
args_o = [f"--target={self.triple}", "-c", "-o", f"{o}", f"{s}"]
186199
await _llvm.run(
187-
"clang", args_o, echo=self.verbose, llvm_version=self.llvm_version
200+
"clang",
201+
args_o,
202+
echo=self.verbose,
203+
llvm_version=self.llvm_version,
204+
llvm_tools_install_dir=self.llvm_tools_install_dir,
188205
)
189206
return await self._parse(o)
190207

Tools/jit/build.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
"--cflags", help="additional flags to pass to the compiler", default=""
4444
)
4545
parser.add_argument("--llvm-version", help="LLVM version to use")
46+
parser.add_argument(
47+
"--llvm-tools-install-dir", help="Installation location of LLVM tools"
48+
)
4649
args = parser.parse_args()
4750
for target in args.target:
4851
target.debug = args.debug
@@ -52,6 +55,8 @@
5255
target.pyconfig_dir = args.pyconfig_dir
5356
if args.llvm_version:
5457
target.llvm_version = args.llvm_version
58+
if args.llvm_tools_install_dir:
59+
target.llvm_tools_install_dir = args.llvm_tools_install_dir
5560
target.build(
5661
comment=comment,
5762
force=args.force,

configure

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2804,7 +2804,7 @@ AS_VAR_IF([jit_flags],
28042804
[],
28052805
[AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
28062806
AS_VAR_SET([REGEN_JIT_COMMAND],
2807-
["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"$CFLAGS_JIT\" --llvm-version=\"$LLVM_VERSION\""])
2807+
["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"$CFLAGS_JIT\" --llvm-version=\"$LLVM_VERSION\" --llvm-tools-install-dir=\"$LLVM_TOOLS_INSTALL_DIR\""])
28082808
AS_VAR_IF([Py_DEBUG],
28092809
[true],
28102810
[AS_VAR_APPEND([REGEN_JIT_COMMAND], [" --debug"])],

0 commit comments

Comments
 (0)