Skip to content

Commit

Permalink
Move to using the same cross-compiling workflow as wasmtime which ena…
Browse files Browse the repository at this point in the history
…bles binary compatible builds and compiles for more platforms

These prebuilt binaries will eventually be used within a wizer npm package (which itself will be used within the `@fastly/js-compute` npm package).

I've tested both the macos builds and they are working
I don't have a windows machine to test on and I don't have an x86_64 linux machine to test on unfortunately

aarch64-linux and s390x-linux are commented out due to build errors these errors are solved in a newer version of wasmtime, when wizer updates to the newer wasmtime then we should uncomment these builds
  • Loading branch information
Jake Champion authored and JakeChampion committed Nov 3, 2022
1 parent 7e9855a commit d3f5d04
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 179 deletions.
9 changes: 9 additions & 0 deletions .github/actions/binary-compatible-builds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# binary-compatible-builds

A small (ish) action which is intended to be used and will configure builds of
Rust projects to be "more binary compatible". On Windows and macOS this
involves setting a few env vars, and on Linux this involves spinning up a CentOS
6 container which is running in the background.

All subsequent build commands need to be wrapped in `$CENTOS` to optionally run
on `$CENTOS` on Linux to ensure builds happen inside the container.
10 changes: 10 additions & 0 deletions .github/actions/binary-compatible-builds/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: 'Set up a CentOS 6 container to build releases in'
description: 'Set up a CentOS 6 container to build releases in'

runs:
using: node12
main: 'main.js'
inputs:
name:
required: true
description: "Name of the build"
56 changes: 56 additions & 0 deletions .github/actions/binary-compatible-builds/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env node

const child_process = require('child_process');
const stdio = { stdio: 'inherit' };
const fs = require('fs');

function set_env(name, val) {
fs.appendFileSync(process.env['GITHUB_ENV'], `${name}=${val}\n`)
}

// On OSX all we need to do is configure our deployment target as old as
// possible. For now 10.9 is the limit.
if (process.platform == 'darwin') {
set_env("MACOSX_DEPLOYMENT_TARGET", "10.9");
return;
}

// On Windows we build against the static CRT to reduce dll dependencies
if (process.platform == 'win32') {
set_env("RUSTFLAGS", "-Ctarget-feature=+crt-static");
return;
}

// ... and on Linux we do fancy things with containers. We'll spawn an old
// CentOS container in the background with a super old glibc, and then we'll run
// commands in there with the `$CENTOS` env var.

if (process.env.CENTOS !== undefined) {
const args = ['exec', '-w', process.cwd(), '-i', 'build-container'];
for (const arg of process.argv.slice(2)) {
args.push(arg);
}
child_process.execFileSync('docker', args, stdio);
return;
}

const name = process.env.INPUT_NAME;

child_process.execFileSync('docker', [
'build',
'--tag', 'build-image',
`${process.cwd()}/ci/docker/${name}`
], stdio);

child_process.execFileSync('docker', [
'run',
'--detach',
'--interactive',
'--name', 'build-container',
'-v', `${process.cwd()}:${process.cwd()}`,
'-v', `${child_process.execSync('rustc --print sysroot').toString().trim()}:/rust:ro`,
'build-image',
], stdio);

// Use ourselves to run future commands
set_env("CENTOS", __filename);
18 changes: 18 additions & 0 deletions .github/actions/install-rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# install-rust

A small github action to install `rustup` and a Rust toolchain. This is
generally expressed inline, but it was repeated enough in this repository it
seemed worthwhile to extract.

Some gotchas:

* Can't `--self-update` on Windows due to permission errors (a bug in Github
Actions)
* `rustup` isn't installed on macOS (a bug in Github Actions)

When the above are fixed we should delete this action and just use this inline:

```yml
- run: rustup update $toolchain && rustup default $toolchain
shell: bash
```
12 changes: 12 additions & 0 deletions .github/actions/install-rust/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'Install Rust toolchain'
description: 'Install both `rustup` and a Rust toolchain'

inputs:
toolchain:
description: 'Default toolchan to install'
required: false
default: 'stable'

runs:
using: node12
main: 'main.js'
36 changes: 36 additions & 0 deletions .github/actions/install-rust/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const child_process = require('child_process');
const toolchain = process.env.INPUT_TOOLCHAIN;
const fs = require('fs');

function set_env(name, val) {
fs.appendFileSync(process.env['GITHUB_ENV'], `${name}=${val}\n`)
}

