Compare commits

...

3 Commits

Author SHA1 Message Date
xermicus 75a83af4da ci: clippy (#227)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-02-21 16:43:09 +01:00
xermicus 9c330ef8fc llvm-builder: only run expensive tests on linux (#226)
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
2025-02-21 16:38:44 +01:00
Yuri Volkov 687cec31ef Using released LLVM in revive build (#220) 2025-02-21 16:30:26 +01:00
3 changed files with 405 additions and 348 deletions
+36
View File
@@ -0,0 +1,36 @@
module.exports = async ({
octokit,
context,
releasePrefix,
artifactSuffix,
}) => {
let page = 1;
while (true) {
const res = await octokit.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
page,
});
if (res.data.length === 0) {
throw new Error(
`No LLVM releases with '${artifactSuffix}' atifacts found! Please release LLVM before running this workflow.`,
);
}
for (let release of res.data) {
if (release.tag_name.startsWith(releasePrefix)) {
for (let asset of release.assets) {
if (asset.name.includes(artifactSuffix)) {
return asset.browser_download_url;
}
}
console.warn(
`LLVM release ${release.tag_name} doesn't have a '${artifactSuffix}' artifact; searching for older releases...`,
);
}
}
page++;
}
};
+366 -347
View File
@@ -1,347 +1,366 @@
name: Release name: Release
run-name: Release ${{ github.ref_name }} run-name: Release ${{ github.ref_name }}
on: on:
push: push:
branches: branches:
- 'main' - "main"
concurrency: concurrency:
group: ${{ github.ref }}-${{ github.workflow }} group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true cancel-in-progress: true
env: env:
#rust-musl-cross:x86_64-musl #rust-musl-cross:x86_64-musl
RUST_MUSL_CROSS_IMAGE: messense/rust-musl-cross@sha256:68b86bc7cb2867259e6b233415a665ff4469c28b57763e78c3bfea1c68091561 RUST_MUSL_CROSS_IMAGE: messense/rust-musl-cross@sha256:68b86bc7cb2867259e6b233415a665ff4469c28b57763e78c3bfea1c68091561
RUST_LOG: trace
jobs:
jobs:
# tag:
# runs-on: ubuntu-24.04
# permissions:
tag: contents: write
runs-on: ubuntu-24.04 outputs:
permissions: TAG: ${{ steps.versions.outputs.TAG }}
contents: write PKG_VER: ${{ steps.versions.outputs.PKG_VER }}
outputs: RELEASE_NOTES: ${{ steps.versions.outputs.RELEASE_NOTES }}
TAG: ${{ steps.versions.outputs.TAG }} steps:
PKG_VER: ${{ steps.versions.outputs.PKG_VER }} - name: Checkout
steps: uses: actions/checkout@v4
- name: Checkout with:
uses: actions/checkout@v4 fetch-tags: "true"
with: fetch-depth: 0
fetch-tags: 'true'
fetch-depth: 0 - name: Versions
id: versions
- name: Versions run: |
id: versions export CURRENT_TAG=$(git describe --tags --abbrev=0 --exclude "llvm-*")
run: | export PKG_VER=v$(cat Cargo.toml | grep -A 5 package] | grep version | cut -d '=' -f 2 | tr -d '"' | tr -d " ")
export CURRENT_TAG=$(git describe --tags --abbrev=0 --exclude "llvm-*") echo "Current tag $CURRENT_TAG"
export PKG_VER=v$(cat Cargo.toml | grep -A 5 package] | grep version | cut -d '=' -f 2 | tr -d '"' | tr -d " ") echo "Package version $PKG_VER"
echo "Current tag $CURRENT_TAG" #
echo "Package version $PKG_VER" echo "PKG_VER=$PKG_VER" >> $GITHUB_OUTPUT
# if [[ $CURRENT_TAG == $PKG_VER ]];
echo "PKG_VER=$PKG_VER" >> $GITHUB_OUTPUT then
if [ $CURRENT_TAG == $PKG_VER ]; echo "Tag is up to date. Nothing to do.";
then export TAG=old;
echo "Tag is up to date. Nothing to do."; else
export TAG=old; echo "Tag was updated.";
else export TAG=new;
echo "Tag was updated."; fi
export TAG=new; echo "TAG=$TAG" >> $GITHUB_OUTPUT
fi
echo "TAG=$TAG" >> $GITHUB_OUTPUT # Generating release notes early, in order to avoid checkout at the last step
export RELEASE_NOTES="$(sed '/^## '${PKG_VER}'/,/^## v/!d' CHANGELOG.md | sed -e '1d' -e '$d')"
#
# echo "Release notes:"
# echo "$RELEASE_NOTES"
build-linux-all:
if: ${{ needs.tag.outputs.TAG == 'new' }} echo 'RELEASE_NOTES<<EOF' >> $GITHUB_OUTPUT
runs-on: parity-large echo "$RELEASE_NOTES" >> $GITHUB_OUTPUT
needs: [tag] echo 'EOF' >> $GITHUB_OUTPUT
steps:
- uses: actions/checkout@v4 build-macos:
strategy:
- name: install linux deps matrix:
run: | os: [macos-14, macos-13]
sudo apt-get update && sudo apt-get install -y cmake ninja-build \ include:
curl git libssl-dev pkg-config clang lld musl - os: macos-13
arch: x64
- name: Install Rust stable toolchain - os: macos-14
uses: actions-rs/toolchain@v1 arch: arm64
with: if: ${{ needs.tag.outputs.TAG == 'new' }}
profile: minimal runs-on: ${{ matrix.os }}
toolchain: stable name: "build-macos-${{ matrix.arch }}"
components: rust-src needs: [tag]
target: wasm32-unknown-emscripten steps:
- uses: actions/checkout@v4
- name: versions
run: | - name: Get latest macos ${{ matrix.arch }} LLVM release artifact
rustup show id: get-llvm-artifact
cargo --version uses: actions/github-script@v7
cmake --version with:
echo "bash:" && bash --version result-encoding: string
echo "ninja:" && ninja --version script: |
echo "clang:" && clang --version const getReleaseArtifact = require("./.github/workflows/get-release-artifact.js");
return await getReleaseArtifact({
- name: build revive-llvm octokit: github,
run: make install-llvm-builder context,
releasePrefix: "llvm-",
# musl LLVM artifactSuffix: "-macos-${{ matrix.arch }}"
});
- name: llvm-musl-cache restore
id: llvm-musl-cache - uses: actions-rust-lang/setup-rust-toolchain@v1
uses: actions/cache/restore@v4 with:
with: toolchain: stable
path: target-llvm/musl/target-final components: rust-src
key: llvm-linux-musl-${{ hashFiles('crates/solidity/**') }} target: wasm32-unknown-emscripten
rustflags: ""
- name: Build musl LLVM
if: steps.llvm-musl-cache.outputs.cache-hit != 'true' - name: install macos deps
run: | run: |
revive-llvm --target-env musl clone brew install ninja
revive-llvm --target-env musl build --llvm-projects lld --llvm-projects clang
- name: versions
- name: llvm-musl-cache save run: |
if: steps.llvm-musl-cache.outputs.cache-hit != 'true' rustup show
uses: actions/cache/save@v4 cargo --version
with: cmake --version
path: target-llvm/musl/target-final echo "bash:" && bash --version
key: llvm-linux-musl-${{ hashFiles('crates/solidity/**') }} echo "ninja:" && ninja --version
echo "clang:" && clang --version
# emscripten LLVM
- name: download llvm
- name: llvm-emscripten-cache restore run: |
id: llvm-emscripten-cache curl -L -o llvm.tar.gz "${{ steps.get-llvm-artifact.outputs.result }}"
uses: actions/cache/restore@v4 tar -xvf llvm.tar.gz
with:
path: | - name: build revive
target-llvm/emscripten/target-final run: |
emsdk export LLVM_SYS_181_PREFIX=$PWD/target-llvm/gnu/target-final
key: llvm-linux-emscripten-${{ hashFiles('crates/solidity/**') }} make install-bin
cp ./target/release/resolc ./target/release/resolc-${{ matrix.arch }}
- name: Build emscripten LLVM
if: steps.llvm-emscripten-cache.outputs.cache-hit != 'true' - name: check revive
run: | run: |
revive-llvm --target-env emscripten clone mkdir solc
source emsdk/emsdk_env.sh curl -sSLo solc/solc https://github.com/ethereum/solidity/releases/download/v0.8.28/solc-macos
revive-llvm --target-env emscripten build --llvm-projects lld chmod +x solc/solc
PATH=$PWD/solc:$PATH
- name: llvm-emscripten-cache save result=$(./target/release/resolc-${{ matrix.arch }} --bin crates/integration/contracts/flipper.sol)
if: steps.llvm-emscripten-cache.outputs.cache-hit != 'true' echo $result
uses: actions/cache/save@v4 if [[ $result == *'0x50564d'* ]]; then exit 0; else exit 1; fi
with:
path: | - uses: actions/upload-artifact@v4
target-llvm/emscripten/target-final with:
emsdk name: "revive-macos-${{ matrix.arch }}"
key: llvm-linux-emscripten-${{ hashFiles('crates/solidity/**') }} path: |
./target/release/resolc-${{ matrix.arch }}
# Build revive retention-days: 1
- name: build musl macos-universal-binary:
run: | runs-on: macos-14
mkdir resolc-out needs: [build-macos]
docker run -v $PWD:/opt/revive $RUST_MUSL_CROSS_IMAGE /bin/bash -c " steps:
cd /opt/revive - uses: actions/download-artifact@v4
apt update && apt upgrade -y && apt install -y pkg-config with:
export LLVM_SYS_181_PREFIX=/opt/revive/target-llvm/musl/target-final pattern: revive-macos-*
make install-bin path: revive-macos
cp /root/.cargo/bin/resolc /opt/revive/resolc-out/resolc
" - name: run lipo
run: |
- name: check musl lipo revive-macos/revive-macos-arm64/resolc-arm64 revive-macos/revive-macos-x64/resolc-x64 -create -output resolc-macos
run: |
mkdir solc - name: compress macos artifact
curl -sSLo solc/solc https://github.com/ethereum/solidity/releases/download/v0.8.28/solc-static-linux run: |
chmod +x solc/solc tar -czf resolc-macos.tar.gz ./resolc-macos
PATH=$PWD/solc:$PATH
result=$(./resolc-out/resolc --bin crates/integration/contracts/flipper.sol) - uses: actions/upload-artifact@v4
echo $result with:
if [[ $result == *'0x50564d'* ]]; then exit 0; else exit 1; fi name: revive-macos
path: |
- name: Set Up Node.js resolc-macos.tar.gz
uses: actions/setup-node@v3 retention-days: 1
with:
node-version: "20" build-linux-all:
if: ${{ needs.tag.outputs.TAG == 'new' }}
- name: build wasm runs-on: parity-large
run: | needs: [tag]
export LLVM_SYS_181_PREFIX=$PWD/target-llvm/musl/target-final steps:
export REVIVE_LLVM_TARGET_PREFIX=$PWD/target-llvm/emscripten/target-final - uses: actions/checkout@v4
source emsdk/emsdk_env.sh
rustup target add wasm32-unknown-emscripten - name: Get latest linux LLVM release artifact
make install-wasm id: get-llvm-musl-artifact
uses: actions/github-script@v7
- name: check wasm with:
run: | result-encoding: string
curl -sSLo solc/soljson.js https://github.com/ethereum/solidity/releases/download/v0.8.28/soljson.js script: |
node -e " const getReleaseArtifact = require("./.github/workflows/get-release-artifact.js")
const soljson = require('solc/soljson'); return await getReleaseArtifact({
const createRevive = require('./target/wasm32-unknown-emscripten/release/resolc.js'); octokit: github,
context,
const compiler = createRevive(); releasePrefix: "llvm-",
compiler.soljson = soljson; artifactSuffix: "-x86_64-linux-musl"
})
const standardJsonInput =
{ - name: install linux deps
language: 'Solidity', run: |
sources: { sudo apt-get update && sudo apt-get install -y cmake ninja-build \
'MyContract.sol': { curl git libssl-dev pkg-config clang lld musl
content: 'pragma solidity ^0.8.0; contract MyContract { function greet() public pure returns (string memory) { return \'Hello\'; } }',
}, - uses: actions-rust-lang/setup-rust-toolchain@v1
}, with:
settings: { optimizer: { enabled: false } } toolchain: stable
}; components: rust-src
target: wasm32-unknown-emscripten
compiler.writeToStdin(JSON.stringify(standardJsonInput)); rustflags: ""
compiler.callMain(['--standard-json']);
- name: versions
// Collect output run: |
const stdout = compiler.readFromStdout(); rustup show
const stderr = compiler.readFromStderr(); cargo --version
cmake --version
if (stderr) { console.error(stderr); process.exit(1); } echo "bash:" && bash --version
echo "ninja:" && ninja --version
let out = JSON.parse(stdout); echo "clang:" && clang --version
let bytecode = out.contracts['MyContract.sol']['MyContract'].evm.bytecode.object
console.log(bytecode); - name: download llvm
run: |
if(!bytecode.startsWith('50564d')) { process.exit(1); } curl -L -o llvm.tar.gz "${{ steps.get-llvm-musl-artifact.outputs.result }}"
" tar -xvf llvm.tar.gz
- uses: actions/upload-artifact@v4 # Build revive
with:
name: revive-wasm - name: build musl
path: | run: |
./target/wasm32-unknown-emscripten/release/resolc.js mkdir resolc-out
./target/wasm32-unknown-emscripten/release/resolc.wasm docker run -v $PWD:/opt/revive $RUST_MUSL_CROSS_IMAGE /bin/bash -c "
./target/wasm32-unknown-emscripten/release/resolc_web.js cd /opt/revive
retention-days: 1 apt update && apt upgrade -y && apt install -y pkg-config
export LLVM_SYS_181_PREFIX=/opt/revive/target-llvm/musl/target-final
- uses: actions/upload-artifact@v4 make install-bin
with: cp /root/.cargo/bin/resolc /opt/revive/resolc-out/resolc-static-linux
name: revive-linux "
path: |
./resolc-out/resolc - name: check musl
retention-days: 1 run: |
mkdir solc
# curl -sSLo solc/solc https://github.com/ethereum/solidity/releases/download/v0.8.28/solc-static-linux
# chmod +x solc/solc
# PATH=$PWD/solc:$PATH
create-release: result=$(./resolc-out/resolc-static-linux --bin crates/integration/contracts/flipper.sol)
needs: [tag, build-linux-all] echo $result
runs-on: ubuntu-24.04 if [[ $result == *'0x50564d'* ]]; then exit 0; else exit 1; fi
permissions:
contents: write - name: compress musl artifact
outputs: run: |
upload_url: ${{ steps.create_release.outputs.result }} tar --strip-components 1 -czf resolc-static-linux.tar.gz ./resolc-out/resolc-static-linux
steps:
- uses: actions/checkout@v4 - uses: actions/upload-artifact@v4
with:
- name: Create/update tag name: revive-linux
id: tag path: |
uses: actions/github-script@v7 ./resolc-static-linux.tar.gz
with: retention-days: 1
result-encoding: string
script: | - name: Set Up Node.js
await github.rest.git.createRef({ uses: actions/setup-node@v3
owner: context.repo.owner, with:
repo: context.repo.repo, node-version: "20"
ref: 'refs/tags/${{ needs.tag.outputs.PKG_VER }}',
sha: context.sha - name: Get latest emscripten LLVM release artifact
}) id: get-llvm-emscripten-artifact
uses: actions/github-script@v7
- name: get relese notes with:
id: get-notes result-encoding: string
run: | script: |
{ const getReleaseArtifact = require("./.github/workflows/get-release-artifact.js")
echo 'releaseNotes<<EOF' return await getReleaseArtifact({
sed '/^## ${{ needs.tag.outputs.PKG_VER }}/,/^## v/!d' CHANGELOG.md | sed -e '1d' -e '$d' octokit: github,
echo EOF context,
} >> "$GITHUB_OUTPUT" releasePrefix: "llvm-",
artifactSuffix: "-wasm32-unknown-emscripten"
})
- name: Create release
id: create_release - name: download llvm
env: run: |
releaseNotes: ${{ steps.get-notes.outputs.releaseNotes }} curl -L -o llvm.tar.gz "${{ steps.get-llvm-emscripten-artifact.outputs.result }}"
version: ${{ needs.tag.outputs.PKG_VER }} tar -xvf llvm.tar.gz
uses: actions/github-script@v7
with: - name: build wasm
result-encoding: string run: |
script: | make install-llvm-builder
let response = await github.rest.repos.createRelease({ revive-llvm --target-env emscripten clone
owner: context.repo.owner, export LLVM_SYS_181_PREFIX=$PWD/target-llvm/musl/target-final
repo: context.repo.repo, export REVIVE_LLVM_TARGET_PREFIX=$PWD/target-llvm/emscripten/target-final
tag_name: process.env.version, source emsdk/emsdk_env.sh
name: process.env.version, rustup target add wasm32-unknown-emscripten
body: process.env.releaseNotes, make install-wasm
draft: true,
prerelease: true - name: check wasm
}); run: |
console.log(response); curl -sSLo solc/soljson.js https://github.com/ethereum/solidity/releases/download/v0.8.28/soljson.js
return response.data.upload_url; node -e "
const soljson = require('solc/soljson');
- name: Log const createRevive = require('./target/wasm32-unknown-emscripten/release/resolc.js');
run: |
echo "tag result: ${{ needs.tag.outputs.TAG }}" const compiler = createRevive();
echo "pkg version: ${{ needs.tag.outputs.PKG_VER }}" compiler.soljson = soljson;
# const standardJsonInput =
# {
# language: 'Solidity',
upload-assets: sources: {
runs-on: ubuntu-24.04 'MyContract.sol': {
needs: [create-release] content: 'pragma solidity ^0.8.0; contract MyContract { function greet() public pure returns (string memory) { return \'Hello\'; } }',
steps: },
},
- name: Download Artifact settings: { optimizer: { enabled: false } }
uses: actions/download-artifact@v4 };
with:
name: revive-wasm compiler.writeToStdin(JSON.stringify(standardJsonInput));
path: resolc/ compiler.callMain(['--standard-json']);
- name: Download Artifact // Collect output
uses: actions/download-artifact@v4 const stdout = compiler.readFromStdout();
with: const stderr = compiler.readFromStderr();
name: revive-linux
path: resolc/ if (stderr) { console.error(stderr); process.exit(1); }
- name: upload resolc let out = JSON.parse(stdout);
uses: actions/upload-release-asset@v1 let bytecode = out.contracts['MyContract.sol']['MyContract'].evm.bytecode.object
env: console.log(bytecode);
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: if(!bytecode.startsWith('50564d')) { process.exit(1); }
upload_url: ${{ needs.create-release.outputs.upload_url }} "
asset_path: ./resolc/resolc
asset_name: resolc-static-linux - name: compress wasm artifact
asset_content_type: application/octet-stream run: |
tar --strip-components 3 -czf resolc-wasm.tar.gz \
- name: upload resolc.js ./target/wasm32-unknown-emscripten/release/resolc.js \
uses: actions/upload-release-asset@v1 ./target/wasm32-unknown-emscripten/release/resolc.wasm \
env: ./target/wasm32-unknown-emscripten/release/resolc_web.js
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: - uses: actions/upload-artifact@v4
upload_url: ${{ needs.create-release.outputs.upload_url }} with:
asset_path: ./resolc/resolc.js name: revive-wasm
asset_name: resolc.js path: |
asset_content_type: application/octet-stream resolc-wasm.tar.gz
retention-days: 1
- name: upload resolc.wasm
uses: actions/upload-release-asset@v1 create-release:
env: needs: [tag, build-linux-all, macos-universal-binary]
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} runs-on: ubuntu-24.04
with: permissions:
upload_url: ${{ needs.create-release.outputs.upload_url }} contents: write
asset_path: ./resolc/resolc.wasm outputs:
asset_name: resolc.wasm upload_url: ${{ steps.create_release.outputs.result }}
asset_content_type: application/octet-stream steps:
- name: Download revive-wasm
- name: upload resolc_web.js uses: actions/download-artifact@v4
uses: actions/upload-release-asset@v1 with:
env: name: revive-wasm
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} path: resolc-wasm/
with:
upload_url: ${{ needs.create-release.outputs.upload_url }} - name: Download revive-linux
asset_path: ./resolc/resolc_web.js uses: actions/download-artifact@v4
asset_name: resolc_web.js with:
asset_content_type: application/octet-stream name: revive-linux
path: resolc-linux/
- name: Download revive-macos
uses: actions/download-artifact@v4
with:
name: revive-macos
path: resolc-macos/
- name: create-release
uses: softprops/action-gh-release@v2
with:
body: ${{ needs.tag.outputs.RELEASE_NOTES }}
tag_name: ${{ needs.tag.outputs.PKG_VER }}
name: ${{ needs.tag.outputs.PKG_VER }}
draft: true
files: |
./resolc-linux/resolc-static-linux.tar.gz
./resolc-macos/resolc-macos.tar.gz
./resolc-wasm/resolc-wasm.tar.gz
+3 -1
View File
@@ -83,6 +83,7 @@ fn clone_build_and_clean_musl() -> anyhow::Result<()> {
/// This test verifies that the LLVM repository can be successfully cloned and built in debug mode /// This test verifies that the LLVM repository can be successfully cloned and built in debug mode
/// with tests and coverage enabled. /// with tests and coverage enabled.
#[test] #[test]
#[cfg(target_os = "linux")]
fn debug_build_with_tests_coverage() -> anyhow::Result<()> { fn debug_build_with_tests_coverage() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?; let test_dir = common::TestDir::with_lockfile(None)?;
@@ -107,6 +108,7 @@ fn debug_build_with_tests_coverage() -> anyhow::Result<()> {
/// This test verifies that the LLVM repository can be successfully built with address sanitizer. /// This test verifies that the LLVM repository can be successfully built with address sanitizer.
#[test] #[test]
#[cfg(target_os = "linux")]
fn build_with_sanitizers() -> anyhow::Result<()> { fn build_with_sanitizers() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?; let test_dir = common::TestDir::with_lockfile(None)?;
@@ -129,7 +131,7 @@ fn build_with_sanitizers() -> anyhow::Result<()> {
/// Tests the clone, build, and clean process of the LLVM repository for the emscripten target. /// Tests the clone, build, and clean process of the LLVM repository for the emscripten target.
#[test] #[test]
#[cfg(any(target_os = "linux", target_os = "macos"))] #[cfg(target_os = "linux")]
fn clone_build_and_clean_emscripten() -> anyhow::Result<()> { fn clone_build_and_clean_emscripten() -> anyhow::Result<()> {
let test_dir = common::TestDir::with_lockfile(None)?; let test_dir = common::TestDir::with_lockfile(None)?;
let command = Command::cargo_bin(common::REVIVE_LLVM)?; let command = Command::cargo_bin(common::REVIVE_LLVM)?;