diff options
Diffstat (limited to 'zjit')
-rw-r--r-- | zjit/Cargo.toml | 17 | ||||
-rw-r--r-- | zjit/bindgen/Cargo.toml | 2 | ||||
-rw-r--r-- | zjit/build.rs | 3 | ||||
-rw-r--r-- | zjit/zjit.mk | 58 |
4 files changed, 14 insertions, 66 deletions
diff --git a/zjit/Cargo.toml b/zjit/Cargo.toml index ed8e66be02..a86117d6e2 100644 --- a/zjit/Cargo.toml +++ b/zjit/Cargo.toml @@ -1,25 +1,10 @@ [package] name = "zjit" version = "0.0.1" -edition = "2024" # Rust 2021 edition to compile with +edition = "2024" rust-version = "1.85.0" # Minimally supported rust version publish = false # Don't publish to crates.io -[lib] -crate-type = ["staticlib"] - -[profile.release] -# NOTE: --enable-zjit builds use `rustc` without going through Cargo. You -# might want to update the `rustc` invocation if you change this profile. -opt-level = 3 -# The extra robustness that comes from checking for arithmetic overflow is -# worth the performance cost for the compiler. -overflow-checks = true -# Generate debug info -debug = true -# Use ThinLTO. Much smaller output for a small amount of build time increase. -lto = "thin" - [dependencies] # No required dependencies to simplify build process. TODO: Link to yet to be # written rationale. Optional For development and testing purposes diff --git a/zjit/bindgen/Cargo.toml b/zjit/bindgen/Cargo.toml index 2824f31213..2f20f18016 100644 --- a/zjit/bindgen/Cargo.toml +++ b/zjit/bindgen/Cargo.toml @@ -8,3 +8,5 @@ edition = "2024" [dependencies] bindgen = "0.71.1" env_logger = "0.11.5" + +[workspace] diff --git a/zjit/build.rs b/zjit/build.rs index cf402fbc1d..fc6ad1decf 100644 --- a/zjit/build.rs +++ b/zjit/build.rs @@ -1,7 +1,8 @@ fn main() { use std::env; - if let Ok(ruby_build_dir) = env::var("RUBY_BUILD_DIR") { + // option_env! automatically registers a rerun-if-env-changed + if let Some(ruby_build_dir) = option_env!("RUBY_BUILD_DIR") { // Link against libminiruby println!("cargo:rustc-link-search=native={ruby_build_dir}"); println!("cargo:rustc-link-lib=static:-bundle=miniruby"); diff --git a/zjit/zjit.mk b/zjit/zjit.mk index 91cf861a39..9107c15809 100644 --- a/zjit/zjit.mk +++ b/zjit/zjit.mk @@ -19,60 +19,20 @@ ZJIT_SRC_FILES = $(wildcard \ # rebuild at the next build. ZJIT_LIB_TOUCH = touch $@ +# Absolute path to match RUST_LIB rules to avoid picking +# the "target" dir in the source directory through VPATH. +BUILD_ZJIT_LIBS = $(TOP_BUILD_DIR)/$(ZJIT_LIBS) + # ZJIT_SUPPORT=yes when `configure` gets `--enable-zjit` ifeq ($(ZJIT_SUPPORT),yes) -$(ZJIT_LIBS): $(ZJIT_SRC_FILES) +$(BUILD_ZJIT_LIBS): $(ZJIT_SRC_FILES) $(ECHO) 'building Rust ZJIT (release mode)' +$(Q) $(RUSTC) $(ZJIT_RUSTC_ARGS) $(ZJIT_LIB_TOUCH) -else ifeq ($(ZJIT_SUPPORT),no) -$(ZJIT_LIBS): - $(ECHO) 'Error: Tried to build ZJIT without configuring it first. Check `make showconfig`?' - @false -else ifeq ($(ZJIT_SUPPORT),$(filter dev dev_nodebug stats,$(ZJIT_SUPPORT))) -# NOTE: MACOSX_DEPLOYMENT_TARGET to match `rustc --print deployment-target` to avoid the warning below. -# ld: warning: object file (zjit/target/debug/libzjit.a(<libcapstone object>)) was built for -# newer macOS version (15.2) than being linked (15.0) -# We don't use newer macOS feature as of yet. -$(ZJIT_LIBS): $(ZJIT_SRC_FILES) - $(ECHO) 'building Rust ZJIT ($(ZJIT_SUPPORT) mode)' - +$(Q)$(CHDIR) $(top_srcdir)/zjit && \ - CARGO_TARGET_DIR='$(ZJIT_CARGO_TARGET_DIR)' \ - CARGO_TERM_PROGRESS_WHEN='never' \ - MACOSX_DEPLOYMENT_TARGET=11.0 \ - $(CARGO) $(CARGO_VERBOSE) build $(ZJIT_CARGO_BUILD_ARGS) - $(ZJIT_LIB_TOUCH) -else -endif - -zjit-libobj: $(ZJIT_LIBOBJ) - -ZJIT_LIB_SYMBOLS = $(ZJIT_LIBS:.a=).symbols -$(ZJIT_LIBOBJ): $(ZJIT_LIBS) - $(ECHO) 'partial linking $(ZJIT_LIBS) into $@' -ifneq ($(findstring darwin,$(target_os)),) - $(Q) $(CC) -nodefaultlibs -r -o $@ -exported_symbols_list $(ZJIT_LIB_SYMBOLS) $(ZJIT_LIBS) -else - $(Q) $(LD) -r -o $@ --whole-archive $(ZJIT_LIBS) - -$(Q) $(OBJCOPY) --wildcard --keep-global-symbol='$(SYMBOL_PREFIX)rb_*' $(@) endif -# For Darwin only: a list of symbols that we want the glommed Rust static lib to export. -# Unfortunately, using wildcard like '_rb_*' with -exported-symbol does not work, at least -# not on version 820.1. Assume llvm-nm, so XCode 8.0 (from 2016) or newer. -# -# The -exported_symbols_list pulls out the right archive members. Symbols not listed -# in the list are made private extern, which are in turn made local as we're using `ld -r`. -# Note, section about -keep_private_externs in ld's man page hints at this behavior on which -# we rely. -ifneq ($(findstring darwin,$(target_os)),) -$(ZJIT_LIB_SYMBOLS): $(ZJIT_LIBS) - $(Q) $(tooldir)/darwin-ar $(NM) --defined-only --extern-only $(ZJIT_LIBS) | \ - sed -n -e 's/.* //' -e '/^$(SYMBOL_PREFIX)rb_/p' \ - -e '/^$(SYMBOL_PREFIX)rust_eh_personality/p' \ - > $@ - -$(ZJIT_LIBOBJ): $(ZJIT_LIB_SYMBOLS) +ifneq ($(ZJIT_SUPPORT),no) +$(RUST_LIB): $(ZJIT_SRC_FILES) endif # By using ZJIT_BENCH_OPTS instead of RUN_OPTS, you can skip passing the options to `make install` @@ -113,7 +73,7 @@ zjit-bindgen: zjit.$(OBJEXT) zjit-test: libminiruby.a RUBY_BUILD_DIR='$(TOP_BUILD_DIR)' \ RUBY_LD_FLAGS='$(LDFLAGS) $(XLDFLAGS) $(MAINLIBS)' \ - CARGO_TARGET_DIR='$(ZJIT_CARGO_TARGET_DIR)' \ + CARGO_TARGET_DIR='$(CARGO_TARGET_DIR)' \ $(CARGO) nextest run --manifest-path '$(top_srcdir)/zjit/Cargo.toml' $(ZJIT_TESTS) # Run a ZJIT test written with Rust #[test] under LLDB @@ -126,7 +86,7 @@ zjit-test-lldb: libminiruby.a fi; \ exe_path=`RUBY_BUILD_DIR='$(TOP_BUILD_DIR)' \ RUBY_LD_FLAGS='$(LDFLAGS) $(XLDFLAGS) $(MAINLIBS)' \ - CARGO_TARGET_DIR='$(ZJIT_CARGO_TARGET_DIR)' \ + CARGO_TARGET_DIR='$(CARGO_TARGET_DIR)' \ $(CARGO) nextest list --manifest-path '$(top_srcdir)/zjit/Cargo.toml' --message-format json --list-type=binaries-only | \ $(BASERUBY) -rjson -e 'puts JSON.load(STDIN.read).dig("rust-binaries", "zjit", "binary-path")'`; \ exec lldb $$exe_path -- --test-threads=1 $(ZJIT_TESTS) |