Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Update libunwind and move CI to GitHub Actions #21

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
name: CI
on:
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
build:
strategy:
fail-fast: false
matrix:
target:
- os: linux
cpu: amd64
- os: linux
cpu: i386
- os: macos
cpu: amd64
- os: windows
cpu: amd64
branch: [version-1-2, version-1-4, version-1-6, devel]
include:
- target:
os: linux
builder: ubuntu-20.04
shell: bash
- target:
os: macos
builder: macos-11
shell: bash
- target:
os: windows
builder: windows-2019
shell: msys2 {0}

defaults:
run:
shell: ${{ matrix.shell }}

name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})'
runs-on: ${{ matrix.builder }}
continue-on-error: ${{ matrix.branch == 'version-1-6' || matrix.branch == 'devel' }}
steps:
- name: Git checkout
uses: actions/checkout@v2
with:
submodules: true

- name: Install build dependencies (Linux i386)
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
run: |
sudo dpkg --add-architecture i386
sudo apt-get update -qq
sudo DEBIAN_FRONTEND='noninteractive' apt-get install \
--no-install-recommends -yq gcc-multilib g++-multilib \
libssl-dev:i386 libpcre3-dev:i386
mkdir -p external/bin
cat << EOF > external/bin/gcc
#!/bin/bash
exec $(which gcc) -m32 -mno-adx "\$@"
EOF
cat << EOF > external/bin/g++
#!/bin/bash
exec $(which g++) -m32 -mno-adx "\$@"
EOF
chmod 755 external/bin/gcc external/bin/g++
echo "${{ github.workspace }}/external/bin" >> $GITHUB_PATH

- name: MSYS2 (Windows i386)
if: runner.os == 'Windows' && matrix.target.cpu == 'i386'
uses: msys2/setup-msys2@v2
with:
path-type: inherit
msystem: MINGW32
install: >-
base-devel
git
mingw-w64-i686-toolchain

- name: MSYS2 (Windows amd64)
if: runner.os == 'Windows' && matrix.target.cpu == 'amd64'
uses: msys2/setup-msys2@v2
with:
path-type: inherit
install: >-
base-devel
git
mingw-w64-x86_64-toolchain

- name: Restore Nim DLLs dependencies (Windows) from cache
if: runner.os == 'Windows'
id: windows-dlls-cache
uses: actions/cache@v2
with:
path: external/dlls-${{ matrix.target.cpu }}
key: 'dlls-${{ matrix.target.cpu }}'

- name: Install DLLs dependencies (Windows)
if: >
steps.windows-dlls-cache.outputs.cache-hit != 'true' &&
runner.os == 'Windows'
run: |
mkdir -p external
curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip
7z x -y external/windeps.zip -oexternal/dlls-${{ matrix.target.cpu }}

- name: Path to cached dependencies (Windows)
if: >
runner.os == 'Windows'
run: |
echo "${{ github.workspace }}/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH

- name: Derive environment variables
run: |
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
PLATFORM=x64
else
PLATFORM=x86
fi
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV

ncpu=
MAKE_CMD="make"
case '${{ runner.os }}' in
'Linux')
ncpu=$(nproc)
;;
'macOS')
ncpu=$(sysctl -n hw.ncpu)
;;
'Windows')
ncpu=$NUMBER_OF_PROCESSORS
MAKE_CMD="mingw32-make"
;;
esac
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
echo "ncpu=$ncpu" >> $GITHUB_ENV
echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV

- name: Build the Nim compiler
run: |
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh
env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ matrix.branch }} \
QUICK_AND_DIRTY_COMPILER=1 CC=gcc \
bash build_nim.sh nim csources dist/nimble NimBinaries
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH

- name: Update config files (Windows)
if: runner.os == 'Windows'
run: |
# ./configure can't figure out the "MSYS_NT-6.3" platform with old autoconf files
curl -o vendor/libbacktrace-upstream/config.guess -L -s -S "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD"
curl -o vendor/libbacktrace-upstream/config.sub -L -s -S "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD"

- name: Run tests
run: |
if [[ "${{ matrix.target.os }}" == "windows" ]]; then
# https://github.com/status-im/nimbus-eth2/issues/3121
export NIMFLAGS="-d:nimRawSetjmp"
fi
nim --version
${MAKE_CMD} -j ${ncpu}
${MAKE_CMD} test

49 changes: 29 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ ifneq ($(USE_SYSTEM_LIBS), 0)
NIM_PARAMS := $(NIM_PARAMS) -d:libbacktraceUseSystemLibs
endif

