Skip to content

Commit 537fb47

Browse files
committed
Clean rust target when rustc bumped up
Fix: ``` error[E0514]: found crate `jit` compiled by an incompatible version of rustc ```
1 parent 9d374b9 commit 537fb47

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

defs/jit.mk

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RUST_LIB_TOUCH = touch $@
2222
# ld: warning: object file (target/debug/libjit.a(<libcapstone object>)) was built for
2323
# newer macOS version (15.2) than being linked (15.0)
2424
# This limits us to an older set of macOS API in the rust code, but we don't use any.
25-
$(RUST_LIB): $(srcdir)/ruby.rs
25+
$(RUST_LIB): $(srcdir)/ruby.rs target/.rustc-version
2626
$(Q)if [ '$(ZJIT_SUPPORT)' != no -a '$(YJIT_SUPPORT)' != no ]; then \
2727
echo 'building YJIT and ZJIT ($(JIT_CARGO_SUPPORT:yes=release) mode)'; \
2828
elif [ '$(ZJIT_SUPPORT)' != no ]; then \
@@ -37,7 +37,7 @@ $(RUST_LIB): $(srcdir)/ruby.rs
3737
$(RUST_LIB_TOUCH)
3838
else ifneq ($(strip $(RLIB_DIR)),) # combo build
3939

40-
$(RUST_LIB): $(srcdir)/ruby.rs
40+
$(RUST_LIB): $(srcdir)/ruby.rs target/.rustc-version
4141
$(ECHO) 'building $(@F)'
4242
$(gnumake_recursive)$(Q) $(RUSTC) --edition=2024 \
4343
$(RUSTC_FLAGS) \
@@ -54,7 +54,7 @@ $(RUST_LIB): $(srcdir)/ruby.rs
5454
JIT_RLIB = $(TOP_BUILD_DIR)/$(RLIB_DIR)/libjit.rlib
5555
$(YJIT_RLIB): $(JIT_RLIB)
5656
$(ZJIT_RLIB): $(JIT_RLIB)
57-
$(JIT_RLIB):
57+
$(JIT_RLIB): target/.rustc-version
5858
$(ECHO) 'building $(@F)'
5959
$(gnumake_recursive)$(Q) $(RUSTC) --crate-name=jit \
6060
--edition=2024 \
@@ -77,6 +77,17 @@ endif
7777
rust-libobj: $(RUST_LIBOBJ)
7878
rust-lib: $(RUST_LIB)
7979

80+
rustc-version-check: target/.rustc-version
81+
82+
target/.rustc-version: PHONY
83+
$(eval prev_version := $(if $(wildcard $@),$(shell cat $@)))
84+
$(eval curr_version := $(shell $(RUSTC) -V | cut -d' ' -f2))
85+
$(eval clean := $(filter-out $(prev_version),$(curr_version)))
86+
$(if $(clean),$(ECHO) Cleaning $(@D) for rustc $(curr_version))
87+
$(if $(clean),$(Q)$(RMALL) $(@D))
88+
$(Q)$(MAKEDIRS) $(@D)
89+
$(Q)echo $(curr_version) > $@
90+
8091
# For Darwin only: a list of symbols that we want the glommed Rust static lib to export.
8192
# Unfortunately, using wildcard like '_rb_*' with -exported-symbol does not work, at least
8293
# not on version 820.1. Assume llvm-nm, so XCode 8.0 (from 2016) or newer.

yjit/yjit.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ BUILD_YJIT_LIBS = $(TOP_BUILD_DIR)/$(YJIT_LIBS)
1616
# In a YJIT-only build (no ZJIT)
1717
ifneq ($(strip $(YJIT_LIBS)),)
1818
yjit-libs: $(BUILD_YJIT_LIBS)
19-
$(BUILD_YJIT_LIBS): $(YJIT_SRC_FILES)
19+
$(BUILD_YJIT_LIBS): $(YJIT_SRC_FILES) rustc-version-check
2020
$(ECHO) 'building Rust YJIT (release mode)'
2121
$(gnumake_recursive)$(Q) $(RUSTC) $(YJIT_RUSTC_ARGS)
2222
else ifneq ($(strip $(RLIB_DIR)),) # combo build
2323
# Absolute path to avoid VPATH ambiguity
2424
YJIT_RLIB = $(TOP_BUILD_DIR)/$(RLIB_DIR)/libyjit.rlib
2525

26-
$(YJIT_RLIB): $(YJIT_SRC_FILES)
26+
$(YJIT_RLIB): $(YJIT_SRC_FILES) rustc-version-check
2727
$(ECHO) 'building $(@F)'
2828
$(gnumake_recursive)$(Q) $(RUSTC) '-L$(@D)' --extern=jit $(YJIT_RUSTC_ARGS)
2929

zjit/zjit.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ BUILD_ZJIT_LIBS = $(TOP_BUILD_DIR)/$(ZJIT_LIBS)
2020

2121
# In a ZJIT-only build (no YJIT)
2222
ifneq ($(strip $(ZJIT_LIBS)),)
23-
$(BUILD_ZJIT_LIBS): $(ZJIT_SRC_FILES)
23+
$(BUILD_ZJIT_LIBS): $(ZJIT_SRC_FILES) rustc-version-check
2424
$(ECHO) 'building Rust ZJIT (release mode)'
2525
$(gnumake_recursive)$(Q) $(RUSTC) $(ZJIT_RUSTC_ARGS)
2626
else ifneq ($(strip $(RLIB_DIR)),) # combo build
2727
# Absolute path to avoid VPATH ambiguity
2828
ZJIT_RLIB = $(TOP_BUILD_DIR)/$(RLIB_DIR)/libzjit.rlib
2929

30-
$(ZJIT_RLIB): $(ZJIT_SRC_FILES)
30+
$(ZJIT_RLIB): $(ZJIT_SRC_FILES) rustc-version-check
3131
$(ECHO) 'building $(@F)'
3232
$(gnumake_recursive)$(Q) $(RUSTC) '-L$(@D)' --extern=jit $(ZJIT_RUSTC_ARGS)
3333

0 commit comments

Comments
 (0)