From 90e5a7f137a489ca3c76e7d3b499890c4f7eddb1 Mon Sep 17 00:00:00 2001 From: Jason Dellaluce Date: Mon, 10 Jul 2023 16:51:30 +0000 Subject: [PATCH] refactor(ci): build and upload WASM packages Signed-off-by: Jason Dellaluce --- .github/workflows/ci.yml | 33 ----------- .../workflows/reusable_build_packages.yaml | 56 +++++++++++++++++++ CMakeLists.txt | 6 +- cmake/modules/CPackConfig.cmake | 6 +- 4 files changed, 66 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7d489ad2d4..4a2e24461ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,39 +33,6 @@ jobs: static: ${{ matrix.static != '' && true || false }} version: ${{ needs.fetch-version.outputs.version }} - build-falco-emscripten: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Install deps - run: | - sudo apt update - sudo DEBIAN_FRONTEND=noninteractive apt install libjq-dev libelf-dev libyaml-cpp-dev cmake build-essential git emscripten -y - - - name: Emscripten build - run: | - mkdir -p build - pushd build - emcmake cmake -DBUILD_FALCO_UNIT_TESTS=On .. - emmake make falco falco_unit_tests - popd - - - name: Select node version - uses: actions/setup-node@v3 - with: - node-version: 14 - - - - name: Run unit Tests - run: | - pushd build - node ./unit_tests/falco_unit_tests.js - popd - build-dev: strategy: fail-fast: false diff --git a/.github/workflows/reusable_build_packages.yaml b/.github/workflows/reusable_build_packages.yaml index 9ff23a9a378..0f56d0cb561 100644 --- a/.github/workflows/reusable_build_packages.yaml +++ b/.github/workflows/reusable_build_packages.yaml @@ -158,3 +158,59 @@ jobs: name: falco-${{ inputs.version }}-static-x86_64.tar.gz path: | ${{ github.workspace }}/build/falco-${{ inputs.version }}-static-x86_64.tar.gz + + build-wasm-package: + if: ${{ inputs.arch == 'x86_64' }} + runs-on: ubuntu-latest + steps: + # Always install deps before invoking checkout action, to properly perform a full clone. + - name: Install build dependencies + run: | + sudo apt update + sudo DEBIAN_FRONTEND=noninteractive apt install cmake build-essential git emscripten -y + + - name: Select node version + uses: actions/setup-node@v3 + with: + node-version: 14 + + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Prepare project + run: | + mkdir build && cd build + emcmake cmake \ + -DBUILD_BPF=Off \ + -DBUILD_DRIVER=Off \ + -DBUILD_LIBSCAP_MODERN_BPF=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DUSE_BUNDLED_DEPS=On \ + -DFALCO_ETC_DIR=/etc/falco \ + -DBUILD_FALCO_UNIT_TESTS=On \ + -DFALCO_VERSION=${{ inputs.version }} \ + .. + + - name: Build project + run: | + cd build + emmake make -j6 all + + - name: Run unit Tests + run: | + cd build + node ./unit_tests/falco_unit_tests.js + + - name: Build packages + run: | + cd build + emmake make -j6 package + + - name: Upload Falco WASM package + uses: actions/upload-artifact@v3 + with: + name: falco-${{ inputs.version }}-wasm.tar.gz + path: | + ${{ github.workspace }}/build/falco-${{ inputs.version }}-wasm.tar.gz diff --git a/CMakeLists.txt b/CMakeLists.txt index a1707234e51..72ebfb949e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,11 @@ if(NOT DEFINED FALCO_ETC_DIR) endif() # This will be used to print the architecture for which Falco is compiled. -set(FALCO_TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR}) +if (EMSCRIPTEN) + set(FALCO_TARGET_ARCH "wasm") +else() + set(FALCO_TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR}) +endif() if(NOT FALCO_EXTRA_DEBUG_FLAGS) set(FALCO_EXTRA_DEBUG_FLAGS "-D_DEBUG") diff --git a/cmake/modules/CPackConfig.cmake b/cmake/modules/CPackConfig.cmake index 07a3de129a5..d444f7a10a3 100644 --- a/cmake/modules/CPackConfig.cmake +++ b/cmake/modules/CPackConfig.cmake @@ -20,10 +20,14 @@ set(CPACK_PACKAGE_VERSION "${FALCO_VERSION}") set(CPACK_PACKAGE_VERSION_MAJOR "${FALCO_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${FALCO_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_PATCH "${FALCO_VERSION_PATCH}") -set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_PROCESSOR}") set(CPACK_PROJECT_CONFIG_FILE "${PROJECT_SOURCE_DIR}/cmake/cpack/CMakeCPackOptions.cmake") set(CPACK_PACKAGE_RELOCATABLE "OFF") set(CPACK_STRIP_FILES "ON") +if (EMSCRIPTEN) + set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-wasm") +else() + set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_PROCESSOR}") +endif() # Built packages will include only the following components set(CPACK_INSTALL_CMAKE_PROJECTS