Skip to content

Commit 634210b

Browse files
committed
Add LLVM_TOOLS_INSTALL_DIR to configure
1 parent be6b5b2 commit 634210b

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:
@@ -105,10 +111,11 @@ async def maybe_run(
105111
args: typing.Iterable[str],
106112
echo: bool = False,
107113
llvm_version: str = _LLVM_VERSION,
114+
llvm_tools_install_dir: str | None = None,
108115
) -> str | None:
109116
"""Run an LLVM tool if it can be found. Otherwise, return None."""
110117

111-
path = await _find_tool(tool, llvm_version, echo=echo)
118+
path = await _find_tool(tool, llvm_version, llvm_tools_install_dir, echo=echo)
112119
return path and await _run(path, args, echo=echo)
113120

114121

@@ -117,10 +124,17 @@ async def run(
117124
args: typing.Iterable[str],
118125
echo: bool = False,
119126
llvm_version: str = _LLVM_VERSION,
127+
llvm_tools_install_dir: str | None = None,
120128
) -> str:
121129
"""Run an LLVM tool if it can be found. Otherwise, raise RuntimeError."""
122130

123-
output = await maybe_run(tool, args, echo=echo, llvm_version=llvm_version)
131+
output = await maybe_run(
132+
tool,
133+
args,
134+
echo=echo,
135+
llvm_version=llvm_version,
136+
llvm_tools_install_dir=llvm_tools_install_dir,
137+
)
124138
if output is None:
125139
raise RuntimeError(f"Can't find {tool}-{llvm_version}!")
126140
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")
@@ -181,14 +190,22 @@ async def _compile(
181190
*shlex.split(self.cflags),
182191
]
183192
await _llvm.run(
184-
"clang", args_s, echo=self.verbose, llvm_version=self.llvm_version
193+
"clang",
194+
args_s,
195+
echo=self.verbose,
196+
llvm_version=self.llvm_version,
197+
llvm_tools_install_dir=self.llvm_tools_install_dir,
185198
)
186199
self.optimizer(
187200
s, label_prefix=self.label_prefix, symbol_prefix=self.symbol_prefix
188201
).run()
189202
args_o = [f"--target={self.triple}", "-c", "-o", f"{o}", f"{s}"]
190203
await _llvm.run(
191-
"clang", args_o, echo=self.verbose, llvm_version=self.llvm_version
204+
"clang",
205+
args_o,
206+
echo=self.verbose,
207+
llvm_version=self.llvm_version,
208+
llvm_tools_install_dir=self.llvm_tools_install_dir,
192209
)
193210
return await self._parse(o)
194211

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
@@ -2787,7 +2787,7 @@ AS_VAR_IF([jit_flags],
27872787
[],
27882788
[AS_VAR_APPEND([CFLAGS_NODIST], [" $jit_flags"])
27892789
AS_VAR_SET([REGEN_JIT_COMMAND],
2790-
["\$(PYTHON_FOR_REGEN) \$(srcdir)/Tools/jit/build.py ${ARCH_TRIPLES:-$host} --output-dir . --pyconfig-dir . --cflags=\"$CFLAGS_JIT\" --llvm-version=\"$LLVM_VERSION\""])
2790+
["\$(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\""])
27912791
AS_VAR_IF([Py_DEBUG],
27922792
[true],
27932793
[AS_VAR_APPEND([REGEN_JIT_COMMAND], [" --debug"])],

0 commit comments

Comments
 (0)