diff --git a/.github/workflows/crypto3-testing-linux.yml b/.github/workflows/crypto3-testing-linux.yml index 3c616db3e..00e751881 100644 --- a/.github/workflows/crypto3-testing-linux.yml +++ b/.github/workflows/crypto3-testing-linux.yml @@ -1,16 +1,5 @@ name: Crypto3 Build and Test on Linux Platforms -on: - workflow_call: - inputs: - submodules-refs: - type: string - description: "Lines with submodules' repo names and refs (e.g. `org/repo: ref`)" - required: false - -env: - TESTS_ARTIFACT_NAME: "test-results-linux" - jobs: build-and-test: name: "Build and test Linux" @@ -24,7 +13,6 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 0 - submodules: recursive - name: Checkout submodules to specified refs if: inputs.submodules-refs != '' @@ -37,49 +25,8 @@ jobs: !${{ github.workspace }}/**/.git/** - name: Run checks - run: nix flake -L check .?submodules=1# + run: nix flake -L check env: NIX_CONFIG: | cores = 6 max-jobs = 4 - - - name: Copy test results - run: | - check_names=( - "algebra-clang" - "containers-clang" - "hash-clang" - "marshalling-algebra-clang" - "marshalling-core-clang" - "marshalling-zk-clang" - "math-clang" - "pubkey-clang" - "zk-clang" - "algebra-gcc" - "containers-gcc" - "hash-gcc" - "marshalling-algebra-gcc" - "marshalling-core-gcc" - "marshalling-zk-gcc" - "math-gcc" - "pubkey-gcc" - "zk-gcc" - ) - - results_dir="./results" - mkdir -p "$results_dir" - - for check_name in "${check_names[@]}"; do - # This completes immediately since results are in cache - nix build -L .?submodules=1#checks.x86_64-linux.$check_name - cp -r ./result/* "$results_dir/$check_name" - rm result - done - - - name: Publish Test Results - uses: EnricoMi/publish-unit-test-result-action/linux@v2 - with: - check_name: "Linux Test Results" - files: "results/**/*.xml" - comment_mode: ${{ github.event.pull_request.head.repo.fork && 'off' || 'always' }} # Don't create PR comment from fork runs - action_fail_on_inconclusive: true # fail, if no reports diff --git a/.github/workflows/crypto3-testing-mac.yml b/.github/workflows/crypto3-testing-mac.yml index f26d7d383..f8dc02e25 100644 --- a/.github/workflows/crypto3-testing-mac.yml +++ b/.github/workflows/crypto3-testing-mac.yml @@ -1,16 +1,5 @@ name: Crypto3 Build and Test on macOS Platforms -on: - workflow_call: - inputs: - submodules-refs: - type: string - description: "Lines with submodules' repo names and refs (e.g. `org/repo: ref`)" - required: false - -env: - TESTS_ARTIFACT_NAME: "test-results-mac" - jobs: build-and-test: name: "Build and test macOS" @@ -20,17 +9,6 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - submodules: recursive - - - name: Checkout submodules to specified refs - if: inputs.submodules-refs != '' - uses: NilFoundation/ci-cd/actions/recursive-checkout@v1.2.1 - with: - refs: ${{ inputs.submodules-refs }} - paths: | - ${{ github.workspace }}/** - !${{ github.workspace }}/ - !${{ github.workspace }}/**/.git/** # From https://github.com/DeterminateSystems/magic-nix-cache-action - uses: DeterminateSystems/nix-installer-action@main @@ -38,40 +16,8 @@ jobs: - uses: DeterminateSystems/flake-checker-action@main - name: Run checks - run: nix flake -L check .?submodules=1# + run: nix flake -L check env: NIX_CONFIG: | cores = 0 max-jobs = 1 - - - name: Copy test results - run: | - check_names=( - "algebra-clang" - "containers-clang" - "hash-clang" - "marshalling-algebra-clang" - "marshalling-core-clang" - "marshalling-zk-clang" - "math-clang" - "pubkey-clang" - "zk-clang" - ) - - results_dir="./results" - mkdir -p "$results_dir" - - for check_name in "${check_names[@]}"; do - # This completes immediately since results are in cache - nix build -L .?submodules=1#checks.aarch64-darwin.$check_name - cp -r ./result/* "$results_dir/$check_name" - rm result - done - - - name: Publish Test Results - uses: EnricoMi/publish-unit-test-result-action/linux@v2 - with: - check_name: "Mac Test Results" - files: "results/**/*.xml" - comment_mode: ${{ github.event.pull_request.head.repo.fork && 'off' || 'always' }} # Don't create PR comment from fork runs - action_fail_on_inconclusive: true # fail, if no reports diff --git a/.github/workflows/deploy_docs.yaml b/.github/workflows/deploy_docs.yaml deleted file mode 100644 index 72df20dbe..000000000 --- a/.github/workflows/deploy_docs.yaml +++ /dev/null @@ -1,103 +0,0 @@ -name: Deploy docs - -on: - # Allows you to run this workflow manually from Actions tab - workflow_dispatch: - inputs: - sha-commit: - type: string - description: Sha-commit. Leave empty to use latest commit from selected branch - required: false - target: - type: choice - description: Target - required: true - options: - - staging - - production - default: staging - -env: - SHA_COMMIT: ${{ github.event.inputs.sha-commit || github.sha }} - BUILD_DOCS_WORKFLOW: build_docs.yaml - BUILD_NAME: build_docs-${{ github.event.inputs.sha-commit || github.sha }} - -jobs: - deploy-staging: - if: github.event.inputs.target == 'staging' - runs-on: [ubuntu-latest] - steps: - - name: Download artifacts - uses: dawidd6/action-download-artifact@v2 - with: - workflow: ${{ env.BUILD_DOCS_WORKFLOW }} - workflow_conclusion: completed - search_artifacts: true - name: ${{ env.BUILD_NAME }} - - - name: Extract artifacts - run: | - tar -xf ${{ env.BUILD_NAME }}.tar.gz - rm ${{ env.BUILD_NAME }}.tar.gz - - - name: Install SSH Key - uses: shimataro/ssh-key-action@v2 - with: - key: ${{ secrets.DOCS_STAGING_SSH_KEY }} - known_hosts: ${{secrets.DOCS_STAGING_KNOWN_HOSTS}} - if_key_exists: ignore - - - name: Deploy on staging host - env: - HOST: ${{ secrets.DOCS_STAGING_HOST }} - USER: ${{ secrets.DOCS_STAGING_USER }} - TARGET_DIR: '/home/docs/build' - OPTIONS: '-az --progress --delete' - run: rsync ${{ env.OPTIONS }} . ${{ env.USER }}@${{ env.HOST }}:${{ env.TARGET_DIR }} - - - deploy-production: - if: github.event.inputs.target == 'production' - runs-on: [ubuntu-latest] - env: - SOURCE_REPO: "NilFoundation/crypto3" - PRODUCTION_REPO: "NilFoundation/crypto3.nil.foundation" - DOCS_PATH_IN_REPO: "projects/crypto3/" - steps: - - name: Checkout production repository - uses: actions/checkout@v3 - with: - repository: ${{ env.PRODUCTION_REPO }} - ref: master - - - name: Download artifacts - uses: dawidd6/action-download-artifact@v2 - with: - workflow: ${{ env.BUILD_DOCS_WORKFLOW }} - workflow_conclusion: completed - search_artifacts: true - name: ${{ env.BUILD_NAME }} - - - name: Extract artifacts - run: | - tar -xf ${{ env.BUILD_NAME }}.tar.gz -C ${{ env.DOCS_PATH_IN_REPO }} - rm ${{ env.BUILD_NAME }}.tar.gz - - - name: Commit changes - run: | - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - git add . - git commit -m "Build docs from commit ${{ env.SHA_COMMIT }} in ${{ env.SOURCE_REPO }}" - - - name: Install SSH Key - uses: webfactory/ssh-agent@v0.5.4 - with: - ssh-private-key: ${{ secrets.DOCS_STAGING_DEPLOY_KEY }} - - - name: Push changes - uses: ad-m/github-push-action@master - with: - repository: ${{ env.PRODUCTION_REPO }} - ssh: true - branch: master diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 020d12e3b..6fd573dd3 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -15,22 +15,11 @@ concurrency: cancel-in-progress: true jobs: - handle-syncwith: - if: github.event_name == 'pull_request' - name: Call Reusable SyncWith Handler - uses: NilFoundation/ci-cd/.github/workflows/reusable-handle-syncwith.yml@v1.2.1 - with: - ci-cd-ref: 'v1.1.2' - secrets: inherit - test-linux: name: Linux Crypto3 Testing uses: ./.github/workflows/crypto3-testing-linux.yml - needs: - - handle-syncwith if: | - always() && !cancelled() && - (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') + always() && !cancelled() secrets: inherit with: submodules-refs: ${{ needs.handle-syncwith.outputs.prs-refs }} @@ -38,11 +27,8 @@ jobs: test-mac: name: macOS Crypto3 Testing uses: ./.github/workflows/crypto3-testing-mac.yml - needs: - - handle-syncwith if: | - always() && !cancelled() && - (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') + always() && !cancelled() secrets: inherit with: submodules-refs: ${{ needs.handle-syncwith.outputs.prs-refs }} diff --git a/.github/workflows/reusable-submodule-testing-linux.yml b/.github/workflows/reusable-submodule-testing-linux.yml deleted file mode 100644 index bd9c6bf50..000000000 --- a/.github/workflows/reusable-submodule-testing-linux.yml +++ /dev/null @@ -1,97 +0,0 @@ -name: Crypto3 Build and Test on Linux Platforms (Reusable) - -on: - workflow_call: - inputs: - submodules-refs: - type: string - description: "Lines with submodules' repo names and refs (e.g. `org/repo: ref`)" - required: false - check-names: - type: string - description: "Newline-separated names of checks to run, concurrency level can be provided after space for each check (e.g. `check1 4\ncheck2 2`)" - required: true - -env: - TESTS_ARTIFACT_NAME: "test-results-linux" - -jobs: - build-and-test: - name: "Build and test Linux" - runs-on: [self-hosted, Linux, X64, aws_autoscaling, c5.9xlarge] - steps: - # https://github.com/actions/checkout/issues/1552 - - name: Clean up after previous checkout - run: chmod +w -R ${GITHUB_WORKSPACE}; rm -rf ${GITHUB_WORKSPACE}/*; - - - name: Checkout Crypto3 repository - # We need full history, because during CMake config stage we are finding the nearest tag - uses: actions/checkout@v3 - with: - repository: NilFoundation/crypto3 - fetch-depth: 1 # Fetch only the latest commit on the triggered branch/ref - submodules: recursive - - - name: Checkout submodules to specified refs - if: inputs.submodules-refs != '' - uses: NilFoundation/ci-cd/actions/recursive-checkout@v1.2.1 - with: - refs: ${{ inputs.submodules-refs }} - paths: | - ${{ github.workspace }}/** - !${{ github.workspace }}/**/.git/** - - - name: Determine submodule path - id: get-submodule-path - run: | - # Parsing .gitmodules to find the path of the submodule repository. - submodule_path=$(git config --file .gitmodules --get-regexp path | awk -v repo_name="${{ github.event.repository.name }}" '$0 ~ "submodule\\."repo_name"\\.path" { sub(/.*path /, ""); print }') - echo "Submodule path is $submodule_path" - echo "submodule-path=$submodule_path" >> $GITHUB_OUTPUT - - - name: Checkout current repository as umbrella submodule lib - # TODO: update to v4 when runner will support node20, for now it raises `GLIBC_2.27 ... GLIBC_2.28 not found` - uses: actions/checkout@v3 - with: - path: ${{ steps.get-submodule-path.outputs.submodule-path }} - fetch-depth: 1 - submodules: recursive - - - name: Run checks, copy test results - run: | - input="${{ inputs.check-names }}" - - # Split the input into lines - IFS=$'\n' read -r -d '' -a lines <<< "$input"$'\n' || true - results_dir="results" - mkdir -p "$results_dir" - - for line in "${lines[@]}"; do - # Skip empty lines - [[ -z "$line" ]] && continue - - # Split each line into words - IFS=' ' read -r -a parts <<< "$line" - - check_name="${parts[0]}" - concurrency="${parts[1]:-}" # Default to empty if not specified - extra_args="" - - if [[ -n "$concurrency" ]]; then - extra_args+=" --cores $concurrency" - fi - - echo "Running check for $check_name ${extra_args:+with $extra_args}" - nix build -L .?submodules=1#checks.x86_64-linux.$check_name $extra_args - - cp -r ./result/* "$results_dir/$check_name" - rm -rf result - done - - - name: Publish Test Results - uses: EnricoMi/publish-unit-test-result-action/linux@v2 - with: - check_name: "Linux Test Results" - files: "results/**/*.xml" - comment_mode: ${{ github.event.pull_request.head.repo.fork && 'off' || 'always' }} # Don't create PR comment from fork runs - action_fail_on_inconclusive: true # fail, if no reports diff --git a/.github/workflows/reusable-submodule-testing-mac.yml b/.github/workflows/reusable-submodule-testing-mac.yml deleted file mode 100644 index 816ec1495..000000000 --- a/.github/workflows/reusable-submodule-testing-mac.yml +++ /dev/null @@ -1,98 +0,0 @@ -name: Crypto3 Build and Test on Mac (Reusable) - -on: - workflow_call: - inputs: - submodules-refs: - type: string - description: "Lines with submodules' repo names and refs (e.g. `org/repo: ref`)" - required: false - check-names: - type: string - description: "Newline-separated names of checks to run, concurrency level can be provided after space for each check (e.g. `check1 4\ncheck2 2`)" - required: true - -env: - TESTS_ARTIFACT_NAME: "test-results-mac" - -jobs: - build-and-test: - name: "Build and test macOS" - runs-on: [macos-12] - steps: - - name: Checkout Crypto3 repository - # We need full history, because during CMake config stage we are finding the nearest tag - uses: actions/checkout@v3 - with: - repository: NilFoundation/crypto3 - fetch-depth: 1 # Fetch only the latest commit on the triggered branch/ref - submodules: recursive - - - name: Checkout submodules to specified refs - if: inputs.submodules-refs != '' - uses: NilFoundation/ci-cd/actions/recursive-checkout@v1.2.1 - with: - refs: ${{ inputs.submodules-refs }} - paths: | - ${{ github.workspace }}/** - !${{ github.workspace }}/ - !${{ github.workspace }}/**/.git/** - - - name: Determine submodule path - id: get-submodule-path - run: | - # Parsing .gitmodules to find the path of the submodule repository. - submodule_path=$(git config --file .gitmodules --get-regexp path | awk -v repo_name="${{ github.event.repository.name }}" '$0 ~ "submodule\\."repo_name"\\.path" { sub(/.*path /, ""); print }') - echo "Submodule path is $submodule_path" - echo "submodule-path=$submodule_path" >> $GITHUB_OUTPUT - - - name: Checkout current repository as umbrella submodule lib - uses: actions/checkout@v4 - with: - path: ${{ steps.get-submodule-path.outputs.submodule-path }} - fetch-depth: 1 - submodules: recursive - - # From https://github.com/DeterminateSystems/magic-nix-cache-action - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main - - uses: DeterminateSystems/flake-checker-action@main - - - name: Run checks, copy test results - run: | - input="${{ inputs.check-names }}" - - # Split the input into lines - IFS=$'\n' read -r -d '' -a lines <<< "$input"$'\n' || true - results_dir="./results" - mkdir -p "$results_dir" - - for line in "${lines[@]}"; do - # Skip empty lines - [[ -z "$line" ]] && continue - - # Split each line into words - IFS=' ' read -r -a parts <<< "$line" - - check_name="${parts[0]}" - concurrency="${parts[1]:-}" # Default to empty if not specified - extra_args="" - - if [[ -n "$concurrency" ]]; then - extra_args+=" --cores $concurrency" - fi - - echo "Running check for $check_name ${extra_args:+with $extra_args}" - nix build -L .?submodules=1#checks.x86_64-darwin.$check_name $extra_args - - cp -r ./result/* "$results_dir/$check_name" - rm -rf result - done - - - name: Publish Test Results - uses: EnricoMi/publish-unit-test-result-action/linux@v2 - with: - check_name: "Linux Test Results" - files: "results/**/*.xml" - comment_mode: ${{ github.event.pull_request.head.repo.fork && 'off' || 'always' }} # Don't create PR comment from fork runs - action_fail_on_inconclusive: true # fail, if no reports diff --git a/.gitignore b/.gitignore index 14a750208..3073ba18b 100644 --- a/.gitignore +++ b/.gitignore @@ -350,6 +350,7 @@ install_manifest.txt compile_commands.json CTestTestfile.cmake build +result ### LaTeX ### ## Core latex/pdflatex auxiliary files: diff --git a/CMakeLists.txt b/CMakeLists.txt index baf7c8933..b0a4c93d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") find_package(CM) include(CMConfig) include(CMSetupVersion) - cm_workspace(crypto3) cm_setup_version(VERSION 0.3.0 PREFIX ${CMAKE_WORKSPACE_NAME}) diff --git a/cmake/CheckSSE.cmake b/cmake/CheckSSE.cmake index 4ba5bf550..dbc971b36 100644 --- a/cmake/CheckSSE.cmake +++ b/cmake/CheckSSE.cmake @@ -59,7 +59,7 @@ macro(check_sse) endif(SSE42_TRUE) elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") - execute_process(COMMAND "/usr/sbin/sysctl -n machdep.cpu.features" OUTPUT_VARIABLE + execute_process(COMMAND "/usr/bin/env -S sysctl -n machdep.cpu.features" OUTPUT_VARIABLE CPUINFO) string(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE "${CPUINFO}") @@ -143,4 +143,4 @@ macro(check_sse) mark_as_advanced(SSE2_FOUND SSE3_FOUND SSSE3_FOUND SSE4_1_FOUND SSE4_2_FOUND) -endmacro(check_sse) \ No newline at end of file +endmacro(check_sse) diff --git a/crypto3.nix b/crypto3.nix new file mode 100644 index 000000000..2daf3dae8 --- /dev/null +++ b/crypto3.nix @@ -0,0 +1,48 @@ +{ lib, + stdenv, + src_repo, + ninja, + pkg-config, + cmake, + boost183, + # We'll use boost183 by default, but you can override it + boost_lib ? boost183, + gdb, + cmake_modules, + enableDebugging, + enableDebug ? false, + runTests ? false, + }: +let + inherit (lib) optional; +in stdenv.mkDerivation { + name = "Crypto3"; + + src = src_repo; + + nativeBuildInputs = [ cmake ninja pkg-config ] ++ (lib.optional (!stdenv.isDarwin) gdb); + + # enableDebugging will keep debug symbols in boost + propagatedBuildInputs = [ (if enableDebug then (enableDebugging boost_lib) else boost_lib) ]; + + buildInputs = [cmake_modules]; + + cmakeFlags = + [ + (if runTests then "-DBUILD_TESTS=TRUE" else "") + (if runTests then "-DCMAKE_ENABLE_TESTS=TRUE" else "") + (if enableDebug then "-DCMAKE_BUILD_TYPE=Debug" else "-DCMAKE_BUILD_TYPE=Release") + (if enableDebug then "-DCMAKE_CXX_FLAGS=-ggdb" else "") + ]; + + doCheck = runTests; # tests are inside crypto3-tests derivation + + installPhase = '' + cmake --build build --target install + ''; + + shellHook = '' + PS1="\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ " + echo "Welcome to Crypto3 development environment!" + ''; +} diff --git a/flake.lock b/flake.lock index 8f46a8c55..0f8cdca1a 100644 --- a/flake.lock +++ b/flake.lock @@ -20,7 +20,9 @@ }, "nix-3rdparty": { "inputs": { - "flake-utils": "flake-utils", + "flake-utils": [ + "flake-utils" + ], "nixpkgs": [ "nixpkgs" ] @@ -41,11 +43,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1717676683, - "narHash": "sha256-7X8hfLabXt+U3cjEgSl24dAUJnGdRNXHDPX7LdZIL0s=", + "lastModified": 1720038964, + "narHash": "sha256-im/eyMVgBg5ZXT3QxyE9TM534OG0+D8CtiFbMrf0GpY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "2f0d160888de781bb1b49d2656b1291e2b368b9d", + "rev": "26d9cafa3461c8ec55a6aa7e76ec0f8db0737ff9", "type": "github" }, "original": { @@ -56,6 +58,7 @@ }, "root": { "inputs": { + "flake-utils": "flake-utils", "nix-3rdparty": "nix-3rdparty", "nixpkgs": "nixpkgs" } diff --git a/flake.nix b/flake.nix index a6c19e503..973f5e4dc 100644 --- a/flake.nix +++ b/flake.nix @@ -1,184 +1,59 @@ { - description = "Nix flake for Crypto3 header-only C++ library by =nil; Foundation"; + description = + "Nix flake for Crypto3 header-only C++ library by Nil; Foundation"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; nix-3rdparty = { url = "github:NilFoundation/nix-3rdparty"; inputs = { nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; }; }; }; - outputs = { self - , nixpkgs - , nix-3rdparty - , ... }: - let - supportedSystems = [ - "x86_64-linux" - "x86_64-darwin" - "aarch64-linux" - "aarch64-darwin" - ]; - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - - makeCrypto3Derivation = { system }: - let - pkgs = import nixpkgs { - overlays = [ nix-3rdparty.overlays.${system}.default ]; - inherit system; + outputs = { self, nixpkgs, flake-utils, nix-3rdparty, ... }: + (flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ nix-3rdparty.overlays.${system}.default ]; }; - in - pkgs.stdenv.mkDerivation { - name = "Crypto3"; - - src = self; - - nativeBuildInputs = with pkgs; [ - cmake - cmake_modules - ninja - pkg-config - ]; - - propagatedBuildInputs = with pkgs; [ - boost183 - ]; - - cmakeFlags = [ - "-B build" - "-G Ninja" - "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" - ]; - - dontBuild = true; # nothing to build, header-only lib - - doCheck = false; # tests are inside crypto3-tests derivation - - installPhase = '' - cmake --build build --target install - ''; - }; - - makeCrypto3Shell = { system }: - let - pkgs = import nixpkgs { - overlays = [ nix-3rdparty.overlays.${system}.default ]; - inherit system; + in { + packages = rec { + crypto3 = (pkgs.callPackage ./crypto3.nix { src_repo = self; }); + crypto3-debug = (pkgs.callPackage ./crypto3.nix { + src_repo = self; + enableDebug = true; + }); + crypto3-debug-tests = (pkgs.callPackage ./crypto3.nix { + src_repo = self; + enableDebug = true; + runTests = true; + }); + default = crypto3-debug-tests; }; - in - pkgs.mkShell { - buildInputs = with pkgs; [ - cmake - cmake_modules - ninja - clang - gcc - boost183 - ]; - - shellHook = '' - PS1="\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ " - echo "Welcome to Crypto3 development environment!" - ''; - }; - - makeCrypto3Tests = { system }: - let - pkgs = import nixpkgs { - overlays = [ nix-3rdparty.overlays.${system}.default ]; - inherit system; - }; - isDarwin = builtins.match ".*-darwin" system != null; # Used only to exclude gcc from macOS. - testCompilers = [ - "clang" - # TODO: fix gcc linkage on macOS, remove optional condition - ] ++ nixpkgs.lib.optional (!isDarwin) "gcc"; - # Modules with no failing tests are kept here. Built as `tests-crypto3-` targets - moduleToTestsRegex = { - algebra = "algebra_.*_test"; - containers = "crypto3_containers_.*_test"; - hash = "hash_.*_test"; - math = "math_.*_test"; - block = "block_.*_test"; - multiprecision = "multiprecision_.*_test"; - zk = "crypto3_zk_*_test"; - pubkey = "pubkey_*_test"; - marshalling-core = "marshalling_core_*_test"; - marshalling-zk = "marshalling_zk_*_test"; - marshalling-algebra = "marshalling_algebra_*_test"; - }; - makeTestDerivation = { name, compiler, targets ? [ ], buildTargets ? targets, testTargets ? targets }: - (makeCrypto3Derivation { inherit system; }).overrideAttrs (oldAttrs: { - name = "Crypto3-${name}-tests"; - - nativeBuildInputs = oldAttrs.nativeBuildInputs ++ oldAttrs.propagatedBuildInputs ++ [ - (if compiler == "gcc" then pkgs.gcc else pkgs.clang) - ]; - - propagatedBuildInputs = []; - - cmakeFlags = [ - "-G Ninja" - "-DCMAKE_CXX_COMPILER=${if compiler == "gcc" then "g++" else "clang++"}" - "-DCMAKE_BUILD_TYPE=Release" # TODO: change to Debug after build fix - "-DCMAKE_ENABLE_TESTS=TRUE" - ]; - - dontBuild = false; - # working dir is already set to build dir - buildPhase = '' - cmake --build . --parallel $NIX_BUILD_CORES --target ${nixpkgs.lib.concatStringsSep " " buildTargets} - ''; - - doCheck = true; - checkPhase = '' - # JUNIT file without explicit file name is generated after the name of the master test suite inside `CMAKE_CURRENT_SOURCE_DIR` (/build/source) - export BOOST_TEST_LOGGER=JUNIT:HRF - ctest --verbose -j $NIX_BUILD_CORES --output-on-failure -R "${nixpkgs.lib.concatStringsSep "|" (map (target: "^" + target + "$") testTargets)}" - - mkdir -p ${placeholder "out"}/test-logs - find .. -type f -name '*_test.xml' -exec cp {} ${placeholder "out"}/test-logs \; - ''; - - dontInstall = true; - }); - compilerModuleTestsRegexPairs = pkgs.lib.cartesianProductOfSets { - compiler = testCompilers; - module = pkgs.lib.attrNames moduleToTestsRegex; + checks = rec { + gcc = (pkgs.callPackage ./crypto3.nix { + src_repo = self; + runTests = true; + }); + clang = (pkgs.callPackage ./crypto3.nix { + stdenv = pkgs.llvmPackages_18.stdenv; + src_repo = self; + runTests = true; + }); + all = pkgs.symlinkJoin { + name = "all"; + paths = [ gcc clang ]; }; - in - pkgs.lib.listToAttrs ( - builtins.map - (pair: { - name = "${pair.module}-${pair.compiler}"; - value = makeTestDerivation { - name = pair.module; - compiler = pair.compiler; - buildTargets = [ "tests-crypto3-${pair.module}" ]; - testTargets = [ moduleToTestsRegex.${pair.module} ]; - }; - }) - compilerModuleTestsRegexPairs - ); - in - { - packages = forAllSystems (system: { - default = makeCrypto3Derivation { inherit system; }; - }); - checks = forAllSystems (system: - makeCrypto3Tests { inherit system; } - ); - devShells = forAllSystems (system: { - default = makeCrypto3Shell { inherit system; }; - }); - }; + default = all; + }; + })); } - -# `nix flake -L check .?submodules=1#` to run all tests (-L to output build logs) -# `nix build -L .?submodules=1#checks.x86_64-linux.hash-clang` for partial testing +# `nix flake -L check` to run all tests (-L to output build logs) # `nix flake show` to show derivations tree # If build fails due to OOM, run `export NIX_CONFIG="cores = 2"` to set desired parallel level diff --git a/libs/marshalling/zk/example/CMakeLists.txt b/libs/marshalling/zk/example/CMakeLists.txt index 9d2c0efe5..55af1dcc5 100644 --- a/libs/marshalling/zk/example/CMakeLists.txt +++ b/libs/marshalling/zk/example/CMakeLists.txt @@ -15,12 +15,12 @@ macro(define_marshalling_example name) add_executable(marshalling_${name}_example ${name}.cpp) target_link_libraries(marshalling_${name}_example PRIVATE - + crypto3::multiprecision crypto3::algebra crypto3::zk - ${CMAKE_WORKSPACE_NAME}::crypto3_multiprecision - ${CMAKE_WORKSPACE_NAME}::crypto3_algebra + ${CMAKE_WORKSPACE_NAME}::marshalling-multiprecision + ${CMAKE_WORKSPACE_NAME}::marshalling-algebra ${CMAKE_WORKSPACE_NAME}::crypto3_zk ${CMAKE_WORKSPACE_NAME}::core diff --git a/libs/multiprecision/test/CMakeLists.txt b/libs/multiprecision/test/CMakeLists.txt index 3eadb3048..8f265d72b 100644 --- a/libs/multiprecision/test/CMakeLists.txt +++ b/libs/multiprecision/test/CMakeLists.txt @@ -7,8 +7,6 @@ # http://www.boost.org/LICENSE_1_0.txt #---------------------------------------------------------------------------# -find_package(Eigen3) - #add_custom_target(${CURRENT_PROJECT_NAME}_test_suite_arithmetic_tests) #add_custom_target(${CURRENT_PROJECT_NAME}_test_suite_functions_and_limits) #add_custom_target(${CURRENT_PROJECT_NAME}_test_suite_conversions) diff --git a/libs/random/test/CMakeLists.txt b/libs/random/test/CMakeLists.txt index 676f3b7c3..906748dc0 100644 --- a/libs/random/test/CMakeLists.txt +++ b/libs/random/test/CMakeLists.txt @@ -13,37 +13,38 @@ cm_test_link_libraries(${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME} ${CMAKE_WORKSPACE_NAME}::multiprecision Boost::unit_test_framework) -# TODO(uncomment the failing tests once they pass) -#cm_test(NAME ${CURRENT_PROJECT_NAME}_chacha_test SOURCES ${CURRENT_TEST_SOURCES_DIR}/chacha.cpp) -#set_target_properties(${CURRENT_PROJECT_NAME}_chacha_test PROPERTIES CXX_STANDARD 17) -#target_include_directories(${CURRENT_PROJECT_NAME}_chacha_test PRIVATE -# "$" -# "$" - -# ${Boost_INCLUDE_DIRS}) - -#cm_test(NAME ${CURRENT_PROJECT_NAME}_hash_test SOURCES ${CURRENT_TEST_SOURCES_DIR}/hash.cpp) -#set_target_properties(${CURRENT_PROJECT_NAME}_hash_test PROPERTIES CXX_STANDARD 17) -#target_include_directories(${CURRENT_PROJECT_NAME}_hash_test PRIVATE -# "$" -# "$" -# -# ${Boost_INCLUDE_DIRS}) +macro(define_random_test test) + get_filename_component(name ${test} NAME) + string(REPLACE "/" "_" full_test_name ${CMAKE_WORKSPACE_NAME}_${CURRENT_PROJECT_NAME}_${test}_test) + + cm_test(NAME ${full_test_name} SOURCES ${test}.cpp) + + target_include_directories(${full_test_name} PRIVATE + "$" + "$" -cm_test(NAME ${CURRENT_PROJECT_NAME}_algebraic_engine_test SOURCES ${CURRENT_TEST_SOURCES_DIR}/algebraic_engine.cpp) -set_target_properties(${CURRENT_PROJECT_NAME}_algebraic_engine_test PROPERTIES CXX_STANDARD 17) -target_include_directories(${CURRENT_PROJECT_NAME}_algebraic_engine_test PRIVATE - "$" - "$" + ${Boost_INCLUDE_DIRS}) - ${Boost_INCLUDE_DIRS}) + set_target_properties(${full_test_name} PROPERTIES CXX_STANDARD 17) + + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(${full_test_name} PRIVATE "-fconstexpr-steps=2147483647") + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(${full_test_name} PRIVATE "-fconstexpr-ops-limit=4294967295") + endif() + +endmacro() + +# TODO(uncomment the failing tests once they pass) +set(TESTS_NAMES + # "chacha" + # "hash" + "algebraic_engine" + "rfc6979") -cm_test(NAME ${CURRENT_PROJECT_NAME}_rfc6979_engine_test SOURCES ${CURRENT_TEST_SOURCES_DIR}/rfc6979.cpp) -set_target_properties(${CURRENT_PROJECT_NAME}_rfc6979_engine_test PROPERTIES CXX_STANDARD 17) -target_include_directories(${CURRENT_PROJECT_NAME}_rfc6979_engine_test PRIVATE - "$" - "$" +foreach(TEST_NAME ${TESTS_NAMES}) + define_random_test(${TEST_NAME}) +endforeach() - ${Boost_INCLUDE_DIRS}) include_directories(${CMAKE_WORKSPACE_SOURCES_DIR})