Skip to content

Commit

Permalink
Compile windows runners in linux
Browse files Browse the repository at this point in the history
  • Loading branch information
coolreader18 committed Apr 28, 2021
1 parent 2c3ee0a commit 87194d4
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 55 deletions.
50 changes: 41 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,45 @@ env:
CARGO_TERM_COLOR: always

jobs:
compile_windows:
runs-on: ubuntu-latest

steps:
- run: curl https://get.wasmer.io -sSfL | sh

- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- run: aws s3 sync s3://${{ secrets.S3_BUCKET_PUBLIC }}/lang-runners lang-runners

- name: Compile windows runners
run: |
source ~/.wasmer/wasmer.sh
for runner in lang-runners/*.wasm; do
wasmer compile --target x86_64-pc-windows-msvc --llvm "$runner" -o "${runner/.wasm/.wjit}"
rm "$runner"
done
- uses: actions/upload-artifact@v2
with:
name: windows-runners
path: lang-runners/

build:
needs: compile_windows
runs-on: ${{ matrix.os }}-latest

strategy:
matrix:
os: [ubuntu, macos] #, windows]
include:
- os: ubuntu
cargoargs: --features build-llvm
- os: macos
cargoargs: --features build-llvm
- os: windows
cargoargs: ''

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -41,22 +74,21 @@ jobs:
- run: aws s3 sync s3://${{ secrets.S3_BUCKET_BUILD }}/cli-assets dist

- if: matrix.os == 'windows'
name: Install LLVM on windows
uses: actions/download-artifact@v2
with:
name: windows-runners
path: compiled_runners
- if: matrix.os == 'windows'
run: echo "COMPILED_RUNNERS=compiled_runners" >>$GITHUB_ENV
shell: bash
run: |
cargo install llvmenv
llvmenv init
llvmenv build-entry 11.0.0 -j4
llvmenv global 11.0.0
echo "LLVM_SYS_110_PREFIX=$(llvmenv prefix)" >> $GITHUB_ENV
- if: matrix.os == 'macos'
run: |
brew install llvm
echo "LLVM_SYS_110_PREFIX=$(brew --prefix llvm)" >> $GITHUB_ENV
- if: matrix.os == 'ubuntu'
run: sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"

- run: cargo build --release --no-default-features --features build-llvm
- run: cargo build --release --no-default-features ${{matrix.cargoargs}}
env:
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}

Expand Down
16 changes: 2 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

111 changes: 79 additions & 32 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,111 @@ use wasmer_compiler_cranelift::Cranelift as Compiler;
#[cfg(feature = "build-llvm")]
use wasmer_compiler_llvm::LLVM as Compiler;

use wasmer_engine::Artifact;
enum CompilationSource {
Precompiled(PathBuf),
#[cfg(any(feature = "build-cranelift", feature = "build-llvm"))]
Compiler {
engine: wasmer::JITEngine,
runners_dir: PathBuf,
jit_ext: &'static str,
tunables: wasmer::BaseTunables,
},
}

fn main() {
let mut features = wasmer::CpuFeature::set();
for feat in env::var("CARGO_CFG_TARGET_FEATURE").unwrap().split(',') {
if let Ok(feat) = feat.parse() {
features.insert(feat);
let source = match env::var_os("COMPILED_RUNNERS") {
Some(dir) => CompilationSource::Precompiled(fs::canonicalize(&dir).unwrap()),
#[cfg(not(any(feature = "build-cranelift", feature = "build-llvm")))]
None => {
panic!("need build-cranelift or build-llvm or the COMPILED_RUNNERS env var")
}
}
let target = wasmer::Target::new(env::var("TARGET").unwrap().parse().unwrap(), features);
let tunables = wasmer::BaseTunables::for_target(&target);
let jit_ext = wasmer::JITArtifact::get_default_extension(target.triple());
let engine = wasmer::JIT::new(Compiler::new()).target(target).engine();
#[cfg(any(feature = "build-cranelift", feature = "build-llvm"))]
None => {
let mut features = wasmer::CpuFeature::set();
for feat in env::var("CARGO_CFG_TARGET_FEATURE").unwrap().split(',') {
if let Ok(feat) = feat.parse() {
features.insert(feat);
}
}
let target =
wasmer::Target::new(env::var("TARGET").unwrap().parse().unwrap(), features);
let tunables = wasmer::BaseTunables::for_target(&target);
let jit_ext = wasmer::JITArtifact::get_default_extension(target.triple());
let engine = wasmer::JIT::new(Compiler::new()).target(target).engine();

let runners_dir = fs::canonicalize("../logic/wasm-dist/lang-runners")
.expect("need to run logic/build-wasm.sh");

CompilationSource::Compiler {
engine,
runners_dir,
jit_ext,
tunables,
}
}
};

let lang_runners = [("Python", "pyrunner"), ("Javascript", "jsrunner")];

let runners_dir = fs::canonicalize("../logic/wasm-dist/lang-runners")
.expect("need to run logic/build-wasm.sh");
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());

let mut match_lang = fs::File::create(out_dir.join("lang_runners.rs")).unwrap();
writeln!(match_lang, "match lang {{").unwrap();

for (lang, runner) in &lang_runners {
let mut src = runners_dir.join(runner);
src.set_extension("wasm");
let mut dst = out_dir.join(runner);
dst.set_extension(jit_ext);
let (path, include_bin) = match &source {
CompilationSource::Precompiled(dir) => {
let mut wjit = dir.join(runner);
wjit.set_extension("wjit");
(wjit, true)
}
#[cfg(any(feature = "build-cranelift", feature = "build-llvm"))]
CompilationSource::Compiler {
engine,
runners_dir,
jit_ext,
tunables,
} => {
use wasmer_engine::Artifact;

println!("compiling {}", runner);
let mut src = runners_dir.join(runner);
src.set_extension("wasm");
let mut dst = out_dir.join(runner);
dst.set_extension(*jit_ext);

println!("cargo:rerun-if-changed={}", src.display());
println!("compiling {}", runner);

let needs_updating = src
.metadata()
.and_then(|m| Ok((m, dst.metadata()?)))
.and_then(|(src, dst)| Ok(src.modified()? > dst.modified()?))
.unwrap_or(true);
println!("cargo:rerun-if-changed={}", src.display());

if needs_updating {
let wasm_source = fs::read(&src).unwrap();
let artifact = wasmer::JITArtifact::new(&engine, &wasm_source, &tunables).unwrap();
let needs_updating = src
.metadata()
.and_then(|m| Ok((m, dst.metadata()?)))
.and_then(|(src, dst)| Ok(src.modified()? > dst.modified()?))
.unwrap_or(true);

fs::write(&dst, artifact.serialize().unwrap()).unwrap();
}
if needs_updating {
let wasm_source = fs::read(&src).unwrap();
let artifact =
wasmer::JITArtifact::new(engine, &wasm_source, tunables).unwrap();

fs::write(&dst, artifact.serialize().unwrap()).unwrap();
}

(dst, cfg!(feature = "build-llvm"))
}
};

writeln!(
match_lang,
" Lang::{} => lang_runner!({}({:?}){}),",
lang,
//
if cfg!(feature = "build-llvm") {
if include_bin {
"include_bytes!"
} else {
"&std::fs::read"
},
dst,
if cfg!(feature = "build-llvm") {
path,
if include_bin {
""
} else {
r#".expect("should compile with --features=build-llvm when distributing")"#
Expand Down

0 comments on commit 87194d4

Please sign in to comment.