Skip to content

Commit

Permalink
Maybe fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
milesgranger committed Sep 21, 2024
1 parent c332620 commit 0577a6c
Show file tree
Hide file tree
Showing 7 changed files with 2,290 additions and 127 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: CI

on:
pull_request:
push:
branches:
- main
release:
types:
- released
- prereleased

jobs:
test-cross:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-musl
- s390x-unknown-linux-gnu
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross --rev 6d097fb

- name: Test
run: cross test --target ${{ matrix.target }} --release

test-wasm32-emscripten:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
build: [static, shared]
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-unknown-emscripten

- name: Install build deps
run: sudo apt install nasm gcc-multilib

- name: Install Emscripten
uses: mymindstorm/setup-emsdk@v14

- name: Build
run: cargo build --target wasm32-unknown-emscripten --no-default-features --features regenerate-bindings --features ${{ matrix.build }}

test-native:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-13 # x86_64
- macos-14 # M1
- windows-latest
- ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install nasm
uses: ilammy/setup-nasm@v1

- name: Set MSVC developer prompt
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1.6.0

- name: Test (shared)
run: cargo test --features shared --lib --release

- name: Test (static)
run: |
cargo clean # ensure we're starting fresh, no funny business
cargo test --no-default-features --features static --release
74 changes: 0 additions & 74 deletions .github/workflows/ci.yml

This file was deleted.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ edition = "2021"
[lib]
name = "isal"

[features]
default = ["static"]
static = ["isal-sys/static"]
shared = ["isal-sys/shared"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
isal-sys = { path = "isal-sys" }
isal-sys = { path = "isal-sys"}

[dev-dependencies]
criterion = "0.3"
Expand Down
12 changes: 10 additions & 2 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
[build]
pre-build = ["apt update && apt install -y llvm-dev libclang-dev clang"] # required by cbindgen
[target.x86_64-unknown-linux-musl]
pre-build = [
"apt update",
"apt install -y llvm-dev libclang-dev clang nasm"
]
[target.s390x-unknown-linux-gnu]
pre-build = [
"apt update",
"apt install -y llvm-dev libclang-dev clang nasm"
]
2 changes: 1 addition & 1 deletion isal-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0+62519d9"
edition = "2021"

[features]
default = ["static", "regenerate-bindings"]
default = ["static"]
static = []
shared = []

Expand Down
137 changes: 89 additions & 48 deletions isal-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,60 +1,101 @@
#[cfg(feature = "regenerate-bindings")]
use std::path::PathBuf;
use std::{
io::{self, Write},
path::Path,
process::{Command, Stdio},
};

fn main() {
println!("cargo:rerun-if-changed=build.rs");

{
let out_dir_str = std::env::var("OUT_DIR").unwrap();
let out_dir = Path::new(&out_dir_str);

let src_dir = out_dir.join("isa-l");
if !src_dir.exists() {
copy_dir::copy_dir("isa-l", &src_dir).unwrap();
}

let install_path_str =
std::env::var("ISAL_INSTALL_PREFIX").unwrap_or(out_dir_str.to_owned());
let install_path = Path::new(&install_path_str).join("isa-l");

let current_dir = std::env::current_dir().unwrap();
std::env::set_current_dir(&install_path).unwrap();

// TODO: support 'nmake' for windows and aarch64 target
let cmd = Command::new("make")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.args([
"install",
&format!("prefix={}", install_path.display()),
"-f",
"Makefile.unx",
&format!("CFLAGS_=-fPIC -O3"),
])
.spawn();
std::env::set_current_dir(&current_dir).unwrap();

let output = cmd.unwrap().wait_with_output().unwrap();
io::stdout().write_all(&output.stdout).unwrap();
io::stderr().write_all(&output.stderr).unwrap();
if !output.status.success() {
panic!("Building isa-l failed");
}

// Solves undefined reference to __cpu_model when using __builtin_cpu_supports() in shuffle.c
if let Ok(true) = std::env::var("CARGO_CFG_TARGET_ENV").map(|v| v == "musl") {
println!("cargo:rustc-link-lib=gcc");
}

for subdir in ["bin", "lib", "lib64"] {
let search_path = install_path.join(subdir);
println!("cargo:rustc-link-search=native={}", search_path.display());
}
let is_static = cfg!(feature = "static");
let is_shared = cfg!(feature = "shared");
let target = std::env::var("TARGET").unwrap();
let profile = std::env::var("PROFILE").unwrap();
let out_dir = PathBuf::from(&std::env::var("OUT_DIR").unwrap());

// Copy isa-l source into out; not allow to modify things outside of out dir
let src_dir = out_dir.join("isa-l");
if src_dir.exists() {
std::fs::remove_dir_all(&src_dir).unwrap(); // maybe from a previous build
}
copy_dir::copy_dir("isa-l", &src_dir).unwrap();

let install_path = std::env::var("ISAL_INSTALL_PREFIX")
.map(|p| PathBuf::from(&p).clone())
.unwrap_or(out_dir.clone())
.join("isa-l");

let current_dir = std::env::current_dir().unwrap();
std::env::set_current_dir(&install_path).unwrap();

let status = Command::new("./autogen.sh")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()
.unwrap();
io::stdout().write_all(&status.stdout).unwrap();
io::stderr().write_all(&status.stderr).unwrap();
if !status.status.success() {
panic!("autogen failed");
}

let mut configure_args = vec![
format!("--prefix={}", install_path.display()),
format!("--enable-static={}", if is_static { "yes" } else { "no" }),
format!("--enable-shared={}", if is_shared { "yes" } else { "no" }),
format!("--host={}", target),
format!("LDFLAGS=-{}", if is_static { "static" } else { "shared" }),
"--with-pic=yes".to_string(),
];
if target.starts_with("wasm32") {
configure_args.push("CC=emcc".to_string());
}
if profile == "release" {
configure_args.push("CFLAGS=-g -O3".to_string());
} else {
configure_args.push("CFLAGS=-g -O1".to_string());
}

let status = Command::new("./configure")
.args(&configure_args)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()
.unwrap();
io::stdout().write_all(&status.stdout).unwrap();
io::stderr().write_all(&status.stderr).unwrap();
if !status.status.success() {
panic!("configure failed");
}

let mut cmd = if cfg!(target_os = "windows") {
Command::new("nmake")
} else {
Command::new("make")
};

let cmd = cmd
.args(["install-libLTLIBRARIES"])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn();

std::env::set_current_dir(&current_dir).unwrap();

let output = cmd.unwrap().wait_with_output().unwrap();
io::stdout().write_all(&output.stdout).unwrap();
io::stderr().write_all(&output.stderr).unwrap();
if !output.status.success() {
panic!("Building isa-l failed");
}

if let Ok(true) = std::env::var("CARGO_CFG_TARGET_ENV").map(|v| v == "musl") {
println!("cargo:rustc-link-lib=gcc");
}

for subdir in ["bin", "lib", "lib64"] {
let search_path = install_path.join(subdir);
println!("cargo:rustc-link-search=native={}", search_path.display());
}

#[allow(unused_variables)]
Expand Down
Loading

0 comments on commit 0577a6c

Please sign in to comment.