From fd627b134c686e7c9afb646dc37c573c5d36fd4a Mon Sep 17 00:00:00 2001 From: bitflash-maintainer Date: Wed, 2 Sep 2026 05:22:36 +0000 Subject: build: stop rm -rf'ing a RandomX tree the build did not create deps-randomx built into $(HOME)/RandomX and deleted that path whenever the library was missing, taking out hand-managed checkouts the build never owned. Default the build to the in-tree $(ROOT)/randomx-build, like secp256k1-build, overridable via RANDOMX_DIR and exported so src/Makefile's own fallback resolves to the same tree. As a backstop, the recipe writes a .bitflash-built marker after a successful build and refuses to delete any directory that lacks it, so a user-supplied RANDOMX_DIR pointing at a pre-existing tree is never removed. Closes #27 --- Makefile | 31 ++++++++++++++++++++++++------- src/Makefile | 4 +++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 9f97b73..83a2c73 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,17 @@ APPIMAGETOOL_SHA256 := ed4ce84f0d9caff66f50bcca6ff6f35aae54ce8135408b3fa33abfc3c # ---- Linux ---------------------------------------------------------------- +# RandomX used to build in $(HOME)/RandomX, and deps-randomx would rm -rf that +# path whenever the library was missing -- deleting a tree the build did not +# create and does not own (issue #27; a hand-managed pinned checkout there is +# what this machine's miners build against). The default is now in-tree, like +# secp256k1-build. A host that deliberately keeps RandomX elsewhere can set +# RANDOMX_DIR=... explicitly; the recipe below will still never delete a +# directory that lacks the marker file this build writes after a successful +# build. Exported so src/Makefile's own RANDOMX_DIR ?= picks the same tree. +RANDOMX_DIR ?= $(ROOT)/randomx-build +export RANDOMX_DIR + linux: deps-linux $(MAKE) -C src -f Makefile -j$(NPROC) strip src/bitflash @@ -109,19 +120,25 @@ deps-secp256k1: fi deps-randomx: - @if [ ! -f $(HOME)/RandomX/build/librandomx.a ]; then \ + @if [ ! -f $(RANDOMX_DIR)/build/librandomx.a ]; then \ + if [ -d $(RANDOMX_DIR) ] && [ ! -f $(RANDOMX_DIR)/.bitflash-built ]; then \ + echo "ERROR: $(RANDOMX_DIR) exists but was not created by this build"; \ + echo " refusing to rm -rf it -- remove it yourself or set RANDOMX_DIR"; \ + exit 1; \ + fi; \ echo "==> building RandomX"; \ - rm -rf $(HOME)/RandomX; \ - git init -q $(HOME)/RandomX; \ - cd $(HOME)/RandomX && \ + rm -rf $(RANDOMX_DIR); \ + git init -q $(RANDOMX_DIR); \ + cd $(RANDOMX_DIR) && \ git remote add origin $(RANDOMX_REPO) && \ git fetch -q --depth 1 origin $(RANDOMX_COMMIT) && \ git checkout -q --detach FETCH_HEAD && \ test "$$(git rev-parse HEAD)" = "$(RANDOMX_COMMIT)" && \ echo "==> RandomX pinned at $(RANDOMX_COMMIT)" && \ - mkdir -p $(HOME)/RandomX/build; \ - cd $(HOME)/RandomX/build && cmake .. -DCMAKE_BUILD_TYPE=Release && \ - make -j$(NPROC) randomx; \ + mkdir -p $(RANDOMX_DIR)/build && \ + cd $(RANDOMX_DIR)/build && cmake .. -DCMAKE_BUILD_TYPE=Release && \ + make -j$(NPROC) randomx && \ + touch $(RANDOMX_DIR)/.bitflash-built && \ echo "==> RandomX done"; \ else \ echo "==> RandomX already built"; \ diff --git a/src/Makefile b/src/Makefile index 1bc3ae8..2c6d304 100644 --- a/src/Makefile +++ b/src/Makefile @@ -6,7 +6,9 @@ FUZZ_CXX ?= clang++ SECP_INC ?= /usr/local/include SECP_LIB ?= /usr/local/lib -RANDOMX_DIR ?= $(HOME)/RandomX +# The root Makefile exports RANDOMX_DIR (default: /randomx-build, built +# by deps-randomx). This fallback only applies when src/ is built standalone. +RANDOMX_DIR ?= $(abspath $(CURDIR)/..)/randomx-build IMGUI_DIR = imgui -- cgit v1.2.3