diff --git a/.circleci/build_win.ps1 b/.circleci/build_win.ps1 index e95caa7c1cf6..6e954b0ef2e2 100644 --- a/.circleci/build_win.ps1 +++ b/.circleci/build_win.ps1 @@ -1,5 +1,18 @@ $ErrorActionPreference = "Stop" +# Initialize Visual Studio environment +$vcvarsall = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" +if (Test-Path $vcvarsall) { + cmd.exe /c "`"$vcvarsall`" amd64 && set" | + ForEach-Object { + if ($_ -match "=") { + $v = $_.split("=", 2); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])" + } + } +} else { + Write-Host "Warning: vcvarsall.bat not found at $vcvarsall. Assuming compilers are in the PATH." +} + cd "$PSScriptRoot\.." if ("$Env:FORCE_RELEASE" -Or "$Env:CIRCLE_TAG") { @@ -18,9 +31,33 @@ else { mkdir build cd build $boost_dir=(Resolve-Path $PSScriptRoot\..\deps\boost\lib\cmake\Boost-*) -..\deps\cmake\bin\cmake -G "Visual Studio 16 2019" -DBoost_DIR="$boost_dir\" -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_INSTALL_PREFIX="$PSScriptRoot\..\upload" .. + +# Configure CMake with sccache if available +$sccachePath = Get-Command sccache -ErrorAction SilentlyContinue +if ($sccachePath) { + Write-Host "Configuring build to use sccache with Ninja generator" + # Use Ninja generator which supports compiler launchers + $cmakeArgs = @( + "-G", "Ninja", + "-DBoost_DIR=$boost_dir\", + "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded", + "-DCMAKE_INSTALL_PREFIX=$PSScriptRoot\..\upload", + "-DCMAKE_CXX_COMPILER_LAUNCHER=sccache", + "-DCMAKE_C_COMPILER_LAUNCHER=sccache" + ) +} else { + Write-Host "sccache not found, using Visual Studio generator without cache" + $cmakeArgs = @( + "-G", "Visual Studio 16 2019", + "-DBoost_DIR=$boost_dir\", + "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded", + "-DCMAKE_INSTALL_PREFIX=$PSScriptRoot\..\upload" + ) +} + +..\deps\cmake\bin\cmake @cmakeArgs .. if ( -not $? ) { throw "CMake configure failed." } -msbuild solidity.sln /p:Configuration=Release /m:10 /v:minimal +..\deps\cmake\bin\cmake --build . --config Release -j 10 if ( -not $? ) { throw "Build failed." } ..\deps\cmake\bin\cmake --build . -j 10 --target install --config Release if ( -not $? ) { throw "Install target failed." } diff --git a/.circleci/config.yml b/.circleci/config.yml index 8b69287b8a7e..c0b28654d913 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -186,6 +186,156 @@ commands: # -------------------------------------------------------------------------- # Build Commands + setup_ccache: + parameters: + os: + type: string + default: "undefined" + + steps: + - run: + name: Create CMake files checksum + command: | + find . -name "CMakeLists.txt" -exec cat {} \; > /tmp/all-cmake-files.txt + - restore_cache: + keys: + - ccache-v1-<>-{{ arch }}-{{ .Branch }}-{{ checksum "/tmp/all-cmake-files.txt" }} + - ccache-v1-<>-{{ arch }}-{{ .Branch }}- + - ccache-v1-<>-{{ arch }}- + - run: + name: Install and configure ccache + command: | + # Install ccache if not present (cmake will use it, via EthCcache) + if ! command -v ccache &> /dev/null; then + if command -v brew &> /dev/null; then + brew install ccache + elif command -v apt &> /dev/null; then + sudo apt update + sudo apt install -y ccache + elif command -v pacman &> /dev/null; then + # ArchLinux + sudo pacman --noconfirm -S ccache + else + echo "Warning: Unknown package manager, ccache may not be available" + fi + fi + + # Configure ccache settings (only if ccache is available) + if command -v ccache &> /dev/null; then + ccache --set-config max_size=2G + ccache --set-config cache_dir=$HOME/.ccache + ccache --zero-stats + + # Show initial stats + echo "ccache initial stats:" + ccache --show-stats + else + echo "ccache not available, skipping configuration" + fi + + finalize_ccache: + parameters: + os: + type: string + steps: + - run: + name: Show ccache stats + command: | + if command -v ccache &> /dev/null; then + echo "ccache final stats:" + ccache --show-stats + else + echo "ccache not available" + fi + - save_cache: + key: ccache-v1-<>-{{ arch }}-{{ .Branch }}-{{ checksum "/tmp/all-cmake-files.txt" }} + paths: + - ~/.ccache + + setup_sccache: + steps: + - run: + name: Create CMake files checksum + command: | + Get-ChildItem -Path . -Filter "CMakeLists.txt" -Recurse | Get-Content | Out-File -FilePath C:\Users\circleci\all-cmake-files.txt -Encoding UTF8 + shell: powershell.exe + - restore_cache: + keys: + - sccache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "C:\\Users\\circleci\\all-cmake-files.txt" }} + - sccache-v1-{{ arch }}-{{ .Branch }}- + - sccache-v1-{{ arch }}- + - run: + name: Install and configure sccache + command: | + # Check if sccache is already installed + $sccachePath = Get-Command sccache -ErrorAction SilentlyContinue + if (-not $sccachePath) { + Write-Host "Installing sccache..." + # Download sccache + $sccacheVersion = "v0.8.2" + $sccacheUrl = "https://github.com/mozilla/sccache/releases/download/$sccacheVersion/sccache-$sccacheVersion-x86_64-pc-windows-msvc.tar.gz" + Invoke-WebRequest -Uri $sccacheUrl -OutFile sccache.tar.gz -UserAgent "" + + # Extract sccache + tar -xf sccache.tar.gz + $sccacheDir = Get-ChildItem -Directory -Filter "sccache-*" | Select-Object -First 1 + Move-Item "$sccacheDir\sccache.exe" "C:\Windows\System32\" + Remove-Item sccache.tar.gz + Remove-Item -Recurse $sccacheDir + } + + # Check if Ninja is already installed + $ninjaPath = Get-Command ninja -ErrorAction SilentlyContinue + if (-not $ninjaPath) { + Write-Host "Installing Ninja..." + # Download Ninja + $ninjaVersion = "v1.11.1" + $ninjaUrl = "https://github.com/ninja-build/ninja/releases/download/$ninjaVersion/ninja-win.zip" + Invoke-WebRequest -Uri $ninjaUrl -OutFile ninja.zip -UserAgent "" + + # Extract Ninja + Expand-Archive -Path ninja.zip -DestinationPath ninja + Move-Item "ninja\ninja.exe" "C:\Windows\System32\" + Remove-Item ninja.zip + Remove-Item -Recurse ninja + } + + # Configure sccache + $env:SCCACHE_CACHE_SIZE = "2G" + $env:SCCACHE_DIR = "C:\Users\circleci\sccache" + [Environment]::SetEnvironmentVariable("SCCACHE_CACHE_SIZE", "2G", "Machine") + [Environment]::SetEnvironmentVariable("SCCACHE_DIR", "C:\Users\circleci\sccache", "Machine") + + # Create sccache directory if it doesn't exist + if (-not (Test-Path "C:\Users\circleci\sccache")) { + New-Item -ItemType Directory -Path "C:\Users\circleci\sccache" -Force | Out-Null + } + + # Start sccache server and show initial stats + sccache --stop-server | Out-Null + sccache --start-server + Write-Host "sccache initial stats:" + sccache --show-stats + shell: powershell.exe + + finalize_sccache: + steps: + - run: + name: Show sccache stats + command: | + $sccachePath = Get-Command sccache -ErrorAction SilentlyContinue + if ($sccachePath) { + Write-Host "sccache final stats:" + sccache --show-stats + } else { + Write-Host "sccache not available" + } + shell: powershell.exe + - save_cache: + key: sccache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "C:\\Users\\circleci\\all-cmake-files.txt" }} + paths: + - C:\Users\circleci\sccache + setup_prerelease_commit_hash: steps: - run: @@ -199,10 +349,18 @@ commands: echo -n "$CIRCLE_SHA1" > commit_hash.txt run_build: + parameters: + os: + type: string + default: "undefined" steps: + - setup_ccache: + os: <> - run: name: Build command: scripts/ci/build.sh + - finalize_ccache: + os: <> run_build_ossfuzz: steps: @@ -341,9 +499,14 @@ commands: - matrix_notify_failure_unless_pr build: + parameters: + os: + type: string + default: "undefined" steps: - checkout - - run_build + - run_build: + os: << parameters.os >> - store_artifacts_solc - store_artifacts_yul_phaser - persist_executables_to_workspace @@ -1034,7 +1197,8 @@ jobs: # Enough other jobs depend on it that it's worth it though. <<: *base_ubuntu2404_xlarge steps: - - build + - build: + os: ubu # x64 ASAN build, for testing for memory related bugs b_ubu_asan: &b_ubu_asan @@ -1051,7 +1215,8 @@ jobs: # Set the number of jobs to two instead of the default three, so that we do not run out of memory MAKEFLAGS: -j 2 steps: - - build + - build: + os: ubu_asan b_ubu_clang: &b_ubu_clang <<: *base_ubuntu2404_clang_large @@ -1059,7 +1224,8 @@ jobs: <<: *base_ubuntu2404_clang_large_env MAKEFLAGS: -j 10 steps: - - build + - build: + os: ubu_clang b_ubu_san_clang: # This runs a bit faster on large and xlarge but on nightly efficiency matters more. @@ -1072,7 +1238,8 @@ jobs: # NOTE: Disabled pedantic builds to avoid false positives, see b_ubu_asan for a more detailed explanation. CMAKE_OPTIONS: -DPEDANTIC=OFF << parameters.cmake_options >> steps: - - build + - build: + os: ubu_san_clang b_ubu_force_release: &b_ubu_force_release <<: *b_ubu @@ -1091,7 +1258,8 @@ jobs: CMAKE_OPTIONS: -DCMAKE_BUILD_TYPE=Release -DSOLC_LINK_STATIC=ON steps: - checkout - - run_build + - run_build: + os: ubu - run: name: strip binary command: strip build/solc/solc @@ -1109,7 +1277,8 @@ jobs: <<: *base_ubuntu2204_large steps: - checkout - - run_build + - run_build: + os: ubu_2204 - matrix_notify_failure_unless_pr b_ubu_2204_clang: @@ -1119,7 +1288,8 @@ jobs: MAKEFLAGS: -j 10 steps: - checkout - - run_build + - run_build: + os: ubu_2204_clang - matrix_notify_failure_unless_pr b_ubu_ossfuzz: &b_ubu_ossfuzz @@ -1157,7 +1327,8 @@ jobs: command: | pacman --noconfirm -Syu --noprogressbar --needed base-devel boost cmake git openssh tar - checkout - - run_build + - run_build: + os: archlinux - store_artifacts_solc - persist_executables_to_workspace - matrix_notify_failure_unless_pr @@ -1172,7 +1343,8 @@ jobs: steps: - checkout - install_dependencies_osx - - run_build + - run_build: + os: mac - store_artifacts_solc - store_artifacts_yul_phaser - persist_executables_to_workspace_osx @@ -1215,10 +1387,14 @@ jobs: MAKEFLAGS: -j 10 steps: - checkout + - setup_ccache: + os: ems - run: name: Build command: | scripts/ci/build_emscripten.sh + - finalize_ccache: + os: ems - store_artifacts: path: upload/soljson.js destination: soljson.js @@ -1644,10 +1820,12 @@ jobs: key: dependencies-win-{{ arch }}-{{ checksum "scripts/install_deps.ps1" }} paths: - .\deps + - setup_sccache - run: name: "Building solidity" command: .circleci/build_win.ps1 shell: powershell.exe + - finalize_sccache - run: name: "Run solc.exe to make sure build was successful." command: .\build\solc\Release\solc.exe --version @@ -1889,7 +2067,6 @@ workflows: # build-only - b_docs: *requires_nothing - - b_ubu_ossfuzz: *requires_nothing - b_ubu_2204: *requires_nothing - b_ubu_2204_clang: *requires_nothing diff --git a/scripts/ci/build_emscripten.sh b/scripts/ci/build_emscripten.sh index e4d25f195fb7..739a281887de 100755 --- a/scripts/ci/build_emscripten.sh +++ b/scripts/ci/build_emscripten.sh @@ -74,6 +74,8 @@ function build() { -DBoost_USE_STATIC_LIBS=1 \ -DBoost_USE_STATIC_RUNTIME=1 \ -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DTESTS=0 \ .. make soljson