From af2cef2aaabc37ea16391ee0e1ec593b63222568 Mon Sep 17 00:00:00 2001 From: alien <118136375+alienc0der@users.noreply.github.com> Date: Tue, 27 Dec 2022 19:09:13 +0200 Subject: [PATCH 1/3] Added Github Actions --- .github/workflows/znn_pow_links_builder.yml | 156 ++++++++++++++++++++ CMakeLists.txt | 36 ++++- aarch64-linux-gnu.cmake | 9 ++ mingw-w64-x86_64.cmake | 10 ++ 4 files changed, 203 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/znn_pow_links_builder.yml create mode 100644 aarch64-linux-gnu.cmake create mode 100644 mingw-w64-x86_64.cmake diff --git a/.github/workflows/znn_pow_links_builder.yml b/.github/workflows/znn_pow_links_builder.yml new file mode 100644 index 0000000..c136ec1 --- /dev/null +++ b/.github/workflows/znn_pow_links_builder.yml @@ -0,0 +1,156 @@ +name: Build and release libpow_links + +on: + push: + branches: + - cicd + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build-macos: + runs-on: macos-12 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup environment + run: | + brew install cmake emscripten + brew cleanup + cmake --version + emcc --version + - name: Setup ios-cmake + run: git clone https://github.com/leetal/ios-cmake.git + - name: Create output directories for resulting binaries + run: | + mkdir ios64 + mkdir simulator64 + mkdir darwin + mkdir wasm + mkdir releases + - name: Build ios-arm64 framework + run: | + cmake CMakeLists.txt -G Xcode -DCMAKE_TOOLCHAIN_FILE=ios-cmake/ios.toolchain.cmake -DPLATFORM=OS64 + cmake --build . --config Release + cp -R build/Release/pow_links.framework/ ios64/pow_links.framework + - name: Cleanup action + run: rm -rf CMakeFiles/ CMakeCache.txt build/* + - name: Build ios-simulator-x86_64 framework + run: | + cmake CMakeLists.txt -G Xcode -DCMAKE_TOOLCHAIN_FILE=ios-cmake/ios.toolchain.cmake -DPLATFORM=SIMULATOR64 + cmake --build . --config Release + cp -R build/Release/pow_links.framework/ simulator64/pow_links.framework + - name: Cleanup action + run: rm -rf CMakeFiles/ CMakeCache.txt build/* + - name: Build darwin dynamic library and framework + run: | + cmake CMakeLists.txt + cmake --build . --config Release + cp -R build/pow_links.framework/ darwin/pow_links.framework + cp build/pow_links.framework/Versions/C/pow_links darwin/libpow_links.dylib + cp build/generator darwin/generator + - name: Cleanup action + run: rm -rf CMakeFiles/ CMakeCache.txt build/* + - name: Build wasm + run: emcc -O3 -s WASM=1 -s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' -s EXPORT_ALL=1 -s LINKABLE=1 src/pow_links.cpp SHA3IUF/sha3.c src/bridge.cpp -o wasm/znn-pow-links.js + - name: Create xcframework + run: xcodebuild -create-xcframework -framework darwin/pow_links.framework -framework ios64/pow_links.framework -framework simulator64/pow_links.framework -output pow_links.xcframework + - name: Archive files + run: | + zip -r pow_links.xcframework.zip pow_links.xcframework + zip -j libpow_links-darwin-universal.zip darwin/libpow_links.dylib darwin/generator + zip -jr libpow_links-wasm.zip wasm/* + - name: Copy archived files to releases + run: cp pow_links.xcframework.zip libpow_links-darwin-universal.zip libpow_links-wasm.zip releases/ + - uses: actions/upload-artifact@v3 + with: + name: macos-artifacts + path: releases/ + build-linux: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup environment + run: | + sudo apt update + sudo apt upgrade -y + sudo apt install -y build-essential cmake zip unzip wget mingw-w64 gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + cmake --version + - name: Create output directories for resulting binaries + run: | + mkdir linux-amd64 + mkdir linux-arm64 + mkdir android-arm64_v8a + mkdir windows-amd64 + mkdir releases + - name: Build linux-amd64 shared library + run: | + cmake CMakeLists.txt + cmake --build . --config Release + cp build/libpow_links.so linux-amd64/libpow_links.so + - name: Cleanup action + run: rm -rf CMakeFiles/ CMakeCache.txt build/* + - name: Build linux-arm64 shared library + run: | + cmake CMakeLists.txt -DCMAKE_TOOLCHAIN_FILE=aarch64-linux-gnu.cmake + cmake --build . --config Release + cp build/libpow_links.so linux-arm64/libpow_links.so + - name: Cleanup action + run: rm -rf CMakeFiles/ CMakeCache.txt build/* + - name: Setup Android NDK + run: | + wget -q https://dl.google.com/android/repository/android-ndk-r25-linux.zip + unzip -q android-ndk-r25-linux.zip + - name: Build android-arm64_v8a shared library + run: | + cmake CMakeLists.txt -DCMAKE_SYSTEM_NAME=Android -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_ANDROID_NDK=/home/runner/work/znn-pow-links-cpp/znn-pow-links-cpp/android-ndk-r25 -DCMAKE_ANDROID_STL_TYPE=c++_shared + cmake --build . --config Release + cp build/libpow_links.so android-arm64_v8a/libpow_links.so + - name: Cleanup action + run: rm -rf CMakeFiles/ CMakeCache.txt build/* + - name: Build windows-amd64 dynamic library + run: | + cmake CMakeLists.txt -DCMAKE_TOOLCHAIN_FILE=mingw-w64-x86_64.cmake + cmake --build . --config Release + cp build/libpow_links.dll windows-amd64/libpow_links.dll + cp build/generator.exe windows-amd64/generator.exe + - name: Archive files + run: | + zip -jr libpow_links-linux-amd64.zip linux-amd64/* + zip -jr libpow_links-linux-arm64.zip linux-arm64/* + zip -jr libpow_links-android-arm64_v8a.zip android-arm64_v8a/* + zip -jr libpow_links-windows-amd64.zip windows-amd64/* + - name: Copy archived files to releases + run: cp libpow_links-linux-amd64.zip libpow_links-linux-arm64.zip libpow_links-android-arm64_v8a.zip libpow_links-windows-amd64.zip releases/ + - uses: actions/upload-artifact@v3 + with: + name: linux-artifacts + path: releases/ + make-release: + needs: [build-macos, build-linux] + runs-on: ubuntu-20.04 + steps: + - uses: actions/download-artifact@v3 + with: + name: macos-artifacts + - uses: actions/download-artifact@v3 + with: + name: linux-artifacts + - name: Prepare releases directory + run: | + mkdir releases + cp pow_links.xcframework.zip libpow_links-darwin-universal.zip libpow_links-wasm.zip libpow_links-linux-amd64.zip libpow_links-linux-arm64.zip libpow_links-android-arm64_v8a.zip libpow_links-windows-amd64.zip releases/ + - name: Generate checksums + run: | + cd releases + echo $(sha256sum *) >> SHA256CHECKSUMS.txt + - name: Upload files to a GitHub release + uses: svenstaro/upload-release-action@2.3.0 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: releases/* + tag: v0.0.1-alpha + file_glob: true + overwrite: true + body: "" diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d7d2be..55543e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,47 @@ -SET(CMAKE_EXPORT_COMPILE_COMMANDS ON) +cmake_minimum_required(VERSION 3.14) + project(pow_links) -cmake_minimum_required(VERSION 3.2) +enable_language(CXX) -# fetch submodules execute_process ( COMMAND bash -c "git submodule init && git submodule update && cd SHA3IUF && git checkout e909ac7791ac4335eb4382332ef56eb021dde482" ) -# compile options +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD 17) +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") +set(CMAKE_CXX_FLAGS "-Wall -static -static-libstdc++ -O3") +set(CMAKE_C_FLAGS "-Wall -static -static-libgcc -O3") +else() set(CMAKE_CXX_FLAGS "-Wall -static-libstdc++ -O3") set(CMAKE_C_FLAGS "-Wall -static-libgcc -O3") +endif() + set(SOURCE_DIR "src/") -# generate in build/ set(LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build") set(BIN_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_PATH}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_PATH}) -# library -add_library(pow_links SHARED src/bridge.cpp src/bridge.def src/pow_links.cpp SHA3IUF/sha3.c) -add_executable(generator src/generator.cpp src/pow_links.cpp SHA3IUF/sha3.c) +set(public_headers "${CMAKE_CURRENT_SOURCE_DIR}/src/bridge.hpp") + +set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE) + +add_library(pow_links SHARED src/bridge.hpp src/bridge.cpp src/bridge.def src/pow_links.cpp SHA3IUF/sha3.c) + +if(CMAKE_SYSTEM MATCHES Windows OR CMAKE_SYSTEM MATCHES Linux OR CMAKE_SYSTEM MATCHES Darwin) + add_executable(generator src/generator.cpp src/pow_links.cpp SHA3IUF/sha3.c) +endif() + +set_target_properties(pow_links PROPERTIES + FRAMEWORK TRUE + FRAMEWORK_VERSION C + MACOSX_FRAMEWORK_IDENTIFIER network.zenon.powlinks + VERSION 0.0.1 + SOVERSION 1.0.0 + PUBLIC_HEADER "${public_headers}" +) \ No newline at end of file diff --git a/aarch64-linux-gnu.cmake b/aarch64-linux-gnu.cmake new file mode 100644 index 0000000..c9589d8 --- /dev/null +++ b/aarch64-linux-gnu.cmake @@ -0,0 +1,9 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) +set(TOOLCHAIN_PREFIX aarch64-linux-gnu) +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) \ No newline at end of file diff --git a/mingw-w64-x86_64.cmake b/mingw-w64-x86_64.cmake new file mode 100644 index 0000000..98269b6 --- /dev/null +++ b/mingw-w64-x86_64.cmake @@ -0,0 +1,10 @@ +set(CMAKE_SYSTEM_NAME Windows) +set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran) +set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) \ No newline at end of file From e0e6e73d15f5005333f63baa7b4ccb13f5243f75 Mon Sep 17 00:00:00 2001 From: alienc0der <118136375+alienc0der@users.noreply.github.com> Date: Tue, 28 Mar 2023 12:28:36 +0300 Subject: [PATCH 2/3] cicd: update upload-release-action dependency --- .github/workflows/znn_pow_links_builder.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/znn_pow_links_builder.yml b/.github/workflows/znn_pow_links_builder.yml index c136ec1..4caccdc 100644 --- a/.github/workflows/znn_pow_links_builder.yml +++ b/.github/workflows/znn_pow_links_builder.yml @@ -146,7 +146,7 @@ jobs: cd releases echo $(sha256sum *) >> SHA256CHECKSUMS.txt - name: Upload files to a GitHub release - uses: svenstaro/upload-release-action@2.3.0 + uses: svenstaro/upload-release-action@2.5.0 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: releases/* From 4e3510db67a848784c42b522706237800529face Mon Sep 17 00:00:00 2001 From: alienc0der <118136375+alienc0der@users.noreply.github.com> Date: Tue, 28 Mar 2023 12:54:59 +0300 Subject: [PATCH 3/3] cicd: added bug report --- .github/workflows/ISSUE_TEMPLATE/bug.yml | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/ISSUE_TEMPLATE/bug.yml diff --git a/.github/workflows/ISSUE_TEMPLATE/bug.yml b/.github/workflows/ISSUE_TEMPLATE/bug.yml new file mode 100644 index 0000000..bc546ff --- /dev/null +++ b/.github/workflows/ISSUE_TEMPLATE/bug.yml @@ -0,0 +1,29 @@ +--- +name: Report a bug +about: Something with znn-pow-links is not working as expected +title: '' +labels: 'type:bug' +assignees: '' +--- + +#### System information + +OS & Version: Windows/Linux/OSX +Commit hash : (if `develop`) + +#### Expected behaviour + + +#### Actual behaviour + + +#### Steps to reproduce the behaviour + + +#### Backtrace + +```` +[backtrace] +```` + +When submitting logs: please submit them as text and not screenshots. \ No newline at end of file