From c619f371366add422ff2ae8de5c0424e35f91f6d Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <vital.had@gmail.com>
Date: Fri, 7 Nov 2025 20:03:31 +0800
Subject: [PATCH] minicargo.mk, Makefile: use external llvm

---
 minicargo.mk       | 6 ++++--
 run_rustc/Makefile | 3 ++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/minicargo.mk b/minicargo.mk
index f3fda698..055086eb 100644
--- a/minicargo.mk
+++ b/minicargo.mk
@@ -137,7 +137,8 @@ ifeq ($(RUSTC_VERSION),1.74.0)
 SRCDIR_RUST_TESTS := $(RUSTCSRC)tests/
 endif
 
-LLVM_CONFIG := $(RUSTCSRC)build/bin/llvm-config
+LLVM_CONFIG := @PREFIX@/libexec/llvm-@LLVM_V@/bin/llvm-config
+
 ifeq ($(shell uname -s || echo not),Darwin)
  # /usr/bin/uname because uname might call coreutils
  # which can make the arm64 uname called when
@@ -253,6 +254,7 @@ $(OUTDIR)test/libtest.so: $(RUSTC_SRC_DL)
 
 RUSTC_ENV_VARS := CFG_COMPILER_HOST_TRIPLE=$(RUSTC_TARGET)
 RUSTC_ENV_VARS += LLVM_CONFIG=$(abspath $(LLVM_CONFIG))
+RUSTC_ENV_VARS += CFG_LLVM_ROOT=@PREFIX@/libexec/llvm-@LLVM_V@
 RUSTC_ENV_VARS += CFG_RELEASE=$(RUSTC_VERSION)	# Claiming stable
 RUSTC_ENV_VARS += CFG_RELEASE_CHANNEL=$(RUSTC_CHANNEL)
 RUSTC_ENV_VARS += CFG_VERSION=$(RUSTC_VERSION)-$(RUSTC_CHANNEL)-mrustc
@@ -262,7 +264,7 @@ RUSTC_ENV_VARS += LD_LIBRARY_PATH=$(abspath $(OUTDIR))
 RUSTC_ENV_VARS += REAL_LIBRARY_PATH_VAR=LD_LIBRARY_PATH
 RUSTC_ENV_VARS += RUSTC_INSTALL_BINDIR=bin
 
-$(OUTDIR)rustc: $(MRUSTC) $(MINICARGO) LIBS $(LLVM_CONFIG)
+$(OUTDIR)rustc: $(MRUSTC) $(MINICARGO) LIBS
 	mkdir -p $(OUTDIR)rustc-build
 	+$(RUSTC_ENV_VARS) $(MINICARGO) $(RUSTCSRC)$(SRCDIR_RUSTC) --vendor-dir $(VENDOR_DIR) --output-dir $(OUTDIR)rustc-build -L $(OUTDIR) $(MINICARGO_FLAGS) $(MINICARGO_FLAGS_$@)
 	test -e $@ -a ! $(OUTDIR)rustc-build/$(RUSTC_OUT_BIN) -nt $@ || cp $(OUTDIR)rustc-build/$(RUSTC_OUT_BIN) $@
diff --git a/run_rustc/Makefile b/run_rustc/Makefile
index a97ce927..1b812596 100644
--- a/run_rustc/Makefile
+++ b/run_rustc/Makefile
@@ -90,11 +90,12 @@ BINDIR := $(PREFIX)bin/
 LIBDIR := $(PREFIX)lib/rustlib/$(RUSTC_TARGET)/lib/
 CARGO_HOME := $(PREFIX)cargo_home/
 
-LLVM_CONFIG ?= $(RUST_SRC)build/bin/llvm-config
+LLVM_CONFIG := @PREFIX@/libexec/llvm-@LLVM_V@/bin/llvm-config
 LLVM_TARGETS ?= X86;ARM;AArch64#;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX
 
 RUSTC_ENV_VARS := CFG_COMPILER_HOST_TRIPLE=$(RUSTC_TARGET)
 RUSTC_ENV_VARS += LLVM_CONFIG=$(abspath $(LLVM_CONFIG))
+RUSTC_ENV_VARS += CFG_LLVM_ROOT=@PREFIX@/libexec/llvm-@LLVM_V@
 RUSTC_ENV_VARS += CFG_RELEASE=$(RUSTC_VERSION)	# Claiming stable
 RUSTC_ENV_VARS += CFG_RELEASE_CHANNEL=$(RUSTC_CHANNEL)
 RUSTC_ENV_VARS += CFG_VERSION=$(RUSTC_VERSION)-stable-mrustc