// Needed for now to get 1.24.2 which fixes a bug in 1.24.1 that causes issues
// on Windows.
if (process.platform === 'win32') {
child_process.execFileSync('rustup', ['self', 'update']);
}

child_process.execFileSync('rustup', ['set', 'profile', 'minimal']);
child_process.execFileSync('rustup', ['update', toolchain, '--no-self-update']);
child_process.execFileSync('rustup', ['default', toolchain]);

// Deny warnings on CI to keep our code warning-free as it lands in-tree. Don't
// do this on nightly though since there's a fair amount of warning churn there.
if (!toolchain.startsWith('nightly')) {
set_env("RUSTFLAGS", "-D warnings");
}

// Save disk space by avoiding incremental compilation, and also we don't use
// any caching so incremental wouldn't help anyway.
set_env("CARGO_INCREMENTAL", "0");

// Turn down debuginfo from 2 to 1 to help save disk space
set_env("CARGO_PROFILE_DEV_DEBUG", "1");
set_env("CARGO_PROFILE_TEST_DEBUG", "1");

if (process.platform === 'darwin') {
set_env("CARGO_PROFILE_DEV_SPLIT_DEBUGINFO", "unpacked");
set_env("CARGO_PROFILE_TEST_SPLIT_DEBUGINFO", "unpacked");
}
91 changes: 7 additions & 84 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
on: pull_request

env:
CARGO_TERM_COLOR: always
Expand All @@ -19,8 +15,14 @@ jobs:
os: ubuntu-latest
- build: x86_64-macos
os: macos-latest
- build: aarch64-macos
os: macos-latest
target: aarch64-apple-darwin
- build: x86_64-windows
os: windows-latest
- build: x86_64-mingw
os: windows-latest
target: x86_64-pc-windows-gnu
steps:
- uses: actions/checkout@v2
- name: Build
Expand All @@ -29,22 +31,6 @@ jobs:
run: cargo test --verbose
- name: Checking benches
run : cargo check --benches
- name: Build release binary
run: cargo build --release --bin wizer --features="env_logger structopt"

- name: Create dist
run: mkdir dist

# Move binaries to dist folder
- run: cp target/release/wizer dist
if: matrix.os != 'windows-latest' && matrix.target == ''
- run: cp target/release/wizer.exe dist
if: matrix.build == 'x86_64-windows'

- uses: actions/upload-artifact@v1
with:
name: bins-${{ matrix.build }}
path: dist

check_fuzz:
runs-on: ubuntu-latest
Expand All @@ -61,66 +47,3 @@ jobs:
- run: rustup default stable
- run: rustup component add rustfmt
- run: cargo fmt --all -- --check


# Consumes all published artifacts from all the previous build steps, creates
# a bunch of tarballs for all of them, and then publishes the tarballs
# themselves as an artifact (for inspection) and then optionally creates
# github releases and/or tags for pushes.
publish:
name: Publish
needs: [build, rustfmt]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# Download all the artifacts that we'll be publishing. Should keep an eye on
# the `download-artifact` repository to see if we can ever get something
# like "download all artifacts" or "download this list of artifacts"
- name: Download x86_64 macOS binaries
uses: actions/download-artifact@v1
with:
name: bins-x86_64-macos
- name: Download x86_64 Linux binaries
uses: actions/download-artifact@v1
with:
name: bins-x86_64-linux
- name: Download x86_64 Windows binaries
uses: actions/download-artifact@v1
with:
name: bins-x86_64-windows

- name: Calculate tag name
run: |
name=dev
if [[ $GITHUB_REF == refs/tags/v* ]]; then
name=${GITHUB_REF:10}
fi
echo ::set-output name=val::$name
echo TAG=$name >> $GITHUB_ENV
id: tagname

# Assemble all the build artifacts into tarballs and zip archives.
- name: Assemble tarballs
run: |
./ci/build-tarballs.sh x86_64-linux
./ci/build-tarballs.sh x86_64-macos
./ci/build-tarballs.sh x86_64-windows .exe
# Upload all assembled tarballs as an artifact of the github action run, so
# that way even PRs can inspect the output.
- uses: actions/upload-artifact@v1
with:
name: tarballs
path: dist

# ... and if this was an actual push (tag or `main`) then we publish a
# new release. This'll automatically publish a tag release or update `dev`
# with this `sha`
- name: Publish Release
uses: ./.github/actions/github-release
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
with:
files: "dist/*"
name: ${{ steps.tagname.outputs.val }}
token: ${{ secrets.GITHUB_TOKEN }}
Loading

0 comments on commit d3f5d04

Please sign in to comment.