From b9a5649d0292aef62f648a8186d797785e9ff5a9 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Thu, 10 Oct 2024 13:20:38 +0200 Subject: [PATCH] further build system cleanup sonarqube target put aside (WIP) modular meson targets --- Makefile | 190 ++++++++------------------------------------- build/luarock.mk | 5 -- build/meson.build | 2 +- build/meson.mk | 29 ++++--- build/scanbuild.sh | 1 + build/sonarqube.mk | 31 ++++++++ 6 files changed, 84 insertions(+), 174 deletions(-) delete mode 100644 build/luarock.mk create mode 100644 build/sonarqube.mk diff --git a/Makefile b/Makefile index 0f315aeb1..0beb7c4a4 100644 --- a/Makefile +++ b/Makefile @@ -3,159 +3,46 @@ # # SPDX-License-Identifier: AGPL-3.0-or-later +.PHONY: help + pwd := $(shell pwd) # ARCH ?=$(shell uname -m) PREFIX ?= /usr/local -# VERSION is set in src/Makefile -# Targets to be build in this order -BUILDS := apply-patches milagro lua54 embed-lua quantum-proof ed25519-donna mimalloc - +# VERSION is set in build/init.mk # DESTDIR is supported by install target -# include platform specific configurations pattern-matching target labels -include ${pwd}/build/config.mk - -all: - @echo "Choose a target:" - @echo "- linux, linux-lib, linux-clang, linux-debug" - @echo "- javascript-web, javascript-wasm, javascript-demo, javascript-rn (need EMSDK)" - @echo "- linux-python3, linux-go, osx-python3, osx-go (language bindings)" - @echo "- osx, osx-lib, ios-lib, ios-armv7, ios-arm64, ios-sim (need Apple/OSX)" - @echo "- win, win-dll (cross-compile using MINGW on Linux)" - @echo "- musl, musl-local, musl-system (full static build)" - @echo "- android-arm android-x86 android-aarch64" - @echo "- cortex-arm, linux-riscv64, aarch64" - @echo "for android and ios see scripts in build/" - -# if ! [ -r build/luac ]; then ${gcc} -I${luasrc} -o build/luac ${luasrc}/luac.c ${luasrc}/liblua.a -lm; fi - -sonarqube: - @echo "Configure login token in build/sonarqube.sh" - cp -v build/sonar-project.properties . - ./build/sonarqube.sh - -embed-lua: lua_embed_opts := $(if ${COMPILE_LUA}, compile) -embed-lua: - @echo "Embedding all files in src/lua" - ./build/embed-lualibs ${lua_embed_opts} - @echo "File generated: src/lualibs_detected.c" - -src/zen_ecdh_factory.c: - ${pwd}/build/codegen_ecdh_factory.sh ${ecdh_curve} - -src/zen_ecp_factory.c: - ${pwd}/build/codegen_ecp_factory.sh ${ecp_curve} - -src/zen_big_factory.c: - ${pwd}/build/codegen_ecp_factory.sh ${ecp_curve} - -apply-patches: src/zen_ecdh_factory.c src/zen_ecp_factory.c src/zen_big_factory.c - -# build target for javascript (emscripten) -javascript: ${BUILDS} - CC="${gcc}" AR="${ar}" CFLAGS="${cflags}" \ - LDFLAGS="${ldflags}" LDADD="${ldadd}" \ - make -C src js - @mkdir -p build/npm - @cp -v src/zenroom.js build/npm/ - -# build luarock module -include ${pwd}/build/luarock.mk - -# experimental target for xtensa embedded boards -esp32: apply-patches milagro lua54 - CC=${pwd}/build/xtensa-esp32-elf/bin/xtensa-esp32-elf-${gcc} \ - LD=${pwd}/build/xtensa-esp32-elf/bin/xtensa-esp32-elf-ld \ - CFLAGS="${cflags}" LDFLAGS="${ldflags}" LDADD="${ldadd}" \ - $(MAKE) -C src linux - -# static dependencies in lib -# lpeglabel: -# CC=${gcc} CFLAGS="${cflags} -I${pwd}/lib/lua54/src" AR="${ar}" $(MAKE) -C lib/lpeglabel - -lua54: - CC="${lua_cc}" CFLAGS="${cflags} ${lua_cflags}" \ - LDFLAGS="${ldflags}" AR="${ar}" RANLIB=${ranlib} \ - $(MAKE) -C ${pwd}/lib/lua54/src liblua.a - -android-lua54: - CC="${lua_cc}" CFLAGS="${cflags} ${lua_cflags}" \ - LDFLAGS="${ldflags}" AR="${ar}" RANLIB=${ranlib} \ - $(MAKE) -C ${pwd}/lib/lua54/src ${platform} - -musl-lua54: - CC="${lua_cc}" CFLAGS="${cflags} ${lua_cflags}" \ - LDFLAGS="${ldflags}" AR="${ar}" RANLIB=${ranlib} \ - $(MAKE) -C ${pwd}/lib/lua54/src ${platform} - -cortex-lua54: - CC="${lua_cc}" CFLAGS="${cflags} ${lua_cflags} -DLUA_BAREBONE" \ - LDFLAGS="${ldflags}" AR="${ar}" RANLIB=${ranlib} \ - $(MAKE) -C ${pwd}/lib/lua54/src ${platform} - -milagro-debug: milagro -milagro: - @echo "-- Building milagro (${system})" - if ! [ -r ${pwd}/lib/milagro-crypto-c/build/CMakeCache.txt ]; then \ - cd ${pwd}/lib/milagro-crypto-c && \ - mkdir -p build && \ - cd build && \ - CC=${gcc} LD=${ld} AR=${ar} \ - cmake ../ -DCMAKE_C_FLAGS="${cflags}" -DCMAKE_SYSTEM_NAME="${system}" \ - -DCMAKE_AR=${ar} -DCMAKE_C_COMPILER=${gcc} ${milagro_cmake_flags}; \ - fi - if ! [ -r ${pwd}/lib/milagro-crypto-c/build/lib/libamcl_core.a ]; then \ - RANLIB=${ranlib} LD=${ld} \ - $(MAKE) -C ${pwd}/lib/milagro-crypto-c/build; \ - fi - -mimalloc-debug: mimalloc -mimalloc: - $(info -- Building mimalloc (${system})) - if ! [ -r ${pwd}/lib/mimalloc/build/CMakeCache.txt ]; then \ - cd ${pwd}/lib/mimalloc && \ - mkdir -p build && \ - cd build && \ - CC=${gcc} LD=${ld} AR=${AR} \ - cmake ../ ${mimalloc_cmake_flags} \ - -DCMAKE_C_FLAGS="${cflags} ${mimalloc_cflags}" \ - -DCMAKE_SYSTEM_NAME="${system}" \ - -DCMAKE_AR=${ar} -DCMAKE_C_COMPILER=${gcc} \ - -DCMAKE_CXX_COMPILER=$(subst gcc,g++,${gcc}); \ - fi - if ! [ -r ${pwd}/lib/mimalloc/build/libmimalloc-static.a ]; then \ - RANLIB=${ranlib} LD=${ld} \ - ${MAKE} -C ${pwd}/lib/mimalloc/build; \ - fi - -quantum-proof-ccache: quantum-proof -quantum-proof-debug: quantum-proof -quantum-proof: - $(info -- Building Quantum-Proof libs) - CC="${quantum_proof_cc}" \ - LD=${ld} \ - AR=${ar} \ - RANLIB=${ranlib} \ - LD=${ld} \ - CFLAGS="${quantum_proof_cflags} ${cflags}" \ - LDFLAGS="${ldflags}" \ - ${MAKE} -C ${pwd}/lib/pqclean - -check-milagro: milagro - CC=${gcc} CFLAGS="${cflags}" $(MAKE) -C ${pwd}/lib/milagro-crypto-c test - -ed25519-donna-ccache: ed25519-donna -ed25519-donna: - echo "-- Building ED25519 for EDDSA" - CC="${ed25519_cc}" \ - AR=${ar} \ - CFLAGS="${cflags}" \ - LDFLAGS="${ldflags}" \ - $(MAKE) -C ${pwd}/lib/ed25519-donna +help: + @echo "āœØ Welcome to the Zenroom build system" + @awk 'BEGIN {FS = ":.*##"; printf "šŸ›Ÿ Usage: make \033[36m\033[0m\nšŸ‘‡šŸ½ List of targets:\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5)} ' Makefile + +# help: ## šŸ›Ÿ Show this help message +# @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m šŸ‘‰ %-14s\033[0m %s\n", $$1, $$2}' + +x86-linux: ## Dynamic executable for Linux x86 64bit + $(MAKE) -f build/linux.mk + +x86-musl: ## Static executable for Linux x86 64bit + $(MAKE) -f build/musl-linux.mk + +# bindings: ## Language binding for host platform +# $(MAKE) -f build/linux.mk deps zencode-exec + +x86-win-exe: ## Executable for Windows x86 64bit + $(MAKE) -f build/win-exe.mk + +x86-win-dll: ## Dynamic lib (DLL) for Windows x86 64bit + $(MAKE) -f build/win-dll.mk + +arm64-ios: ## Dynamic lib (dylib) for Apple iOS ARM64 + $(MAKE) -f build/apple-osx.mk ios-arm64 + +sim-ios: ## Dynamic lib (dylib) for Apple iOS simulator + $(MAKE) -f build/apple-ios.mk ios-sim + +wasm: ## WebAssembly (WASM) for Javascript in-browser (Emscripten) + yarn --cwd bindings/javascript + yarn --cwd bindings/javascript build -# ------------------- -# Test suites for all platforms -include ${pwd}/build/tests.mk install: destbin=${DESTDIR}${PREFIX}/bin install: destdocs=${DESTDIR}${PREFIX}/share/zenroom @@ -169,12 +56,6 @@ install: cp LICENSE.txt ${destdocs}/LICENSE.txt cp ChangeLog.md ${destdocs}/ChangeLog.txt -install-lua: destlib=${LIBDIR} -install-lua: - mkdir -p ${destlib} - cp src/octet.so ${destlib} - cp src/ecdh.so ${destlib} - clean: rm -rf ${pwd}/meson $(MAKE) clean -C ${pwd}/lib/lua54/src @@ -202,9 +83,6 @@ clean-src: rm -f src/zen_ecdh_factory.c src/zen_ecp_factory.c src/zen_big_factory.c $(MAKE) clean -C src -distclean: - rm -rf ${musl} - # ------------------- # Parsing the documentation needed-docs: diff --git a/build/luarock.mk b/build/luarock.mk deleted file mode 100644 index 4a763ab4f..000000000 --- a/build/luarock.mk +++ /dev/null @@ -1,5 +0,0 @@ -linux-luarock: cflags := -O3 ${cflags_protection} -fPIE -fPIC -linux-luarock: cflags += -shared -DLIBRARY -linux-luarock: apply-patches milagro lua54 embed-lua - CC=${gcc} CFLAGS="${cflags}" LDFLAGS="${ldflags}" LDADD="${ldadd}" \ - make -C src luarock diff --git a/build/meson.build b/build/meson.build index 861c81933..bf092869d 100644 --- a/build/meson.build +++ b/build/meson.build @@ -60,7 +60,7 @@ zenroom_include_dirs = include_directories('../src') milagro_include_dirs = include_directories('../lib/milagro-crypto-c/include') -milagro_generated_include_dirs = include_directories('milagro-crypto-c/include') +milagro_generated_include_dirs = include_directories('../lib/milagro-crypto-c/build/include') mimalloc_include_dirs = include_directories('../lib/mimalloc/include') diff --git a/build/meson.mk b/build/meson.mk index fec6d87fa..b6901521f 100644 --- a/build/meson.mk +++ b/build/meson.mk @@ -16,14 +16,29 @@ endif # activate CCACHE etc. include build/plugins.mk +all: deps prepare config ninja + # MAIN TARGETS -all: ${BUILD_DEPS} prepare +deps: ${BUILD_DEPS} + +# subtargets +prepare: + mkdir -p meson + ln -sf ../lib/milagro-crypto-c/build meson/milagro-crypto-c + ln -sf ../lib/pqclean/libqpz.a meson/libqpz.a + ln -sf ../lib/lua54/src/liblua.a meson/liblua.a + ln -sf ../lib/ed25519-donna/libed25519.a meson/libed25519.a + ln -sf ../lib/mimalloc/build/libmimalloc-static.a meson/libmimalloc-static.a + ln -sf ../lib/tinycc/libtcc.a meson/libtcc.a + +config: CC="${zenroom_cc}" AR="${ar}" CFLAGS="${cflags}" \ LDFLAGS="${ldflags}" LDADD="${ldadd}" meson -Dexamples=true \ -Ddocs=true -Doptimization=3 -Decdh_curve=${ecdh_curve} \ -Decp_curve=${ecp_curve} -Ddefault_library=both build meson + +ninja: ninja -C meson -gcc: all asan: CC="clang" CXX="clang++" AR="llvm-ar" CFLAGS="-fsanitize=address \ @@ -34,16 +49,6 @@ asan: -Db_sanitize=address build meson ninja -C meson -# subtargets -prepare: - mkdir -p meson - ln -sf ../lib/milagro-crypto-c/build meson/milagro-crypto-c - ln -sf ../lib/pqclean/libqpz.a meson/libqpz.a - ln -sf ../lib/lua54/src/liblua.a meson/liblua.a - ln -sf ../lib/ed25519-donna/libed25519.a meson/libed25519.a - ln -sf ../lib/mimalloc/build/libmimalloc-static.a meson/libmimalloc-static.a - ln -sf ../lib/tinycc/libtcc.a meson/libtcc.a - prepare-test: echo '#!/bin/sh' > ${pwd}/test/zenroom echo "${pwd}/meson/zenroom "'$$*' >> ${pwd}/test/zenroom diff --git a/build/scanbuild.sh b/build/scanbuild.sh index f16de1aa1..2768a0d27 100755 --- a/build/scanbuild.sh +++ b/build/scanbuild.sh @@ -1,2 +1,3 @@ #!/bin/sh +# wrapper script passed to ninja in build/sonarqube.mk scan-build -v -plist "$@" diff --git a/build/sonarqube.mk b/build/sonarqube.mk new file mode 100644 index 000000000..573b8d7fd --- /dev/null +++ b/build/sonarqube.mk @@ -0,0 +1,31 @@ + +## Initialize build defaults +include build/init.mk + +## TODO: test with sonarqube server (we moved out of ow2) +SONAR_LOGIN ?= "" +SONAR_HOST_URL := https://sonarqube.ow2.org +SCANBUILD_SCRIPT := $(pwd)/build/scanbuild.sh + +# Needs clang-tools for scan-build + +COMPILER := clang + +cflags += ${cflags_debug} -fPIC +# activate CCACHE etc. +include build/plugins.mk + +sonarqube: ## build a sonarqube cpp static analysis + $(info Configure login token in build/sonarqube.sh) + $(MAKE) -f build/meson.mk deps COMPILER=clang + $(MAKE) -f build/meson.mk prepare COMPILER=clang + $(MAKE) -f build/meson.mk config COMPILER=clang + SCANBUILD=${SCANBUILD_SCRIPT} ninja -C meson scan-build + @docker pull sonarqube + @cp -v build/sonar-project.properties . + @docker run --rm -e SONAR_HOST_URL=${SONAR_HOST_URL} \ + -e SONAR_LOGIN=${SONAR_LOGIN} \ + -v ${pwd}:/usr/src sonarsource/sonar-scanner-cli \ + -Dsonar.projectKey=zenroom + +# sonarqube debug -X