ECHO_AND_RUN = echo -e "\n$(CMD)\n"; $(CMD) $(MACOS_DEBUG_SYMBOLS) && ./build/$@
ECHO_AND_RUN = echo -e "\n$(CMD)\n"; $(CMD) $(MACOS_DEBUG_SYMBOLS) && ./build/$@ 2>&1 | tee $@_out.txt
CHECK_NOT_SUPPORTED_CMD = tests/not_supported.sh $@_out.txt
CHECK_NOT_SUPPORTED = { echo "$(CHECK_NOT_SUPPORTED_CMD)"; $(CHECK_NOT_SUPPORTED_CMD); }
CHECK_SUPPORTED_NOT_ENABLED_CMD = tests/supported_not_enabled.sh $@_out.txt
CHECK_SUPPORTED_NOT_ENABLED = { echo "$(CHECK_SUPPORTED_NOT_ENABLED_CMD)"; $(CHECK_SUPPORTED_NOT_ENABLED_CMD); }
CHECK_SUPPORTED_AND_ENABLED_CMD = tests/supported_and_enabled.sh $@_out.txt
CHECK_SUPPORTED_AND_ENABLED = { echo "$(CHECK_SUPPORTED_AND_ENABLED_CMD)"; $(CHECK_SUPPORTED_AND_ENABLED_CMD); }
LIBDIR := install/usr/lib
INCLUDEDIR := install/usr/include
CFLAGS += -g -O3 -std=gnu11 -pipe -Wall -Wextra -fPIC
Expand Down Expand Up @@ -133,49 +139,52 @@ endif # USE_VENDORED_LIBUNWIND
# to "./configure". We already set CC in the environment, so it doesn't matter
# what the target host is, as long as it's a valid one.
$(LIBDIR)/libbacktrace.a:
+ echo -e $(BUILD_MSG) "$@" && \
+ echo -e $(BUILD_MSG) "$@"; \
mkdir -p "$(CURDIR)/install/usr"; \
cd vendor/libbacktrace-upstream && \
./configure --prefix="/usr" --libdir="/usr/lib" --disable-shared --enable-static \
--with-pic --build=$(./config.guess) --host=arm MAKE="$(MAKE)" $(HANDLE_OUTPUT) && \
--with-pic --build=$$(./config.guess) --host=arm MAKE="$(MAKE)" $(HANDLE_OUTPUT) && \
$(LIBBACKTRACE_SED) && \
$(MAKE) -j1 DESTDIR="$(CURDIR)/install" clean all install $(HANDLE_OUTPUT)

# DESTDIR does not work on Windows for a CMake-generated Makefile
$(LIBDIR)/libunwind.a:
+ echo -e $(BUILD_MSG) "$@"; \
which $(CMAKE) &>/dev/null || { echo $(CMAKE_MISSING_MSG); exit 1; }; \
mkdir -p "$(CURDIR)/install/usr"; \
cd vendor/libunwind && \
rm -f CMakeCache.txt && \
$(CMAKE) -DLIBUNWIND_ENABLE_SHARED=OFF -DLIBUNWIND_ENABLE_STATIC=ON -DLIBUNWIND_INCLUDE_DOCS=OFF \
-DLIBUNWIND_LIBDIR_SUFFIX="" -DCMAKE_INSTALL_PREFIX="$(CURDIR)/install/usr" -DCMAKE_CROSSCOMPILING=1 \
$(CMAKE_ARGS) . $(HANDLE_OUTPUT) && \
$(MAKE) VERBOSE=$(V) clean install $(HANDLE_OUTPUT) && \
cp -a include "$(CURDIR)/install/usr/"
cp -a include "$(CURDIR)/install/usr/" && ls -lR "$(CURDIR)/install/usr/"

test: $(TESTS)

