From fbd88802ace673c5fa6dc35de10b9eb2bcf0380d Mon Sep 17 00:00:00 2001 From: Miao ZhiCheng Date: Thu, 8 Aug 2024 12:15:34 +0300 Subject: [PATCH] Support official macosx universal builds (#13) * download.sh & mk-solc-static-pkg.nix: support macos universal builds * update solc listing for macos-aarch64 * make 0.8.26 the default --- .github/workflows/ci.yml | 4 ++-- flake.nix | 2 +- mk-solc-static-pkg.nix | 11 +++++++++-- solc-listing.nix | 4 ++-- test/flake.nix | 14 +++++++++----- utils/download.sh | 17 +++++++++++++---- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb4bad6..c7599f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,10 +27,10 @@ jobs: - name: Test Default Shell run: | set -x - nix develop .# --command -- bash -c "solc-0.8.24 --version" + nix develop .# --command -- bash -c "solc-0.8.26 --version" # overriding flake input is needed as a workaround to local sub flake with overlapping paths. nix develop ./test/.# --override-input solc $PWD --command -- bash -c "solc --version" - nix develop ./test/.# --override-input solc $PWD --command -- bash -c "solc-0.8.24 --version" + nix develop ./test/.# --override-input solc $PWD --command -- bash -c "solc-0.8.26 --version" ci-check-success: needs: [ci] runs-on: ubuntu-latest diff --git a/flake.nix b/flake.nix index e4a92bb..bca112f 100644 --- a/flake.nix +++ b/flake.nix @@ -38,7 +38,7 @@ in { # default shell with the latest solc compiler - devShells.default = pkgs.mkShell { buildInputs = [ pkgs.solc_0_8_24 ]; }; + devShells.default = pkgs.mkShell { buildInputs = [ pkgs.solc_0_8_26 ]; }; } ) // { diff --git a/mk-solc-static-pkg.nix b/mk-solc-static-pkg.nix index a19162a..8bf267c 100644 --- a/mk-solc-static-pkg.nix +++ b/mk-solc-static-pkg.nix @@ -33,13 +33,20 @@ let # The official solc binaries for macOS started supporting Apple Silicon with # v0.8.24. For earlier versions, the binaries from svm can be used. # See https://github.com/alloy-rs/solc-builds + macosUniversalBuildUrl = "https://binaries.soliditylang.org/macosx-amd64/${ + solc-macos-amd64-list.releases.${version} + }"; + url = if solc-flavor == "solc-static-linux" then "https://github.com/ethereum/solidity/releases/download/v${version}/solc-static-linux" else if solc-flavor == "solc-macos-amd64" then - "https://binaries.soliditylang.org/macosx-amd64/${solc-macos-amd64-list.releases.${version}}" + macosUniversalBuildUrl else if solc-flavor == "solc-macos-aarch64" && builtins.compareVersions solc_ver "0.8.5" > -1 then - "https://github.com/alloy-rs/solc-builds/raw/master/macosx/aarch64/solc-v${version}" + if builtins.compareVersions solc_ver "0.8.24" == -1 then + "https://github.com/alloy-rs/solc-builds/raw/master/macosx/aarch64/solc-v${version}" + else + macosUniversalBuildUrl else throw "Unsupported version ${version} for ${system}"; in diff --git a/solc-listing.nix b/solc-listing.nix index 8d4245e..fffcd12 100644 --- a/solc-listing.nix +++ b/solc-listing.nix @@ -4,7 +4,7 @@ sha256 = { solc-static-linux = "sha256-1fI0NvRD7bhdjnaQbRLwqGzgSQ52Y6nmCO/repPxSe8="; solc-macos-amd64 = "sha256-D/AWrvI5axLR/GVCnY6mz1PC7ksEG7iSVkRhXuHDCrk="; - # solc-macos-aarch64 not available for this version + solc-macos-aarch64 = "sha256-D/AWrvI5axLR/GVCnY6mz1PC7ksEG7iSVkRhXuHDCrk="; }; } { @@ -12,7 +12,7 @@ sha256 = { solc-static-linux = "sha256-xCqtp6UgV92+2T7AESNeJWxWTEQLaNuqxa5IK6u7PW0="; solc-macos-amd64 = "sha256-zD+UpwrGgbAwQISswZgKq+KhuzJA1Eznao3w4ed6IRA="; - # solc-macos-aarch64 not available for this version + solc-macos-aarch64 = "sha256-zD+UpwrGgbAwQISswZgKq+KhuzJA1Eznao3w4ed6IRA="; }; } { diff --git a/test/flake.nix b/test/flake.nix index 854d9f3..8cacd47 100644 --- a/test/flake.nix +++ b/test/flake.nix @@ -35,21 +35,25 @@ with pkgs; mkShell { buildInputs = - [ solc_0_8_24 ] + [ + solc_0_8_26 + (solc.mkDefault pkgs solc_0_8_26) + ] ++ ( if system == "x86_64-linux" then [ - solc_0_4_26 + solc_0_4_11 solc_0_7_6 - (solc.mkDefault pkgs solc_0_8_26) ] else if system == "x86_64-darwin" then [ + solc_0_4_11 solc_0_7_6 - (solc.mkDefault pkgs solc_0_8_26) ] + else if system == "aarch64-darwin" then + [ solc_0_8_5 ] else - [ (solc.mkDefault pkgs solc_0_8_24) ] + throw "unknown system" ); }; } diff --git a/utils/download.sh b/utils/download.sh index 0378e40..3dbbe6d 100755 --- a/utils/download.sh +++ b/utils/download.sh @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p semver-tool macos_versions=$(mktemp) curl https://binaries.soliditylang.org/macosx-amd64/list.json >"$macos_versions" @@ -37,9 +38,17 @@ download_one_version() { "$T"/bin/macos-amd64/solc-"$v" mkdir -p "$T/bin/macos-aarch64" - run_wget \ - https://github.com/alloy-rs/solc-builds/raw/master/macosx/aarch64/solc-v"$v" \ - "$T"/bin/macos-aarch64/solc-"$v" + if [ "$(semver compare $v 0.8.23)" == 1 ]; then + # starting from 0.8.24, official solidity distribution started to provide universal builds + # references: + # - https://github.com/ethereum/solidity/issues/14813 + # - https://github.com/alloy-rs/solc-builds/issues/13 + ln -s ../macos-amd64/solc-"$v" "$T"/bin/macos-aarch64/solc-"$v" + else + run_wget \ + https://github.com/alloy-rs/solc-builds/raw/master/macosx/aarch64/solc-v"$v" \ + "$T"/bin/macos-aarch64/solc-"$v" + fi } download_all_versions() {