Bootstrap nimble (#3)
* Bootstrap nimble Here it is the script that I am using to generate the nimble sources. ``` rm ~/.cache/nim/nimble_d/ -rf nim cc --genScript src/nimble.nim sed -i 's#-I.*nimble/src##' ~/.cache/nim/nimble_d/compile_nimble.sh cp ~/Sources/nim/Nim/lib/nimbase.h ~/.cache/nim/nimble_d/ mkdir ~/.cache/nim/nim-workspace/ -p rm -rf ~/Sources/nim/nim-workspace/scripts/nimble-linux/ cp -r ~/.cache/nim/nimble_d/ ~/Sources/nim/nim-workspace/scripts/nimble-linux/ rm ~/.cache/nim/nimble_d/ -rf nim cc --os:windows --genScript src/nimble.nim sed -i 's#-I.*nimble/src##' ~/.cache/nim/nimble_d/compile_nimble.bat cp ~/Sources/nim/Nim/lib/nimbase.h ~/.cache/nim/nimble_d/ mkdir ~/.cache/nim/nim-workspace/ -p rm -rf ~/Sources/nim/nim-workspace/scripts/nimble-windows/ cp -r ~/.cache/nim/nimble_d/ ~/Sources/nim/nim-workspace/scripts/nimble-windows/ ``` * Update scripts/rebuild-nimble * Use the revision of nimble sources * Choosenim to bootstrap nim for nimble usage Co-authored-by: zah <zahary@gmail.com>
This commit is contained in:
parent
fb3bb28208
commit
b390f25205
16
.envrc
16
.envrc
|
@ -1,18 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
export IN_STATUS_NIM_WORKSPACE=1
|
||||
|
||||
export NIM_REPO="https://github.com/status-im/Nim"
|
||||
export NIMBLE_REPO="https://github.com/nim-lang/nimble"
|
||||
|
||||
if [[ -z "${NIM_COMMIT}" ]]; then
|
||||
export NIM_COMMIT="d38177b11f628d9675809bfa85356c3ee3a26fea" # latest v1.6.x (2021-04-14)
|
||||
fi
|
||||
|
||||
if [[ -z "${NIMBLE_COMMIT}" ]]; then
|
||||
export NIMBLE_COMMIT="d68b2cb6efe8ce298cb5021fe84d3814d755322f" # latest (2021-04-14)
|
||||
fi
|
||||
|
||||
source ./scripts/rebuild-nim
|
||||
source ./scripts/rebuild-nimble
|
||||
|
||||
export PATH="$(pwd)/${NIM_DIR}/bin:$(pwd)/scripts:${PATH}"
|
||||
export PATH="$(pwd)/bin:~/.cache/nim-workspace/bin/:$(pwd)/${NIM_DIR}/bin:$(pwd)/scripts:${PATH}"
|
||||
|
|
|
@ -8,3 +8,5 @@ nimble.develop
|
|||
!scripts/
|
||||
!scripts/*
|
||||
|
||||
nimble
|
||||
*.c.o
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "scripts/csources-nimble"]
|
||||
path = scripts/csources-nimble
|
||||
url = https://github.com/status-im/csources-nimble
|
|
@ -0,0 +1 @@
|
|||
Subproject commit a9f2ad7c62c7dc5ce71e92d9e284edf7d112fcc2
|
|
@ -1,176 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
# used in Travis CI and AppVeyor scripts
|
||||
|
||||
# Copyright (c) 2018-2020 Status Research & Development GmbH. Licensed under
|
||||
# either of:
|
||||
# - Apache License, version 2.0
|
||||
# - MIT license
|
||||
# at your option. This file may not be copied, modified, or distributed except
|
||||
# according to those terms.
|
||||
|
||||
set -e
|
||||
|
||||
NIM_COMMIT_HASH="" # full hash for NIM_COMMIT, retrieved in "nim_needs_rebuilding()"
|
||||
|
||||
NIM_DIR=nim
|
||||
CSOURCES_DIR=nim-csources
|
||||
NIMBLE_DIR=nimble
|
||||
|
||||
cd "$(dirname "${BASH_SOURCE}")"
|
||||
cd ..
|
||||
|
||||
## env vars
|
||||
# verbosity level
|
||||
[ -z "${V}" ] && V=0
|
||||
[ -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 host
|
||||
UCPU=""
|
||||
[ "${ARCH_OVERRIDE}" = "x86" ] && UCPU="ucpu=i686"
|
||||
[ -z "${NIM_BUILD_MSG}" ] && NIM_BUILD_MSG="Building the Nim compiler (${NIM_COMMIT})"
|
||||
[ -z "${CSOURCES_COMMIT}" ] && CSOURCES_COMMIT=a8a5241f9475099c823cfe1a5e0ca4022ac201ff
|
||||
[ -z "${NIM_REPO}" ] && NIM_REPO="https://github.com/status-im/Nim.git"
|
||||
[ -z "${NIMBLE_REPO}" ] && NIMBLE_REPO="https://github.com/nim-lang/nimble.git"
|
||||
[ -z "${NIM_COMMIT}" ] && { echo "Please specify NIM_COMMIT"; exit 1; }
|
||||
[ -z "${NIMBLE_COMMIT}" ] && { echo "Please specify NIMBLE_COMMIT"; exit 1; }
|
||||
|
||||
# Windows detection
|
||||
if uname | grep -qiE "mingw|msys"; then
|
||||
ON_WINDOWS=1
|
||||
EXE_SUFFIX=".exe"
|
||||
# otherwise it fails in AppVeyor due to https://github.com/git-for-windows/git/issues/2495
|
||||
GIT_TIMESTAMP_ARG="--date=unix" # available since Git 2.9.4
|
||||
else
|
||||
ON_WINDOWS=0
|
||||
EXE_SUFFIX=""
|
||||
GIT_TIMESTAMP_ARG="--date=format-local:%s" # available since Git 2.7.0
|
||||
fi
|
||||
|
||||
NIM_BINARY="${NIM_DIR}/bin/nim${EXE_SUFFIX}"
|
||||
|
||||
nim_needs_rebuilding() {
|
||||
REBUILD=0
|
||||
NO_REBUILD=1
|
||||
|
||||
if [ ! -e "${NIM_DIR}" ]; then
|
||||
# Shallow clone, optimised for the default NIM_COMMIT value.
|
||||
git clone -q --depth=1 "${NIM_REPO}" "${NIM_DIR}"
|
||||
fi
|
||||
|
||||
pushd "${NIM_DIR}" >/dev/null
|
||||
# support old Git versions, like the one from Ubuntu-18.04
|
||||
git restore . 2>/dev/null || git reset --hard
|
||||
if ! git checkout -q "${NIM_COMMIT}" 2>/dev/null; then
|
||||
# Pay the price for a non-default NIM_COMMIT here, by fetching everything.
|
||||
# (This includes upstream branches and tags that might be missing from our fork.)
|
||||
git remote add upstream https://github.com/nim-lang/Nim
|
||||
git fetch --all
|
||||
git checkout -q "${NIM_COMMIT}" 2>/dev/null
|
||||
fi
|
||||
|
||||
# In case the local branch diverged and a fast-forward merge is not possible.
|
||||
git fetch || true
|
||||
git reset -q --hard origin/${NIM_COMMIT} 2> /dev/null || true
|
||||
# In case NIM_COMMIT is a local branch that's behind the remote one it's tracking.
|
||||
git pull -q 2>/dev/null || true
|
||||
git checkout -q ${NIM_COMMIT} 2>/dev/null
|
||||
# We can't use "rev-parse" here, because it would return the tag object's
|
||||
# hash instead of the commit hash, when NIM_COMMIT is a tag.
|
||||
NIM_COMMIT_HASH="$(git rev-list -n 1 ${NIM_COMMIT})"
|
||||
popd >/dev/null
|
||||
|
||||
# compare the last built commit to the one requested
|
||||
if [ -e "${NIM_DIR}/bin/nim_commit_${NIM_COMMIT_HASH}" ]; then
|
||||
# we built the requested commit in the past, so we simply reuse it
|
||||
rm -f "${NIM_DIR}/bin/nim${EXE_SUFFIX}"
|
||||
ln -s "nim_commit_${NIM_COMMIT_HASH}" "${NIM_DIR}/bin/nim${EXE_SUFFIX}"
|
||||
return ${NO_REBUILD}
|
||||
# Bootstap nim to make nimble work
|
||||
if [ ! -f ~/.cache/nim-workspace/bin/nim$EXE_SUFFIX ]; then
|
||||
if uname | grep -qiE "mingw|msys"; then
|
||||
curl https://github.com/dom96/choosenim/releases/download/v0.8.4/choosenim-0.8.4_windows_amd64.exe \
|
||||
--output /tmp/choosenim.exe
|
||||
/tmp/choosenim.exe stable --nimbleDir:~/.cache/nim-workspace
|
||||
else
|
||||
return ${REBUILD}
|
||||
curl https://raw.githubusercontent.com/yyoncho/choosenim/nimble-dir/scripts/choosenim-unix-init.sh -sSf | NIMBLE_BIN=~/.cache/nim-workspace sh -x
|
||||
fi
|
||||
}
|
||||
|
||||
build_nim() {
|
||||
echo "$NIM_BUILD_MSG"
|
||||
[ $V -eq 0 ] && exec >/dev/null 2>&1
|
||||
|
||||
pushd "${NIM_DIR}"
|
||||
# Git repos for csources and Nimble
|
||||
if [ ! -d "${CSOURCES_DIR}" ]; then
|
||||
mkdir -p "${CSOURCES_DIR}"
|
||||
pushd "${CSOURCES_DIR}"
|
||||
git clone https://github.com/nim-lang/csources_v1.git .
|
||||
git checkout $CSOURCES_COMMIT
|
||||
popd
|
||||
fi
|
||||
if [ ! "${CSOURCES_DIR}" = "csources" ]; then
|
||||
rm -rf csources
|
||||
ln -s "${CSOURCES_DIR}" csources
|
||||
fi
|
||||
if [ ! -d "${NIMBLE_DIR}" ]; then
|
||||
mkdir -p "${NIMBLE_DIR}"
|
||||
pushd "${NIMBLE_DIR}"
|
||||
git clone "${NIMBLE_REPO}" .
|
||||
git checkout "${NIMBLE_COMMIT}"
|
||||
# we have to delete .git or koch.nim will checkout a branch tip, overriding our target commit
|
||||
# TODO
|
||||
# This is quite the hack and it breaks the output of `nimble --version`
|
||||
# which prints the Nim revision instead of the Nimble revision.
|
||||
rm -rf .git
|
||||
popd
|
||||
fi
|
||||
|
||||
mkdir -p dist
|
||||
rm -rf dist/nimble
|
||||
ln -s ../"${NIMBLE_DIR}" dist/nimble
|
||||
|
||||
# Clean up the new Nimble cache, because the csources build
|
||||
# won't recognize the validity of the packages there:
|
||||
rm -rf ~/.nimble/pkgs2
|
||||
|
||||
# bootstrap the Nim compiler and build the tools
|
||||
rm -f bin/nim bin/nim_csources
|
||||
pushd csources
|
||||
if [ ${ON_WINDOWS} -eq 0 ]; then
|
||||
"${MAKE}" ${UCPU} clean
|
||||
"${MAKE}" ${UCPU} LD=${CC}
|
||||
else
|
||||
"${MAKE}" myos=windows ${UCPU} clean
|
||||
"${MAKE}" myos=windows ${UCPU} CC=gcc LD=gcc
|
||||
fi
|
||||
popd
|
||||
|
||||
if [ -e csources/bin ]; then
|
||||
rm -f bin/nim bin/nim_csources
|
||||
cp -a csources/bin/nim bin/nim
|
||||
cp -a csources/bin/nim bin/nim_csources
|
||||
rm -rf csources/bin
|
||||
else
|
||||
cp -a bin/nim bin/nim_csources
|
||||
fi
|
||||
|
||||
sed \
|
||||
-e 's/koch$/--warnings:off --hints:off koch/' \
|
||||
-e 's/koch boot/koch boot --warnings:off --hints:off/' \
|
||||
-e '/nimBuildCsourcesIfNeeded/d' \
|
||||
build_all.sh > build_all_custom.sh
|
||||
sh build_all_custom.sh
|
||||
rm -f build_all_custom.sh
|
||||
# Nimble needs a CA cert
|
||||
rm -f bin/cacertmony.pem
|
||||
curl -LsS -o bin/cacert.pem https://curl.se/ca/cacert.pem || echo "Warning: 'curl' failed to download a CA cert needed by Nimble. Ignoring it."
|
||||
|
||||
# create the symlink
|
||||
mv bin/nim "bin/nim_commit_${NIM_COMMIT_HASH}"
|
||||
ln -s "nim_commit_${NIM_COMMIT_HASH}" "bin/nim${EXE_SUFFIX}"
|
||||
popd
|
||||
|
||||
[ $V -eq 0 ] && exec >$(tty) 2>&1
|
||||
}
|
||||
|
||||
if nim_needs_rebuilding; then
|
||||
build_nim
|
||||
fi
|
||||
|
||||
set +e
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env bash
|
||||
# Used to rebuild nimble if not already build
|
||||
|
||||
|
||||
# Windows detection
|
||||
if uname | grep -qiE "mingw|msys"; then
|
||||
EXE_SUFFIX=".exe"
|
||||
NIMBLE_SOURCES=./scripts/csources-nimble/nimble-windows/
|
||||
BUILD_COMMAND="./compile_nimble.bat"
|
||||
else
|
||||
EXE_SUFFIX=""
|
||||
NIMBLE_SOURCES=./scripts/csources-nimble/nimble-linux/
|
||||
BUILD_COMMAND="sh compile_nimble.sh"
|
||||
fi
|
||||
|
||||
pushd $NIMBLE_SOURCES
|
||||
NIMBLE_COMMIT=$(git rev-parse HEAD)
|
||||
popd
|
||||
|
||||
NIMBLE_CACHE_DIR=~/.cache/nim/nim-workspace/
|
||||
NIMBLE=$NIMBLE_CACHE_DIR/nimble_$NIMBLE_COMMIT$EXE_SUFFIX
|
||||
|
||||
if [ ! -f $NIMBLE ]; then
|
||||
git submodule update --init
|
||||
mkdir -p $NIMBLE_CACHE_DIR
|
||||
pushd $NIMBLE_SOURCES
|
||||
$BUILD_COMMAND
|
||||
popd
|
||||
cp $NIMBLE_SOURCES/nimble $NIMBLE
|
||||
fi
|
||||
|
||||
mkdir -p bin
|
||||
rm ./bin/nimble$EXE_SUFFIX 2> /dev/null || true
|
||||
ln -s $NIMBLE ./bin/nimble$EXE_SUFFIX
|
Loading…
Reference in New Issue