$(TESTS): all
$(eval CMD := nim c $(NIM_PARAMS) tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native --stackTrace:off tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:debug tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release -d:nimStackTraceOverride tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:danger tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:danger -d:nimStackTraceOverride tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release --gcc.options.debug:'-g1' -d:nimStackTraceOverride tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_NOT_SUPPORTED)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_NOT_ENABLED)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native --stackTrace:off tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_NOT_ENABLED)
# parameter order matters for Nim-1.4 and up: https://github.com/nim-lang/Nim/issues/18921
$(eval CMD := nim c $(NIM_PARAMS) -d:debug --debugger:native tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_NOT_ENABLED)
$(eval CMD := nim c $(NIM_PARAMS) -d:release --debugger:native tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_NOT_ENABLED)
$(eval CMD := nim c $(NIM_PARAMS) -d:release --debugger:native -d:nimStackTraceOverride tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_AND_ENABLED)
$(eval CMD := nim c $(NIM_PARAMS) -d:danger --debugger:native tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_NOT_ENABLED)
$(eval CMD := nim c $(NIM_PARAMS) -d:danger --debugger:native -d:nimStackTraceOverride tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_AND_ENABLED)
$(eval CMD := nim c $(NIM_PARAMS) -d:release --debugger:native --gcc.options.debug:'-g1' -d:nimStackTraceOverride tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_AND_ENABLED)
ifeq ($(shell uname), Darwin)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release --passC:-flto=thin --passL:"-flto=thin -Wl,-object_path_lto,build/[email protected]" tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release -d:nimStackTraceOverride --passC:-flto=thin --passL:"-flto=thin -Wl,-object_path_lto,build/[email protected]" tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) -d:release --debugger:native --passC:-flto=thin --passL:"-flto=thin -Wl,-object_path_lto,build/[email protected]" tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_NOT_ENABLED)
$(eval CMD := nim c $(NIM_PARAMS) -d:release --debugger:native -d:nimStackTraceOverride --passC:-flto=thin --passL:"-flto=thin -Wl,-object_path_lto,build/[email protected]" tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_AND_ENABLED)
else
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release --passC:-flto=auto --passL:-flto=auto tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) --debugger:native -d:release -d:nimStackTraceOverride --passC:-flto=auto --passL:-flto=auto tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim c $(NIM_PARAMS) -d:release --debugger:native --passC:-flto=auto --passL:-flto=auto tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_NOT_ENABLED)
$(eval CMD := nim c $(NIM_PARAMS) -d:release --debugger:native -d:nimStackTraceOverride --passC:-flto=auto --passL:-flto=auto tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_AND_ENABLED)
endif
ifeq ($(BUILD_CXX_LIB), 1)
# for the C++ backend:
$(eval CMD := nim cpp $(NIM_PARAMS) --debugger:native tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim cpp $(NIM_PARAMS) --debugger:native -d:release -d:nimStackTraceOverride tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim cpp $(NIM_PARAMS) --debugger:native -d:release --gcc.cpp.options.debug:'-g1' -d:nimStackTraceOverride tests/[email protected]) $(ECHO_AND_RUN)
$(eval CMD := nim cpp $(NIM_PARAMS) --debugger:native tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_NOT_ENABLED)
$(eval CMD := nim cpp $(NIM_PARAMS) -d:release --debugger:native -d:nimStackTraceOverride tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_AND_ENABLED)
$(eval CMD := nim cpp $(NIM_PARAMS) -d:release --debugger:native --gcc.cpp.options.debug:'-g1' -d:nimStackTraceOverride tests/[email protected]) $(ECHO_AND_RUN) && $(CHECK_SUPPORTED_AND_ENABLED)
endif

clean:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ away with significantly fewer debugging symbols by switching to "-g1":

```bash
# for the C backend
nim c --debugger:native --gcc.options.debug:'-g1' -d:release somefile.nim
nim c -d:release --debugger:native --gcc.options.debug:'-g1' somefile.nim

# for the C++ backend
nim cpp --debugger:native --gcc.cpp.options.debug:'-g1' -d:release somefile.nim
nim cpp -d:release --debugger:native --gcc.cpp.options.debug:'-g1' somefile.nim

# Clang needs a different argument
nim c --cc:clang --debugger:native --clang.options.debug:'-gline-tables-only' -d:release somefile.nim
nim c --cc:clang -d:release --debugger:native --clang.options.debug:'-gline-tables-only' somefile.nim
```

When the C compiler inlines some functions, or does tail-call optimisation -
Expand Down
11 changes: 11 additions & 0 deletions tests/not_supported.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

F="$1"

[[ -f "${F}" ]] || { echo "Output file not found: ${F}. Aborting."; exit 1; }

# catering for the rare case Glibc has debugging symbols
[[ $(grep -Ev "libc-start.c|libc_start_call_main.h" "${F}" | grep -A1 "getBacktrace():" | grep -v '^$' | wc -l | tr -d '[:space:]') == 1 ]] || { echo "Check failed."; exit 1; }

rm -f "${F}"

12 changes: 12 additions & 0 deletions tests/supported_and_enabled.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

F="$1"

[[ -f "${F}" ]] || { echo "Output file not found: ${F}. Aborting."; exit 1; }

[[ $(grep -A1 "getBacktrace():" "${F}" | grep -v '^$' | wc -l | tr -d '[:space:]') == 2 ]] || { echo "Check failed."; exit 1; }

[[ $(grep -A1 "^Traceback (most recent call last, using override)$" "${F}" | grep -v '^$' | wc -l | tr -d '[:space:]') == 2 ]] || { echo "Check failed."; exit 1; }

rm -f "${F}"

16 changes: 16 additions & 0 deletions tests/supported_not_enabled.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

F="$1"

[[ -f "${F}" ]] || { echo "Output file not found: ${F}. Aborting."; exit 1; }

[[ $(grep -A1 "getBacktrace():" "${F}" | grep -v '^$' | wc -l | tr -d '[:space:]') == 2 ]] || { echo "Check failed."; exit 1; }

grep -Eq "^Traceback \(most recent call last\)|No stack traceback available$" "${F}" || { echo "Check failed."; exit 1; }

if grep -q "^Traceback (most recent call last)$" "${F}"; then
[[ $(grep -A1 "^Traceback (most recent call last)$" "${F}" | grep -v '^$' | wc -l | tr -d '[:space:]') == 2 ]] || { echo "Check failed."; exit 1; }
fi

rm -f "${F}"

4 changes: 0 additions & 4 deletions tests/test1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ proc f3(i: int): int =
writeStackTrace()
stderr.flushFile()

echo "\ngetBacktrace():"
echo getBacktrace()
stderr.flushFile()

return i + 4

proc f2(i: int): int =
Expand Down
2 changes: 1 addition & 1 deletion vendor/libbacktrace-upstream
Loading