-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from bytecodealliance/cfallin/initial
weval: initial Bytecode Alliance-hosted version.
- Loading branch information
Showing
47 changed files
with
10,342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: 'Set up an AlmaLinux 8 container to build releases in' | ||
description: 'Set up an AlmaLinux 8 container to build releases in' | ||
|
||
runs: | ||
using: node12 | ||
main: 'main.js' | ||
inputs: | ||
name: | ||
required: true | ||
description: "Name of the build" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM node:slim | ||
|
||
COPY . /action | ||
WORKDIR /action | ||
|
||
RUN npm install --production | ||
|
||
ENTRYPOINT ["node", "/action/main.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# github-release | ||
|
||
An action used to publish GitHub releases for `wizer`, copied from Wasmtime's CI setup. | ||
|
||
As of the time of this writing there's a few actions floating around which | ||
perform github releases but they all tend to have their set of drawbacks. | ||
Additionally nothing handles deleting releases which we need for our rolling | ||
`dev` release. | ||
|
||
To handle all this this action rolls-its-own implementation using the | ||
actions/toolkit repository and packages published there. These run in a Docker | ||
container and take various inputs to orchestrate the release from the build. | ||
|
||
More comments can be found in `main.js`. | ||
|
||
Testing this is really hard. If you want to try though run `npm install` and | ||
then `node main.js`. You'll have to configure a bunch of env vars though to get | ||
anything reasonably working. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: 'Wizer github releases' | ||
description: 'Wizer github releases' | ||
inputs: | ||
token: | ||
description: '' | ||
required: true | ||
name: | ||
description: '' | ||
required: true | ||
files: | ||
description: '' | ||
required: true | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
const core = require('@actions/core'); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const github = require('@actions/github'); | ||
const glob = require('glob'); | ||
|
||
function sleep(milliseconds) { | ||
return new Promise(resolve => setTimeout(resolve, milliseconds)) | ||
} | ||
|
||
async function runOnce() { | ||
// Load all our inputs and env vars. Note that `getInput` reads from `INPUT_*` | ||
const files = core.getInput('files'); | ||
const name = core.getInput('name'); | ||
const token = core.getInput('token'); | ||
const slug = process.env.GITHUB_REPOSITORY; | ||
const owner = slug.split('/')[0]; | ||
const repo = slug.split('/')[1]; | ||
const sha = process.env.GITHUB_SHA; | ||
|
||
core.info(`files: ${files}`); | ||
core.info(`name: ${name}`); | ||
core.info(`token: ${token}`); | ||
|
||
const octokit = new github.GitHub(token); | ||
|
||
// Delete the previous release since we can't overwrite one. This may happen | ||
// due to retrying an upload or it may happen because we're doing the dev | ||
// release. | ||
const releases = await octokit.paginate("GET /repos/:owner/:repo/releases", { owner, repo }); | ||
for (const release of releases) { | ||
if (release.tag_name !== name) { | ||
continue; | ||
} | ||
const release_id = release.id; | ||
core.info(`deleting release ${release_id}`); | ||
await octokit.repos.deleteRelease({ owner, repo, release_id }); | ||
} | ||
|
||
// We also need to update the `dev` tag while we're at it on the `dev` branch. | ||
if (name == 'dev') { | ||
try { | ||
core.info(`updating dev tag`); | ||
await octokit.git.updateRef({ | ||
owner, | ||
repo, | ||
ref: 'tags/dev', | ||
sha, | ||
force: true, | ||
}); | ||
} catch (e) { | ||
console.log("ERROR: ", JSON.stringify(e, null, 2)); | ||
core.info(`creating dev tag`); | ||
await octokit.git.createTag({ | ||
owner, | ||
repo, | ||
tag: 'dev', | ||
message: 'dev release', | ||
object: sha, | ||
type: 'commit', | ||
}); | ||
} | ||
} | ||
|
||
// Creates an official GitHub release for this `tag`, and if this is `dev` | ||
// then we know that from the previous block this should be a fresh release. | ||
core.info(`creating a release`); | ||
const release = await octokit.repos.createRelease({ | ||
owner, | ||
repo, | ||
tag_name: name, | ||
prerelease: name === 'dev', | ||
}); | ||
|
||
// Upload all the relevant assets for this release as just general blobs. | ||
for (const file of glob.sync(files)) { | ||
const size = fs.statSync(file).size; | ||
core.info(`upload ${file}`); | ||
await octokit.repos.uploadReleaseAsset({ | ||
data: fs.createReadStream(file), | ||
headers: { 'content-length': size, 'content-type': 'application/octet-stream' }, | ||
name: path.basename(file), | ||
url: release.data.upload_url, | ||
}); | ||
} | ||
} | ||
|
||
async function run() { | ||
const retries = 10; | ||
for (let i = 0; i < retries; i++) { | ||
try { | ||
await runOnce(); | ||
break; | ||
} catch (e) { | ||
if (i === retries - 1) | ||
throw e; | ||
logError(e); | ||
console.log("RETRYING after 10s"); | ||
await sleep(10000) | ||
} | ||
} | ||
} | ||
|
||
function logError(e) { | ||
console.log("ERROR: ", e.message); | ||
try { | ||
console.log(JSON.stringify(e, null, 2)); | ||
} catch (e) { | ||
// ignore json errors for now | ||
} | ||
console.log(e.stack); | ||
} | ||
|
||
run().catch(err => { | ||
logError(err); | ||
core.setFailed(err.message); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "wizer-github-release", | ||
"version": "0.0.0", | ||
"main": "main.js", | ||
"dependencies": { | ||
"@actions/core": "^1.0.0", | ||
"@actions/github": "^1.0.0", | ||
"glob": "^7.1.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: CI | ||
|
||
on: pull_request | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
include: | ||
- build: x86_64-linux | ||
os: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build | ||
run: cargo build --verbose | ||
- name: Run tests | ||
run: cargo test --verbose | ||
|
||
rustfmt: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: rustup update stable --no-self-update | ||
- run: rustup default stable | ||
- run: rustup component add rustfmt | ||
- run: cargo fmt --all -- --check |
Oops, something went wrong.