nim_needs_rebuilding.sh and build_nim.sh

This commit is contained in:
Ștefan Talpalaru 2019-06-11 23:29:51 +02:00 committed by zah
parent 4412338b98
commit 688fbd2145
3 changed files with 113 additions and 37 deletions

View File

@ -34,44 +34,14 @@ NIM_DIR := vendor/Nim
# but this is broken when using symlinks, so build csources separately (we get parallel compiling as a bonus)
#- Windows is a special case, as usual
#- macOS is also a special case, with its "ln" not supporting "-r"
#- the AppVeyor 32-build is done on a 64-bit image, so we need to override the architecture detection with ARCH_OVERRIDE
BUILD_NIM := echo -e $(BUILD_MSG) "Nim compiler" && \
V=$(V) CC=$(CC) MAKE=$(MAKE) ARCH_OVERRIDE=$(ARCH_OVERRIDE) "$(CURDIR)/build_nim.sh" "$(NIM_DIR)" ../Nim-csources ../nimble
ifeq ($(OS), Windows_NT)
# the AppVeyor 32-build is done on a 64-bit image, so we need to override the architecture detection
ifeq ($(ARCH_OVERRIDE), x86)
UCPU := ucpu=i686
else
UCPU :=
endif
BUILD_CSOURCES := \
$(MAKE) myos=windows $(UCPU) clean $(HANDLE_OUTPUT) && \
$(MAKE) myos=windows $(UCPU) CC=gcc LD=gcc $(HANDLE_OUTPUT)
EXE_SUFFIX := .exe
else
BUILD_CSOURCES := \
$(MAKE) clean $(HANDLE_OUTPUT) && \
$(MAKE) LD=$(CC) $(HANDLE_OUTPUT)
EXE_SUFFIX :=
endif
BUILD_NIM := echo -e $(BUILD_MSG) "Nim compiler" && \
cd $(NIM_DIR) && \
rm -rf bin/nim_csources csources dist/nimble && \
ln -s ../Nim-csources csources && \
mkdir -p dist && \
ln -s ../../nimble dist/nimble && \
cd csources && \
$(BUILD_CSOURCES) && \
cd - >/dev/null && \
[ -e csources/bin ] && { \
cp -a csources/bin/nim bin/nim && \
cp -a csources/bin/nim bin/nim_csources && \
rm -rf csources/bin; \
} || { \
cp -a bin/nim bin/nim_csources; \
} && { \
sed 's/koch tools/koch --stable tools/' build_all.sh > build_all_custom.sh; \
sh build_all_custom.sh $(HANDLE_OUTPUT); \
rm build_all_custom.sh; \
} && cd ../..
NIM_BINARY := $(NIM_DIR)/bin/nim$(EXE_SUFFIX)
# md5sum - macOS is a special case
ifeq ($(shell uname), Darwin)
@ -197,10 +167,20 @@ build-nim: | deps
#- rebuilds the Nim compiler after the corresponding submodule is updated (keep in mind that Git doesn't preserve file timestamps)
$(NIM_BINARY) update: | sanity-checks
git submodule update --init --recursive
[[ -n "$(CI_CACHE)" && -d "$(CI_CACHE)" ]] && cp -a "$(CI_CACHE)"/* $(NIM_DIR)/bin/ || true
rm -rf $(NIMBLE_DIR) nimbus.nims && $(MAKE) nimbus.nims
+ [[ -e $(NIM_BINARY) && $$(stat -c%Z $(NIM_BINARY)) -gt $$(git log --pretty=format:%cd -n 1 --date=unix -- vendor/Nim) ]] || \
{ $(BUILD_NIM); [[ -n "$(CI_CACHE)" ]] && rm -rf "$(CI_CACHE)" && mkdir $(CI_CACHE) && cp -a $(NIM_DIR)/bin/* "$(CI_CACHE)"/ || true; }
[[ -n "$(CI_CACHE)" && -d "$(CI_CACHE)" ]] && \
cp -a "$(CI_CACHE)"/* $(NIM_DIR)/bin/ || \
true
rm -rf $(NIMBLE_DIR) nimbus.nims && \
$(MAKE) nimbus.nims
+ "$(CURDIR)/nim_needs_rebuilding.sh" "$(NIM_DIR)" $(NIM_BINARY) && \
{ \
$(BUILD_NIM); \
[[ -n "$(CI_CACHE)" ]] && \
rm -rf "$(CI_CACHE)" && \
mkdir $(CI_CACHE) && \
cp -a $(NIM_DIR)/bin/* "$(CI_CACHE)"/ || \
true; \
} || true
# don't use this target, or you risk updating dependency repos that are not ready to be used in Nimbus
update-remote:

83
build_nim.sh Executable file
View File

@ -0,0 +1,83 @@
#!/bin/bash
set -e
# Git commits
CSOURCES_COMMIT="b56e49bbedf62db22eb26388f98262e2948b2cbc" # 0.19.0
NIMBLE_COMMIT="c8d79fc0228682677330a9f57d14389aaa641153" # Mar 26 10:06:06 2019
# script arguments
[[ $# -ne 3 ]] && { echo "usage: $0 nim_dir csources_dir nimble_dir"; exit 1; }
NIM_DIR="$1"
CSOURCES_DIR="$2"
NIMBLE_DIR="$3"
## env vars
# verbosity level
[[ -z "$V" ]] && V=0
[[ "$V" == "0" ]] && exec &>/dev/null
[[ -z "$CC" ]] && CC="gcc"
# to build csources in parallel, set MAKE="make -jN"
[[ -z "$MAKE" ]] && MAKE="make"
# for 32-bit binaries on a 64-bit Windows host
UCPU=""
[[ "$ARCH_OVERRIDE" == "x86" ]] && UCPU="ucpu=i686"
# Windows detection
ON_WINDOWS=0
uname | grep -qi mingw && ON_WINDOWS=1
# working directory
cd "$NIM_DIR"
# Git repos for csources and Nimble
[[ -d "$CSOURCES_DIR" ]] || { \
mkdir -p "$CSOURCES_DIR" && \
cd "$CSOURCES_DIR" && \
git clone https://github.com/nim-lang/csources.git . && \
git checkout $CSOURCES_COMMIT && \
cd - >/dev/null; \
}
[[ "$CSOURCES_DIR" != "csources" ]] && \
rm -rf csources && \
ln -s "$CSOURCES_DIR" csources
# we have to delete .git or koch.nim will checkout a branch tip
[[ -d "$NIMBLE_DIR" ]] || { \
mkdir -p "$NIMBLE_DIR" && \
cd "$NIMBLE_DIR" && \
git clone https://github.com/nim-lang/nimble.git . && \
git checkout $NIMBLE_COMMIT && \
rm -rf .git && \
cd - >/dev/null; \
}
[[ "$NIMBLE_DIR" != "dist/nimble" ]] && \
mkdir -p dist && \
rm -rf dist/nimble && \
ln -s ../"$NIMBLE_DIR" dist/nimble
# bootstrap the Nim compiler and build the tools
rm -rf bin/nim_csources && \
cd csources && { \
[[ "$ON_WINDOWS" == "0" ]] && { \
$MAKE clean && \
$MAKE LD=$CC; \
} || { \
$MAKE myos=windows $UCPU clean && \
$MAKE myos=windows $UCPU CC=gcc LD=gcc; \
}; \
} && \
cd - >/dev/null && { \
[ -e csources/bin ] && { \
cp -a csources/bin/nim bin/nim && \
cp -a csources/bin/nim bin/nim_csources && \
rm -rf csources/bin; \
} || { \
cp -a bin/nim bin/nim_csources; \
}; \
} && { \
sed 's/koch tools/koch --stable tools/' build_all.sh > build_all_custom.sh; \
sh build_all_custom.sh; \
rm build_all_custom.sh; \
}

13
nim_needs_rebuilding.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# this one is required
set -e
# script arguments
[[ $# -ne 2 ]] && { echo "usage: $0 nim_dir nim_binary"; exit 1; }
NIM_DIR="$1"
NIM_BINARY="$2"
# compare binary mtime to the date of the last commit
! [[ -e $NIM_BINARY && $(stat -c%Y $NIM_BINARY) -gt $(cd "$NIM_DIR"; git log --pretty=format:%cd -n 1 --date=unix) ]]