From 9fdeb9f573b8fccd67de4a1472ee4b5686bac9dc Mon Sep 17 00:00:00 2001 From: Andrew Bassett <43486400+apbassett@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:31:07 -0400 Subject: [PATCH] 21695: Fixes WASM debug build, packaging updates (#274) * Fixes issue where WASM debug build did not actually have debug information available * Adds `web` to `sENVIRONMENTS` linker flag * Removes quiet mode from CI/CD build step for future debugability * Splits build process into separate release/debug phases for WASM instead of shoehorning a debug build into the release build --------- Co-authored-by: howsohazard <143410553+howsohazard@users.noreply.github.com> Co-authored-by: Lance Gliser --- .github/workflows/build.yml | 593 +++++++++--------- .gitignore | 3 + .vscode/settings.json | 4 +- CMakeLists.txt | 11 +- CMakePresets.json | 15 + README.md | 10 +- build/cmake/custom_add_target.cmake | 39 +- build/cmake/global_compiler_flags.cmake | 17 +- src/Amalgam/Parser.cpp | 6 +- .../amlg_code/persist_module_test.amlg | 10 +- .../amlg_code/persist_module_test/psm.amlg | 10 +- .../amlg_code/persistent_tree_test_leaf.amlg | 10 +- test/wasm_test/README.md | 8 +- test/wasm_test/tests/wasm.test.cjs | 19 +- 14 files changed, 403 insertions(+), 352 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 64275039..3c51f1e5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,11 +15,10 @@ defaults: shell: bash jobs: - build-linux: runs-on: ubuntu-20.04 container: - image: ghcr.io/howsoai/amalgam-build-container-linux:1.0.0 + image: ghcr.io/howsoai/amalgam-build-container-linux:2.0.8 credentials: username: ${{ github.actor }} password: ${{ github.token }} @@ -28,52 +27,68 @@ jobs: preset: - arch: amd64 platform: linux + type: release - arch: arm64 platform: linux + type: release - arch: arm64_8a platform: linux + type: release + - arch: wasm64 + platform: unknown + type: release - arch: wasm64 platform: unknown + type: debug permissions: contents: write steps: - - uses: actions/checkout@v4 - - - name: Set build preset - run: | - PRESET=$(echo ${{ matrix.preset.arch }}-release-${{ matrix.preset.platform }}) - echo "PRESET=$(echo $PRESET)" >> $GITHUB_ENV - echo "Build preset: $PRESET" - - - name: CMake Configure - run: AMALGAM_BUILD_VERSION=${{ inputs.version }} cmake --preset $PRESET - - - name: CMake Build - run: cmake --build --preset $PRESET -- --quiet - - - name: CMake Test - run: cmake --build --preset $PRESET --target test - - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v4 - with: - name: test-results-${{ matrix.preset.platform }}-${{ matrix.preset.arch }} - path: ./out/test/* - - - name: CMake Install - run: cmake --build --preset $PRESET --target install - - - name: CMake Package - run: cmake --build --preset $PRESET --target package - - - name: Upload Artifact - uses: actions/upload-artifact@v4 - with: - name: amalgam-${{ inputs.version }}-${{ matrix.preset.platform }}-${{ matrix.preset.arch }} - path: ./out/package/amalgam-*.tar.gz - if-no-files-found: error + - uses: actions/checkout@v4 + + - name: Set build preset + run: | + PRESET=$(echo ${{ matrix.preset.arch }}-${{ matrix.preset.type }}-${{ matrix.preset.platform }}) + echo "PRESET=$(echo $PRESET)" >> $GITHUB_ENV + echo "Build preset: $PRESET" + # Print glibc version + ldd --version + + - name: CMake Configure + run: AMALGAM_BUILD_VERSION=${{ inputs.version }} cmake --preset $PRESET + + - name: CMake Build + run: cmake --build --preset $PRESET -- + + - name: CMake Test + run: cmake --build --preset $PRESET --target test + + - name: Print/copy out.txt + if: always() + continue-on-error: true + run: | + tail -n 20 src/Amalgam/out.txt + cp src/Amalgam/out.txt ./out/test/ + + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results-${{ matrix.preset.type }}-${{ matrix.preset.platform }}-${{ matrix.preset.arch }} + path: ./out/test/* + + - name: CMake Install + run: cmake --build --preset $PRESET --target install + + - name: CMake Package + run: cmake --build --preset $PRESET --target package + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: amalgam-${{ inputs.version }}-${{ matrix.preset.type }}-${{ matrix.preset.platform }}-${{ matrix.preset.arch }} + path: ./out/package/amalgam-*.tar.gz + if-no-files-found: error build-macos: runs-on: macos-13 @@ -81,75 +96,75 @@ jobs: matrix: preset: - arch: amd64 - build: release + type: release platform: macos - arch: arm64 - build: release + type: release platform: macos permissions: contents: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Set build preset + run: | + PRESET=$(echo ${{ matrix.preset.arch }}-${{ matrix.preset.type }}-${{ matrix.preset.platform }}) + echo "PRESET=$(echo $PRESET)" >> $GITHUB_ENV + echo "Build preset: $PRESET" + + - name: Install build dependencies + run: | + echo "Python version: $(python --version)" + echo "Brew version: $(brew --version)" + echo "Brew python installs: $(brew list | grep python)" + if [ "${{ matrix.preset.arch }}" = "arm64" ]; then + brew unlink python@3.11 + brew unlink python@3.12 + brew link --force --overwrite python@3.12 + + brew cleanup -s + rm -rf `brew --cache` + brew fetch --force --bottle-tag=arm64_ventura libomp + brew install `brew --cache --bottle-tag=arm64_ventura libomp` || brew link --overwrite python@3.12 + else + brew install libomp + fi + brew list --versions libomp + brew install ninja - - uses: actions/setup-python@v5 - with: - python-version: '3.12' + - name: CMake Configure + run: AMALGAM_BUILD_VERSION=${{ inputs.version }} cmake --preset $PRESET - - name: Set build preset - run: | - PRESET=$(echo ${{ matrix.preset.arch }}-release-${{ matrix.preset.platform }}) - echo "PRESET=$(echo $PRESET)" >> $GITHUB_ENV - echo "Build preset: $PRESET" + - name: CMake Build + run: cmake --build --preset $PRESET -- --quiet - - name: Install build dependencies - run: | - echo "Python version: $(python --version)" - echo "Brew version: $(brew --version)" - echo "Brew python installs: $(brew list | grep python)" - if [ "${{ matrix.preset.arch }}" = "arm64" ]; then - brew unlink python@3.11 - brew unlink python@3.12 - brew link --force --overwrite python@3.12 - - brew cleanup -s - rm -rf `brew --cache` - brew fetch --force --bottle-tag=arm64_ventura libomp - brew install `brew --cache --bottle-tag=arm64_ventura libomp` || brew link --overwrite python@3.12 - else - brew install libomp - fi - brew list --versions libomp - brew install ninja - - - name: CMake Configure - run: AMALGAM_BUILD_VERSION=${{ inputs.version }} cmake --preset $PRESET - - - name: CMake Build - run: cmake --build --preset $PRESET -- --quiet - - - name: CMake Test - run: cmake --build --preset $PRESET --target test - - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v4 - with: - name: test-results-${{ matrix.preset.platform }}-${{ matrix.preset.arch }} - path: ./out/test/* + - name: CMake Test + run: cmake --build --preset $PRESET --target test - - name: CMake Install - run: cmake --build --preset $PRESET --target install + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results-${{ matrix.preset.type }}-${{ matrix.preset.platform }}-${{ matrix.preset.arch }} + path: ./out/test/* - - name: CMake Package - run: cmake --build --preset $PRESET --target package + - name: CMake Install + run: cmake --build --preset $PRESET --target install - - name: Upload Artifact - uses: actions/upload-artifact@v4 - with: - name: amalgam-${{ inputs.version }}-darwin-${{ matrix.preset.arch }} - path: ./out/package/amalgam-*.tar.gz - if-no-files-found: error + - name: CMake Package + run: cmake --build --preset $PRESET --target package + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: amalgam-${{ inputs.version }}-${{ matrix.preset.type }}-darwin-${{ matrix.preset.arch }} + path: ./out/package/amalgam-*.tar.gz + if-no-files-found: error build-windows: runs-on: windows-2022 @@ -157,90 +172,90 @@ jobs: matrix: preset: - arch: amd64 - build: release + type: release platform: windows permissions: contents: write steps: - - uses: actions/checkout@v4 - - - name: Set build preset - run: | - PRESET=$(echo ${{ matrix.preset.arch }}-release-${{ matrix.preset.platform }}) - echo "PRESET=$(echo $PRESET)" >> $GITHUB_ENV - echo "Build preset: $PRESET" - - - name: Enable developer commandline tools - uses: ilammy/msvc-dev-cmd@v1 - - - name: Download tz data - shell: pwsh - run: ./build/powershell/Download-Tzdata.ps1 - - - name: Install build dependencies - run: | - max_retries=2 - count=0 - until choco upgrade ninja; do - ((count++)) - echo "Failed to install Ninja (attempt $count of $max_retries)" - if [ "$count" -ge "$max_retries" ]; then - echo "Reached maximum number of retries" - exit 1 - fi - done + - uses: actions/checkout@v4 + + - name: Set build preset + run: | + PRESET=$(echo ${{ matrix.preset.arch }}-${{ matrix.preset.type }}-${{ matrix.preset.platform }}) + echo "PRESET=$(echo $PRESET)" >> $GITHUB_ENV + echo "Build preset: $PRESET" + + - name: Enable developer commandline tools + uses: ilammy/msvc-dev-cmd@v1 + + - name: Download tz data + shell: pwsh + run: ./build/powershell/Download-Tzdata.ps1 + + - name: Install build dependencies + run: | + max_retries=2 + count=0 + until choco upgrade ninja; do + ((count++)) + echo "Failed to install Ninja (attempt $count of $max_retries)" + if [ "$count" -ge "$max_retries" ]; then + echo "Reached maximum number of retries" + exit 1 + fi + done - - name: CMake Configure - run: AMALGAM_BUILD_VERSION=${{ inputs.version }} cmake --preset $PRESET + - name: CMake Configure + run: AMALGAM_BUILD_VERSION=${{ inputs.version }} cmake --preset $PRESET - - name: CMake Build - run: cmake --build --preset $PRESET -- --quiet + - name: CMake Build + run: cmake --build --preset $PRESET -- --quiet - - name: CMake Test - run: cmake --build --preset $PRESET --target test + - name: CMake Test + run: cmake --build --preset $PRESET --target test - - name: Upload Test Results - if: always() - uses: actions/upload-artifact@v4 - with: - name: test-results-${{ matrix.preset.platform }}-${{ matrix.preset.arch }} - path: ./out/test/* + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-results-${{ matrix.preset.type }}-${{ matrix.preset.platform }}-${{ matrix.preset.arch }} + path: ./out/test/* - - name: CMake Install - run: cmake --build --preset $PRESET --target install + - name: CMake Install + run: cmake --build --preset $PRESET --target install - - name: CMake Package - run: cmake --build --preset $PRESET --target package + - name: CMake Package + run: cmake --build --preset $PRESET --target package - - name: Upload Artifact - uses: actions/upload-artifact@v4 - with: - name: amalgam-${{ inputs.version }}-${{ matrix.preset.platform }}-${{ matrix.preset.arch }} - path: ./out/package/amalgam-*.tar.gz - if-no-files-found: error + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: amalgam-${{ inputs.version }}-${{ matrix.preset.type }}-${{ matrix.preset.platform }}-${{ matrix.preset.arch }} + path: ./out/package/amalgam-*.tar.gz + if-no-files-found: error smoke-test-linux-amd64: - needs: ['build-linux'] - runs-on: ubuntu-latest + needs: ["build-linux"] + runs-on: ubuntu-24.04 steps: - - name: Download Artifact - uses: actions/download-artifact@v4 - with: - name: amalgam-${{ inputs.version }}-linux-amd64 - - - name: Extract Amalgam - run: | - mkdir ./amalgam - tar -xvf ./amalgam-${{ inputs.version }}-linux-amd64.tar.gz -C ./amalgam - - - name: Smoke test - run: | - set -e - cd ./amalgam/bin - for f in *; do - echo -n "$f: " && "./$f" --version - done + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: amalgam-${{ inputs.version }}-release-linux-amd64 + + - name: Extract Amalgam + run: | + mkdir ./amalgam + tar -xvf ./amalgam-${{ inputs.version }}-linux-amd64.tar.gz -C ./amalgam + + - name: Smoke test + run: | + set -e + cd ./amalgam/bin + for f in *; do + echo -n "$f: " && "./$f" --version + done smoke-test-linux-arm64: needs: ['build-linux'] @@ -249,7 +264,7 @@ jobs: - name: Download Artifact uses: actions/download-artifact@v4 with: - name: amalgam-${{ inputs.version }}-linux-arm64 + name: amalgam-${{ inputs.version }}-release-linux-arm64 - name: Extract Amalgam run: | @@ -276,7 +291,7 @@ jobs: - name: Download Artifact uses: actions/download-artifact@v4 with: - name: amalgam-${{ inputs.version }}-linux-arm64_8a + name: amalgam-${{ inputs.version }}-release-linux-arm64_8a - name: Extract Amalgam run: | @@ -299,144 +314,145 @@ jobs: # Uses GitHub default macos runner (amd64) # Note: these runners have the potential to not have AVX+ instructions so only run NoAVX binaries smoke-test-macos-amd64: - needs: ['build-macos'] + needs: ["build-macos"] runs-on: macos-latest steps: - - name: Download Artifact - uses: actions/download-artifact@v4 - with: - name: amalgam-${{ inputs.version }}-darwin-amd64 - - - name: Extract Amalgam - run: | - mkdir ./amalgam - tar -xvf ./amalgam-${{ inputs.version }}-darwin-amd64.tar.gz -C ./amalgam - - - name: Smoke test - run: | - set -e - cd ./amalgam/bin - for f in *noavx*; do - echo -n "$f: " && "./$f" --version - done + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: amalgam-${{ inputs.version }}-release-darwin-amd64 + + - name: Extract Amalgam + run: | + mkdir ./amalgam + tar -xvf ./amalgam-${{ inputs.version }}-darwin-amd64.tar.gz -C ./amalgam + + - name: Smoke test + run: | + set -e + cd ./amalgam/bin + for f in *noavx*; do + echo -n "$f: " && "./$f" --version + done # Uses GitHub large macos runner (amd64) smoke-test-macos-amd64-large: - needs: ['build-macos'] + needs: ["build-macos"] runs-on: macos-latest-large steps: - - name: Download Artifact - uses: actions/download-artifact@v4 - with: - name: amalgam-${{ inputs.version }}-darwin-amd64 - - - name: Extract Amalgam - run: | - mkdir ./amalgam - tar -xvf ./amalgam-${{ inputs.version }}-darwin-amd64.tar.gz -C ./amalgam - - - name: Smoke test - run: | - set -e - cd ./amalgam/bin - for f in *; do - echo -n "$f: " && "./$f" --version - done + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: amalgam-${{ inputs.version }}-release-darwin-amd64 + + - name: Extract Amalgam + run: | + mkdir ./amalgam + tar -xvf ./amalgam-${{ inputs.version }}-darwin-amd64.tar.gz -C ./amalgam + + - name: Smoke test + run: | + set -e + cd ./amalgam/bin + for f in *; do + echo -n "$f: " && "./$f" --version + done # Uses macOS arm64 xlarge runner (arm64) but execute amd64 binaries # Notes: # 1) this is supported by Apple through emulator Rossetta 2 # 2) Rossetta 2 does support AVX+ instructions so only run noavx binaries smoke-test-macos-amd64-on-arm64: - needs: ['build-macos'] + needs: ["build-macos"] runs-on: macos-latest-xlarge steps: - - name: Download Artifact - uses: actions/download-artifact@v4 - with: - name: amalgam-${{ inputs.version }}-darwin-amd64 - - - name: Extract Amalgam - run: | - mkdir ./amalgam - tar -xvf ./amalgam-${{ inputs.version }}-darwin-amd64.tar.gz -C ./amalgam - - - name: Smoke test - run: | - set -e - cd ./amalgam/bin - for f in *noavx*; do - echo -n "$f: " && "./$f" --version - done + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: amalgam-${{ inputs.version }}-release-darwin-amd64 + + - name: Extract Amalgam + run: | + mkdir ./amalgam + tar -xvf ./amalgam-${{ inputs.version }}-darwin-amd64.tar.gz -C ./amalgam + + - name: Smoke test + run: | + set -e + cd ./amalgam/bin + for f in *noavx*; do + echo -n "$f: " && "./$f" --version + done # Uses macOS arm64 xlarge runner (arm64) smoke-test-macos-arm64: - needs: ['build-macos'] + needs: ["build-macos"] runs-on: macos-latest-xlarge steps: - - name: Download Artifact - uses: actions/download-artifact@v4 - with: - name: amalgam-${{ inputs.version }}-darwin-arm64 - - - name: Extract Amalgam - run: | - mkdir ./amalgam - tar -xvf ./amalgam-${{ inputs.version }}-darwin-arm64.tar.gz -C ./amalgam - - - name: Smoke test - run: | - set -e - cd ./amalgam/bin - for f in *; do - echo -n "$f: " && "./$f" --version - done + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: amalgam-${{ inputs.version }}-release-darwin-arm64 + + - name: Extract Amalgam + run: | + mkdir ./amalgam + tar -xvf ./amalgam-${{ inputs.version }}-darwin-arm64.tar.gz -C ./amalgam + + - name: Smoke test + run: | + set -e + cd ./amalgam/bin + for f in *; do + echo -n "$f: " && "./$f" --version + done smoke-test-windows-amd64: - needs: ['build-windows'] + needs: ["build-windows"] runs-on: windows-latest steps: - - name: Download Artifact - uses: actions/download-artifact@v4 - with: - name: amalgam-${{ inputs.version }}-windows-amd64 - - - name: Extract Amalgam - run: | - mkdir ./amalgam - tar -xvf ./amalgam-${{ inputs.version }}-windows-amd64.tar.gz -C ./amalgam - - - name: Smoke test - run: | - set -e - cd ./amalgam/bin - for f in *; do - echo -n "$f: " && "./$f" --version - done + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: amalgam-${{ inputs.version }}-release-windows-amd64 + + - name: Extract Amalgam + run: | + mkdir ./amalgam + tar -xvf ./amalgam-${{ inputs.version }}-windows-amd64.tar.gz -C ./amalgam + + - name: Smoke test + run: | + set -e + cd ./amalgam/bin + for f in *; do + echo -n "$f: " && "./$f" --version + done smoke-test-wasm64: - needs: ['build-linux'] + needs: ["build-linux"] runs-on: ubuntu-latest container: node:18-bullseye-slim steps: - - uses: actions/checkout@v4 - - - name: Download Artifact - uses: actions/download-artifact@v4 - with: - name: amalgam-${{ inputs.version }}-unknown-wasm64 - - - name: Extract Amalgam - run: | - mkdir ./amalgam - tar -xvf ./amalgam-${{ inputs.version }}-wasm64.tar.gz -C ./amalgam - - - name: Smoke test - run: | - export AMALGAM_WASM_DIR=$(pwd)/amalgam/bin - cd test/wasm_test - npm install - npm run test + - uses: actions/checkout@v4 + + - name: Download Artifact + uses: actions/download-artifact@v4 + with: + name: amalgam-${{ inputs.version }}-release-unknown-wasm64 + + - name: Extract Amalgam + run: | + mkdir ./amalgam + tar -xvf ./amalgam-${{ inputs.version }}-wasm64.tar.gz -C ./amalgam + + - name: Smoke test + run: | + export AMALGAM_WASM_DIR=$(pwd)/amalgam/bin + export AMALGAM_BASE_FILE=amalgam-st + cd test/wasm_test + npm install + npm run test generate-changelog: if: inputs.build-type == 'release' @@ -468,18 +484,17 @@ jobs: - generate-changelog runs-on: ubuntu-latest steps: - - - name: Download Artifacts - uses: actions/download-artifact@v4 - - - name: Create Release - uses: ncipollo/release-action@v1 - with: - tag: ${{ inputs.version }} - commit: ${{ github.sha }} - name: "Amalgam ${{ inputs.version }}" - artifactErrorsFailBuild: true - body: ${{ needs.generate-changelog.outputs.changelog }} - makeLatest: legacy - artifacts: amalgam-*/amalgam-*.tar.gz - artifactContentType: application/gzip \ No newline at end of file + - name: Download Artifacts + uses: actions/download-artifact@v4 + + - name: Create Release + uses: ncipollo/release-action@v1 + with: + tag: ${{ inputs.version }} + commit: ${{ github.sha }} + name: "Amalgam ${{ inputs.version }}" + artifactErrorsFailBuild: true + body: ${{ needs.generate-changelog.outputs.changelog }} + makeLatest: legacy + artifacts: amalgam-*/amalgam-*.tar.gz + artifactContentType: application/gzip diff --git a/.gitignore b/.gitignore index ff138bc8..29c25b32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ ## Use glob syntax syntax: glob +## Local files +/local + ## Files created by build src/Amalgam/AmalgamVersion.h diff --git a/.vscode/settings.json b/.vscode/settings.json index c87fd0ee..60d2427e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,4 @@ { - "cSpell.words": ["KullbackLeibler"], - "files.trimTrailingWhitespace": false, + "cSpell.words": ["amlg", "cwrap", "KullbackLeibler"], + "files.trimTrailingWhitespace": false } diff --git a/CMakeLists.txt b/CMakeLists.txt index ea74683c..dd54b0f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -313,15 +313,8 @@ if(IS_LINUX AND IS_AMD64) SOURCE ${AMALGAM_LIB_ONLY_SOURCE} ${COMMON_SOURCE_THREADS} IDE_FOLDER "OtherBuildTargets") endif() -# WASM single-threaded debug target (amalgam-st-debug) -if(IS_WASM) - add_compiled_target(AUTO_NAME TYPE "objlib" USE_DEBUG - SOURCE ${COMMON_SOURCE} IDE_FOLDER "OtherBuildTargets") - add_compiled_target(AUTO_NAME TYPE "app" USE_DEBUG - SOURCE ${COMMON_SOURCE} APP_ONLY_SOURCE ${AMALGAM_APP_ONLY_SOURCE}) - add_compiled_target(AUTO_NAME TYPE "sharedlib" USE_DEBUG - SOURCE ${AMALGAM_LIB_ONLY_SOURCE} ${COMMON_SOURCE} IDE_FOLDER "OtherBuildTargets") -endif() +# Print the current build type +message(STATUS "Current build type: ${CMAKE_BUILD_TYPE}") # # Additional artifacts/test/etc diff --git a/CMakePresets.json b/CMakePresets.json index 75052c40..cb1e68f6 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -272,6 +272,16 @@ "CMAKE_TRY_COMPILE_TARGET_TYPE": "STATIC_LIBRARY" } }, + { + "name": "wasm64-debug-unknown", + "description": "emcc for wasm64 (debug)", + "inherits": [ "base", "wasm64", "debug", "emcc" ], + "cacheVariables": { + "CMAKE_OSX_ARCHITECTURES": "", + "CMAKE_CXX_COMPILER_TARGET": "wasm64-unknown-emscripten", + "CMAKE_TRY_COMPILE_TARGET_TYPE": "STATIC_LIBRARY" + } + }, { "name": "amd64-debug-macos", @@ -356,6 +366,11 @@ "configurePreset": "wasm64-release-unknown", "description": "wasm64 release build" }, + { + "name": "wasm64-debug-unknown", + "configurePreset": "wasm64-debug-unknown", + "description": "wasm64 debug build" + }, { "name": "amd64-debug-macos", "configurePreset": "amd64-debug-macos", diff --git a/README.md b/README.md index f5d4c135..cb5fb895 100644 --- a/README.md +++ b/README.md @@ -114,16 +114,16 @@ Pre-built binaries use CMake+Ninja for CI/CD. See [PR workflow](.github/workflow Though Amalgam is intended to support any C++17 compliant compiler, the current specific tool and OS versions used are: -* CMake 3.23 -* Ninja 1.11 +* CMake 3.30 +* Ninja 1.10 * Windows: * Visual Studio 2022 v143 * Linux: * Ubuntu 20.04, gcc-10 * macOS (Darwin): - * macOS 12, AppleClang 14.0 + * macOS 13, AppleClang 15.0 * WASM: - * Ubuntu 20.04, emscripten 3.1.32 + * Ubuntu 20.04, emscripten 3.1.67 #### Runtime Requirements @@ -148,7 +148,7 @@ Running the pre-built interpreter has specific runtime requirements per platform ##### Linux -* glibc 2.29 or later +* glibc 2.31 or later * Arch: amd64 or arm64 * Specific arm64 builds: `armv8-a+simd` & `armv8.2-a+simd+rcpc` diff --git a/build/cmake/custom_add_target.cmake b/build/cmake/custom_add_target.cmake index 9dae84dc..1eb56cd2 100644 --- a/build/cmake/custom_add_target.cmake +++ b/build/cmake/custom_add_target.cmake @@ -10,7 +10,7 @@ set(ALL_OBJLIB_TARGETS) set(ALL_SHAREDLIB_TARGETS) set(ALL_APP_TARGETS) function(add_compiled_target) - set(options AUTO_NAME USE_THREADS USE_OPENMP USE_PGC USE_AFMI_MT USE_AFMI_ST USE_DEBUG USE_ADVANCED_ARCH_INTRINSICS NO_INSTALL) + set(options AUTO_NAME USE_THREADS USE_OPENMP USE_PGC USE_AFMI_MT USE_AFMI_ST USE_ADVANCED_ARCH_INTRINSICS NO_INSTALL) set(oneValueArgs NAME TYPE OUTPUT_NAME_BASE IDE_FOLDER) set(multiValueArgs INCLUDE_DIRS COMPILER_DEFINES LINK_LIBRARIES SOURCE APP_ONLY_SOURCE) cmake_parse_arguments(args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -29,7 +29,6 @@ function(add_compiled_target) set(USE_PGC ${args_USE_PGC}) set(USE_AFMI_MT ${args_USE_AFMI_MT}) set(USE_AFMI_ST ${args_USE_AFMI_ST}) - set(USE_DEBUG ${args_USE_DEBUG}) set(USE_ADVANCED_ARCH_INTRINSICS ${args_USE_ADVANCED_ARCH_INTRINSICS}) set(NO_INSTALL ${args_NO_INSTALL}) @@ -93,7 +92,7 @@ function(add_compiled_target) string(APPEND TARGET_NAME_BASE "-mt-afmi") elseif(USE_AFMI_ST) string(APPEND TARGET_NAME_BASE "-st-afmi") - elseif(USE_DEBUG) + elseif(IS_WASM AND CMAKE_BUILD_TYPE STREQUAL "Debug") string(APPEND TARGET_NAME_BASE "-st-debug") else() string(APPEND TARGET_NAME_BASE "-st") @@ -251,15 +250,6 @@ function(add_compiled_target) target_compile_options(${TARGET_NAME} PUBLIC -O1) endif() - if(USE_DEBUG) - target_compile_options(${TARGET_NAME} PUBLIC -g -O1) - target_compile_definitions(${TARGET_NAME} PUBLIC DEBUG_BUILD) - if (IS_WASM) - # Enabling WASM assertions can greatly assist in the debugging process - string(APPEND CMAKE_EXE_LINKER_FLAGS " -sASSERTIONS=2") - endif() - endif() - # Advanced arch intrinsics: if(USE_ADVANCED_ARCH_INTRINSICS AND NOT IS_WASM) if (IS_AMD64) @@ -290,13 +280,24 @@ function(add_compiled_target) # Extra files to install for WASM if(IS_WASM) - install( - FILES - "$/$.data" - "$/$.wasm" - DESTINATION "${INSTALL_DIR}" - PERMISSIONS ${DEFAULT_INSTALL_PERMISSIONS} - ) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + install( + FILES + "$/$.data" + "$/$.wasm" + "$/$.wasm.debug.wasm" + DESTINATION "${INSTALL_DIR}" + PERMISSIONS ${DEFAULT_INSTALL_PERMISSIONS} + ) + else() + install( + FILES + "$/$.data" + "$/$.wasm" + DESTINATION "${INSTALL_DIR}" + PERMISSIONS ${DEFAULT_INSTALL_PERMISSIONS} + ) + endif() file(MAKE_DIRECTORY "out/config") set(WASM_DECLARATION_FILE "out/config/${TARGET_NAME_BASE}.d.cts") file(COPY_FILE "build/wasm/amalgam-wasm.d.cts" "${WASM_DECLARATION_FILE}" ONLY_IF_DIFFERENT) diff --git a/build/cmake/global_compiler_flags.cmake b/build/cmake/global_compiler_flags.cmake index 3be46417..83c3795d 100644 --- a/build/cmake/global_compiler_flags.cmake +++ b/build/cmake/global_compiler_flags.cmake @@ -75,7 +75,13 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" S # TODO 1599: WASM support is experimental, these flags will be cleaned up and auto-generated where possible if(IS_WASM) string(APPEND CMAKE_CXX_FLAGS " -sMEMORY64=2 -Wno-experimental -DSIMDJSON_NO_PORTABILITY_WARNING") - string(APPEND CMAKE_EXE_LINKER_FLAGS " -sINVOKE_RUN=0 -sALLOW_MEMORY_GROWTH=1 -sINITIAL_MEMORY=65536000 -sMEMORY_GROWTH_GEOMETRIC_STEP=0.50 -sMODULARIZE=1 -sEXPORT_NAME=AmalgamRuntime -sENVIRONMENT=worker,node -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,FS,setValue,getValue,UTF8ToString -sEXPORTED_FUNCTIONS=_malloc,_free,_LoadEntity,_CloneEntity,_VerifyEntity,_StoreEntity,_ExecuteEntity,_ExecuteEntityJsonPtr,_DestroyEntity,_GetEntities,_SetRandomSeed,_SetJSONToLabel,_GetJSONPtrFromLabel,_SetSBFDataStoreEnabled,_IsSBFDataStoreEnabled,_GetVersionString,_SetMaxNumThreads,_GetMaxNumThreads,_GetConcurrencyTypeString,_DeleteString --preload-file /wasm/tzdata@/tzdata --preload-file /wasm/etc@/etc") + string(APPEND CMAKE_EXE_LINKER_FLAGS " -sINVOKE_RUN=0 -sALLOW_MEMORY_GROWTH=1 -sMEMORY_GROWTH_GEOMETRIC_STEP=0.50 -sMODULARIZE=1 -sEXPORT_NAME=AmalgamRuntime -sENVIRONMENT=worker,node,web -sEXPORTED_RUNTIME_METHODS=cwrap,ccall,FS,setValue,getValue,UTF8ToString -sEXPORTED_FUNCTIONS=_malloc,_free,_LoadEntity,_CloneEntity,_VerifyEntity,_StoreEntity,_ExecuteEntity,_ExecuteEntityJsonPtr,_DestroyEntity,_GetEntities,_SetRandomSeed,_SetJSONToLabel,_GetJSONPtrFromLabel,_SetSBFDataStoreEnabled,_IsSBFDataStoreEnabled,_GetVersionString,_SetMaxNumThreads,_GetMaxNumThreads,_GetConcurrencyTypeString,_DeleteString --preload-file /wasm/tzdata@/tzdata --preload-file /wasm/etc@/etc") + # Set memory arguments + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + string(APPEND CMAKE_EXE_LINKER_FLAGS " -sINITIAL_HEAP=65536000 -sSTACK_SIZE=33554432") + else() + string(APPEND CMAKE_EXE_LINKER_FLAGS " -sINITIAL_HEAP=16777216 -sSTACK_SIZE=8388608") + endif() endif() elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") @@ -139,6 +145,15 @@ if(IS_MSVC) add_compile_definitions(UNICODE _UNICODE) endif() +# Ensure that debug WASM builds include additional WASM-specific linker flags +if (IS_WASM AND CMAKE_BUILD_TYPE STREQUAL "Debug") + string(APPEND CMAKE_EXE_LINKER_FLAGS " -sASSERTIONS=2") + # Remove the below flags as they are incompatible with debugging WASM + string(REPLACE "-Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "-Wlimited-postlink-optimizations" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(APPEND CMAKE_CXX_FLAGS " -O0 -gseparate-dwarf") +endif() + # amd64 advanced intrinsics: # Note: allowed values - avx avx2 avx512 set(ADVANCED_INTRINSICS_AMD64 "avx2") diff --git a/src/Amalgam/Parser.cpp b/src/Amalgam/Parser.cpp index 0ed60021..6c53e1f5 100644 --- a/src/Amalgam/Parser.cpp +++ b/src/Amalgam/Parser.cpp @@ -78,10 +78,10 @@ std::tuple, size_t> { pt.originalSource = std::filesystem::canonical(p).string(); } - catch(std::filesystem::filesystem_error &e) + catch(...) { - //file doesn't exist - pt.originalSource = e.what(); + //file doesn't exist, or was some other form of resource, just use original + pt.originalSource = *original_source; } } diff --git a/src/Amalgam/amlg_code/persist_module_test.amlg b/src/Amalgam/amlg_code/persist_module_test.amlg index b4333df6..83f663f8 100644 --- a/src/Amalgam/amlg_code/persist_module_test.amlg +++ b/src/Amalgam/amlg_code/persist_module_test.amlg @@ -1,5 +1,5 @@ -(parallel - #a 1 - #hello - (print "hello\n") -) +(parallel + #a 1 + #hello + (print "hello\n") +) diff --git a/src/Amalgam/amlg_code/persist_module_test/psm.amlg b/src/Amalgam/amlg_code/persist_module_test/psm.amlg index 485d2c81..3a552910 100644 --- a/src/Amalgam/amlg_code/persist_module_test/psm.amlg +++ b/src/Amalgam/amlg_code/persist_module_test/psm.amlg @@ -1,5 +1,5 @@ -(parallel - #a 8 - #hello - (print "hello from psm\n") -) +(parallel + #a 8 + #hello + (print "hello from psm\n") +) diff --git a/src/Amalgam/amlg_code/persistent_tree_test_leaf.amlg b/src/Amalgam/amlg_code/persistent_tree_test_leaf.amlg index a846389c..79d132ef 100644 --- a/src/Amalgam/amlg_code/persistent_tree_test_leaf.amlg +++ b/src/Amalgam/amlg_code/persistent_tree_test_leaf.amlg @@ -1,5 +1,5 @@ -(parallel - #f 6 - #jello - (print "jello\n") -) +(parallel + #f 6 + #jello + (print "jello\n") +) diff --git a/test/wasm_test/README.md b/test/wasm_test/README.md index 448cdc1d..944dcfc7 100644 --- a/test/wasm_test/README.md +++ b/test/wasm_test/README.md @@ -8,11 +8,11 @@ npm install ## Define environment variables -Define the environment variable `AMALGAM_WASM_DIR` to the directory where the following files exist: +Define the environment variable `AMALGAM_WASM_DIR` and `AMALGAM_BASE_FILE` to the directory where the following files exist: -- amalgam-st.wasm -- amalgam-st.cjs -- amalgam-st.data +- amalgam-st(-debug).wasm +- amalgam-st(-debug).cjs +- amalgam-st(-debug).data On your personal machine, you may find it easier to copy [.env.sample](./.env.sample) to `.env`. diff --git a/test/wasm_test/tests/wasm.test.cjs b/test/wasm_test/tests/wasm.test.cjs index ff0f035a..684e54eb 100644 --- a/test/wasm_test/tests/wasm.test.cjs +++ b/test/wasm_test/tests/wasm.test.cjs @@ -1,21 +1,30 @@ const fs = require("node:fs"); const path = require("node:path"); const { describe, expect, test } = require("@jest/globals"); -const AmalgamRuntime = require(path.resolve(process.env.AMALGAM_WASM_DIR, "amalgam-st.cjs")); + +const AmalgamRuntime = require(path.resolve( + process.env.AMALGAM_WASM_DIR, + process.env.AMALGAM_BASE_FILE + ".cjs" +)); describe("Test Amalgam Webassembly", () => { let amlg; beforeAll(async () => { - const binary = fs.readFileSync(path.resolve(process.env.AMALGAM_WASM_DIR, "amalgam-st.wasm")); + const binary = fs.readFileSync( + path.resolve( + process.env.AMALGAM_WASM_DIR, + process.env.AMALGAM_BASE_FILE + ".wasm" + ) + ); amlg = await AmalgamRuntime({ - "wasmBinary": binary, - "getPreloadedPackage": function (packagePath) { + wasmBinary: binary, + getPreloadedPackage: function (packagePath) { // Manually load package data from file system const data = fs.readFileSync(packagePath); return data.buffer; }, - "locateFile": function (filepath) { + locateFile: function (filepath) { // Override the local file method to use local file system return path.resolve(process.env.AMALGAM_WASM_DIR, filepath); },