From b09cd713487d7feb4dc6ffecebe0f438ba930ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Thu, 4 Nov 2021 15:35:36 +0100 Subject: [PATCH] build: show stderr by default Also added: `-d:cwarnings` and `-d:limitStackUsage` --- config.nims | 21 +++++++++++++++++++++ docs/the_nimbus_book/src/developers.md | 22 ++++++++++++++-------- scripts/compile_nim_program.sh | 3 ++- vendor/nimbus-build-system | 2 +- 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/config.nims b/config.nims index 05c99d23a..ca639083c 100644 --- a/config.nims +++ b/config.nims @@ -13,6 +13,10 @@ switch("nimcache", nimCachePath) # `-flto` gives a significant improvement in processing speed, specially hash tree and state transition (basically any CPU-bound code implemented in nim) # With LTO enabled, optimization flags should be passed to both compiler and linker! if defined(release) and not defined(disableLTO): + # "-w" is not passed to the compiler during linking, so we need to disable + # some warnings by hand. + switch("passL", "-Wno-stringop-overflow -Wno-stringop-overread") + if defined(macosx): # Clang switch("passC", "-flto=thin") switch("passL", "-flto=thin -Wl,-object_path_lto," & nimCachePath & "/lto") @@ -26,6 +30,23 @@ if defined(release) and not defined(disableLTO): # used for static libraries. discard +# show C compiler warnings +if defined(cwarnings): + let common_gcc_options = "-Wno-discarded-qualifiers -Wno-incompatible-pointer-types" + if defined(windows): + put("gcc.options.always", "-mno-ms-bitfields " & common_gcc_options) + put("clang.options.always", "-mno-ms-bitfields " & common_gcc_options) + else: + put("gcc.options.always", common_gcc_options) + put("clang.options.always", common_gcc_options) + +if defined(limitStackUsage): + # This limits stack usage of each individual function to 1MB - the option is + # available on some GCC versions but not all - run with `-d:limitStackUsage` + # and look for .su files in "./nimcache/" that list the stack size of each function + switch("passC", "-fstack-usage -Werror=stack-usage=1048576") + switch("passL", "-fstack-usage -Werror=stack-usage=1048576") + if defined(windows): # disable timestamps in Windows PE headers - https://wiki.debian.org/ReproducibleBuilds/TimestampsInPEBinaries switch("passL", "-Wl,--no-insert-timestamp") diff --git a/docs/the_nimbus_book/src/developers.md b/docs/the_nimbus_book/src/developers.md index 33c0442da..d5aca917e 100644 --- a/docs/the_nimbus_book/src/developers.md +++ b/docs/the_nimbus_book/src/developers.md @@ -139,7 +139,19 @@ make NIMFLAGS="-d:disableMarchNative" nimbus_beacon_node make NIMFLAGS="-d:disableLTO" nimbus_beacon_node ``` -- build a static binary +- show C compiler warnings: + +```bash +make NIMFLAGS="-d:cwarnings" nimbus_beacon_node +``` + +- limit stack usage to 1 MiB per C function (static analysis - see the [GCC docs](https://gcc.gnu.org/onlinedocs/gnat_ugn/Static-Stack-Usage-Analysis.html); if LTO is enabled, it works without `-d:cwarnings`): + +```bash +make NIMFLAGS="-d:limitStackUsage" nimbus_beacon_node +``` + +- build a static binary: ```bash make NIMFLAGS="--passL:-static" nimbus_beacon_node @@ -151,18 +163,12 @@ make NIMFLAGS="--passL:-static" nimbus_beacon_node make publish-book ``` -- create a binary distribution +- create a binary distribution: ```bash make dist ``` -- test the binaries - -```bash -make dist-test -``` - ## Multi-client interop scripts [This repository](https://github.com/eth2-clients/multinet) contains a set of scripts used by the client implementation teams to test interop between the clients (in certain simplified scenarios). It mostly helps us find and debug issues. diff --git a/scripts/compile_nim_program.sh b/scripts/compile_nim_program.sh index 4bb1ba540..51e0b6ba4 100755 --- a/scripts/compile_nim_program.sh +++ b/scripts/compile_nim_program.sh @@ -23,7 +23,8 @@ PROJECT_NAME="$(basename ${SOURCE%.nim})" # LTO on macOS, in "config.nims" nim c --compileOnly -o:build/${BINARY} "$@" -d:nimCachePathOverride=nimcache/release/${BINARY} "${SOURCE}" build/generate_makefile "nimcache/release/${BINARY}/${PROJECT_NAME}.json" "nimcache/release/${BINARY}/${BINARY}.makefile" -[[ "$V" == "0" ]] && exec &>/dev/null +# Don't swallow stderr, in case it's important. +[[ "$V" == "0" ]] && exec >/dev/null "${MAKE}" -f "nimcache/release/${BINARY}/${BINARY}.makefile" --no-print-directory build if uname | grep -qi darwin || [[ -n "${FORCE_DSYMUTIL}" ]]; then diff --git a/vendor/nimbus-build-system b/vendor/nimbus-build-system index 9d6b4b6e9..5fbffb228 160000 --- a/vendor/nimbus-build-system +++ b/vendor/nimbus-build-system @@ -1 +1 @@ -Subproject commit 9d6b4b6e98515af8248127f51889c24308006096 +Subproject commit 5fbffb22859a85aa0dc3e9238cc03d92ab197682