Skip to content

Commit a4ef308

Browse files
committed
mk: Add the ability to depend on native LLVM tools
The compiler will require that `llvm-ar.exe` be available for MSVC-targeting builds (more comments on this soon), so this commit adds support for targets to depend on LLVM tools. The `core` library for MSVC depends on `llvm-ar.exe` which will be copied into place for the target before the compiler starts to run. Note that these targets all depend on `llvm-config.exe` to ensure that they're built before they're attempted to be copied.
1 parent 6122a5f commit a4ef308

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

mk/cfg/x86_64-pc-windows-msvc.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ endif
3939
ifdef CFG_MSVC_LINK
4040
export PATH := $(CFG_MSVC_ROOT)/VC/bin/amd64:$(PATH)
4141
endif
42+
43+
# There are more comments about this available in the target specification for
44+
# Windows MSVC in the compiler, but the gist of it is that we use `llvm-ar.exe`
45+
# instead of `lib.exe` for assembling archives, so we need to inject this custom
46+
# dependency here.
47+
NATIVE_TOOL_DEPS_core_T_x86_64-pc-windows-msvc += llvm-ar.exe

mk/llvm.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ else
5858
clean-llvm$(1):
5959
endif
6060

61+
$$(LLVM_AR_$(1)): $$(LLVM_CONFIG_$(1))
62+
6163
# This is used to independently force an LLVM clean rebuild
6264
# when we changed something not otherwise captured by builtin
6365
# dependencies. In these cases, commit a change that touches

mk/main.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ endif
292292
# Any rules that depend on LLVM should depend on LLVM_CONFIG
293293
LLVM_CONFIG_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-config$$(X_$(1))
294294
LLVM_MC_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-mc$$(X_$(1))
295+
LLVM_AR_$(1):=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-ar$$(X_$(1))
295296
LLVM_VERSION_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --version)
296297
LLVM_BINDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --bindir)
297298
LLVM_INCDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --includedir)

mk/target.mk

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ CRATE_FULLDEPS_$(1)_T_$(2)_H_$(3)_$(4) := \
3737
$$(foreach dep,$$(NATIVE_DEPS_$(4)), \
3838
$$(RT_OUTPUT_DIR_$(2))/$$(call CFG_STATIC_LIB_NAME_$(2),$$(dep))) \
3939
$$(foreach dep,$$(NATIVE_DEPS_$(4)_T_$(2)), \
40-
$$(RT_OUTPUT_DIR_$(2))/$$(dep))
40+
$$(RT_OUTPUT_DIR_$(2))/$$(dep)) \
41+
$$(foreach dep,$$(NATIVE_TOOL_DEPS_$(4)_T_$(2)), \
42+
$$(TBIN$(1)_T_$(3)_H_$(3))/$$(dep))
4143
endef
4244

4345
$(foreach host,$(CFG_HOST), \
@@ -149,6 +151,11 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/%: $$(RT_OUTPUT_DIR_$(2))/% \
149151
| $$(TLIB$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)
150152
@$$(call E, cp: $$@)
151153
$$(Q)cp $$< $$@
154+
155+
$$(TBIN$(1)_T_$(2)_H_$(3))/%: $$(CFG_LLVM_INST_DIR_$(2))/bin/% \
156+
| $$(TBIN$(1)_T_$(2)_H_$(3))/ $$(SNAPSHOT_RUSTC_POST_CLEANUP)
157+
@$$(call E, cp: $$@)
158+
$$(Q)cp $$< $$@
152159
endef
153160

154161
$(foreach source,$(CFG_HOST), \

0 commit comments

Comments
 (0)