From 9db836a9e845a4965bf1bc48a265a84373a6e407 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Sat, 26 Feb 2022 14:48:08 -0600 Subject: [PATCH] [wip] first steps toward a Nim wrapper for github.com/catid/leopard --- .github/workflows/ci.yml | 4 +-- Makefile | 61 +++++++++++++++++++++++++++--------- dagger/leopard.nim | 5 +++ tests/dagger/testleopard.nim | 5 +++ tests/testAll.nim | 2 ++ 5 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 dagger/leopard.nim create mode 100644 tests/dagger/testleopard.nim diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26dce3b3..eef45e3e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,6 @@ jobs: fail-fast: false max-parallel: 20 matrix: - branch: [v1.4.6] target: # Unit tests - os: linux @@ -35,7 +34,7 @@ jobs: - target: os: windows builder: windows-2019 - name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (${{ matrix.branch }})' + name: '${{ matrix.target.os }}-${{ matrix.target.cpu }}' runs-on: ${{ matrix.builder }} steps: - name: Checkout nim-dagger @@ -93,6 +92,7 @@ jobs: EOF chmod 755 external/bin/gcc external/bin/g++ echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH + echo "LIBLEOPARD_CMAKE_FLAGS=-DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32" >> $GITHUB_ENV - name: Restore MinGW-W64 (Windows) from cache if: runner.os == 'Windows' diff --git a/Makefile b/Makefile index e00f84e9..f01b3afe 100644 --- a/Makefile +++ b/Makefile @@ -23,9 +23,12 @@ LINK_PCRE := 0 all \ deps \ update \ + leopard \ + testAll \ test \ - clean \ - libbacktrace + libbacktrace \ + clean-leopard \ + clean ifeq ($(NIM_PARAMS),) # "variables.mk" was not included, so we update the submodules. @@ -48,6 +51,16 @@ all: | test # must be included after the default target -include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk +# detecting the os +ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10... +detected_OS := Windows +else ifeq ($(strip $(shell uname)),Darwin) +detected_OS := macOS +else + # e.g. Linux +detected_OS := $(strip $(shell uname)) +endif + # "-d:release" implies "--stacktrace:off" and it cannot be added to config.nims ifeq ($(USE_LIBBACKTRACE), 0) NIM_PARAMS := $(NIM_PARAMS) -d:debug -d:disable_libbacktrace @@ -55,7 +68,7 @@ else NIM_PARAMS := $(NIM_PARAMS) -d:release endif -deps: | deps-common nat-libs dagger.nims +deps: | deps-common nat-libs dagger.nims leopard ifneq ($(USE_LIBBACKTRACE), 0) deps: | libbacktrace endif @@ -67,20 +80,37 @@ update: | update-common # a phony target, because teaching `make` how to do conditional recompilation of Nim projects is too complicated +LIBLEOPARD := $(shell pwd)/vendor/leopard/build/liblibleopard.a +LIBLEOPARD_HEADER := $(shell pwd)/vendor/leopard/leopard.h + +ifeq ($(detected_OS),Windows) +LIBLEOPARD_CMAKE_FLAGS ?= -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release +else +LIBLEOPARD_CMAKE_FLAGS ?= -DCMAKE_BUILD_TYPE=Release +endif + +ifeq ($(detected_OS),Windows) +NIM_PARAMS += --passC:"-I$(shell cygpath -m $(shell dirname $(LIBLEOPARD_HEADER)))" --passL:"$(shell cygpath -m $(LIBLEOPARD))" +else +NIM_PARAMS += --passC:"-I$(shell dirname $(LIBLEOPARD_HEADER))" --passL:"$(LIBLEOPARD)" +endif + +ifneq ($(detected_OS),macOS) +NIM_PARAMS += --passL:"-fopenmp" +endif + +$(LIBLEOPARD): + cd vendor/leopard && \ + mkdir -p build && cd build && \ + cmake .. $(LIBLEOPARD_CMAKE_FLAGS) && \ + $(MAKE) + +leopard: $(LIBLEOPARD) + testAll: | build deps echo -e $(BUILD_MSG) "build/$@" && \ $(ENV_SCRIPT) nim testAll $(NIM_PARAMS) dagger.nims -# detecting the os -ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10... - detected_OS := Windows -else ifeq ($(strip $(shell uname)),Darwin) - detected_OS := macOS -else - # e.g. Linux - detected_OS := $(strip $(shell uname)) -endif - # Builds and run the test suite (Waku v1 + v2) test: | testAll @@ -92,8 +122,11 @@ dagger.nims: libbacktrace: + $(MAKE) -C vendor/nim-libbacktrace --no-print-directory BUILD_CXX_LIB=0 +clean-leopard: + rm -rf $(shell dirname $(LIBLEOPARD)) + # usual cleaning -clean: | clean-common +clean: | clean-common clean-leopard rm -rf build ifneq ($(USE_LIBBACKTRACE), 0) + $(MAKE) -C vendor/nim-libbacktrace clean $(HANDLE_OUTPUT) diff --git a/dagger/leopard.nim b/dagger/leopard.nim new file mode 100644 index 00000000..66960c5f --- /dev/null +++ b/dagger/leopard.nim @@ -0,0 +1,5 @@ +const header = "leopard.h" + +{.pragma: leo, cdecl, header: header, importCpp.} + +proc leo_init*(): cint {.leo.} diff --git a/tests/dagger/testleopard.nim b/tests/dagger/testleopard.nim new file mode 100644 index 00000000..d1fda3da --- /dev/null +++ b/tests/dagger/testleopard.nim @@ -0,0 +1,5 @@ +import pkg/dagger/leopard + +let lin = leo_init() + +echo "leo_init() return code: " & $lin diff --git a/tests/testAll.nim b/tests/testAll.nim index f9e7167e..232b633b 100644 --- a/tests/testAll.nim +++ b/tests/testAll.nim @@ -4,5 +4,7 @@ import ./dagger/testasyncheapqueue import ./dagger/testchunking import ./dagger/testmanifest import ./dagger/testnode +import ./dagger/testleopard + {.warning[UnusedImport]: off.}