Skip to content

Commit

Permalink
Arm support (#11)
Browse files Browse the repository at this point in the history
* build updates for arm
* add travis
* readme update
* always enable rust crypto on travis for now
  • Loading branch information
franziskuskiefer authored Oct 14, 2020
1 parent eaa7ab2 commit 581e505
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 49 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/evercrypt-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ jobs:
run: |
cd evercrypt-rs
cargo build --verbose --release
- if: matrix.os == 'macos-latest' # Broken on Ubuntu for some reason right now
name: Test evercrypt-sys
- name: Test evercrypt-sys
run: |
cd evercrypt-sys
cargo test --verbose
Expand Down
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
language: rust
rust:
- stable
- nightly
arch:
- amd64
- arm64
jobs:
allow_failures:
- rust: nightly
fast_finish: true
include:
- name: Aarch64
os: linux
arch: arm64
dist: bionic
- name: Linux
os: linux
- name: MacOS (xcode12)
os: osx
osx_image: xcode12
# - name: Windows (vs2017)
# os: windows
script:
- cd evercrypt-sys
- cargo build --verbose
- cargo test --verbose
- cd ../evercrypt-rs
- cargo build --verbose --features rust-crypto-aes
- cargo test --verbose --features rust-crypto-aes
7 changes: 5 additions & 2 deletions evercrypt-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "evercrypt"
version = "0.0.2"
version = "0.0.3-dev"
authors = ["Franziskus Kiefer <[email protected]>"]
edition = "2018"
license = "MPL-2.0"
Expand All @@ -20,11 +20,14 @@ force-rust-crypto-aes = ["rust-crypto-aes"]
random = ["rand", "rand_core"]

[dependencies]
evercrypt-sys = { path = "../evercrypt-sys", version = "0.0.2" }
evercrypt-sys = { version = "0.0.3-dev" }
aes-gcm = { version = "0.6", optional = true }
rand = { version = "0.7", optional = true }
rand_core = { version = "0.5", optional = true }

[patch.crates-io]
evercrypt-sys = { path = "../evercrypt-sys" }

[dev-dependencies]
serde_json = "1.0"
serde = {version = "1.0", features = ["derive"]}
Expand Down
18 changes: 9 additions & 9 deletions evercrypt-rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ To provide AES for other platforms the Evercrypt crate uses the [RustCrypto](htt

## Platforms
Currently only Linux x64 and MacOS are supported.
Windows and ARM builds are on the To Do list and should be supported in future.

| Platform | Supported |
| :------- | :-----------------------------------------------------------------: |
| MacOS ||
| Linux ||
| Windows |[#3](https://github.com/franziskuskiefer/evercrypt-rust/issues/3) |
| Arm64 |[#7](https://github.com/franziskuskiefer/evercrypt-rust/issues/7) |
| Arm32 |[#7](https://github.com/franziskuskiefer/evercrypt-rust/issues/7) |
Windows builds are on the To Do list and should be supported in future.

| Platform | Supported |
| :---------- | :-----------------------------------------------------------------: |
| MacOS ||
| Linux ||
| Windows |[#3](https://github.com/franziskuskiefer/evercrypt-rust/issues/3) |
| Arm64 Linux | |
| Arm32 Linux | |


## Benchmarks
Expand Down
2 changes: 1 addition & 1 deletion evercrypt-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "evercrypt-sys"
version = "0.0.2"
version = "0.0.3-dev"
authors = ["Franziskus Kiefer <[email protected]>"]
edition = "2018"
build = "build.rs"
Expand Down
16 changes: 8 additions & 8 deletions evercrypt-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ The hacl/evercrypt build is currently not part of the `cargo build`.
Run `build-evercrypt.sh` in order to build the `gcc-compatible` dist (this requires OCAML to be set up.).

### Platforms
Windows and ARM support is on the todo list.
Windows support is on the To Do list.

| Platform | Supported |
| :------- | :-----------------------------------------------------------------: |
| MacOS ||
| Linux ||
| Windows |[#3](https://github.com/franziskuskiefer/evercrypt-rust/issues/3) |
| Arm64 |[#7](https://github.com/franziskuskiefer/evercrypt-rust/issues/7) |
| Arm32 |[#7](https://github.com/franziskuskiefer/evercrypt-rust/issues/7) |
| Platform | Supported |
| :---------- | :-----------------------------------------------------------------: |
| MacOS ||
| Linux ||
| Windows |[#3](https://github.com/franziskuskiefer/evercrypt-rust/issues/3) |
| Arm64 Linux | |
| Arm32 Linux | |
123 changes: 97 additions & 26 deletions evercrypt-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
extern crate bindgen;

use std::{env, fs, path::Path, path::PathBuf, process::Command};
use std::{collections::HashMap, env, fs, path::Path, path::PathBuf, process::Command};

// TODO: add ARM builds

#[cfg(windows)]
fn build_hacl() {
fn build_hacl(lib_dir: &Path, build_config: &BuildConfig) {
// TODO: add Windows builds
panic!("Windows builds are not supported yet. Sorry!");
}

#[cfg(not(windows))]
fn build_hacl(lib_dir: &Path) {
fn build_hacl(lib_dir: &Path, build_config: &BuildConfig) {
// Run configure
// TODO: add config for iOS and Android
let mut configure_cmd = Command::new(
fs::canonicalize(lib_dir.join("configure")).expect("Failed to find configure script!"),
);
let configure_status = configure_cmd
.current_dir(lib_dir)
.args(&build_config.config_flags)
.arg("--disable-ocaml")
.envs(build_config.env.clone())
.status()
.expect("Failed to run configure");
if !configure_status.success() {
panic!("Failed to run configure.")
}

// Make a clean build.
// This might fail but we don't care.
let mut make_cmd = Command::new("make");
let _make_status = make_cmd.current_dir(lib_dir).arg("clean").status();

// Run make
let mut make_cmd = Command::new("make");
if !build_config.make_flags.is_empty() {
make_cmd.args(&build_config.make_flags);
}
let make_status = make_cmd
.current_dir(lib_dir)
.arg("-j")
.arg("libevercrypt.a")
.env("DISABLE_OCAML_BINDINGS", "1")
.status()
.expect("Failed to run make");
Expand Down Expand Up @@ -61,6 +72,53 @@ fn copy_hacl_to_out(out_dir: &Path) {

struct BuildConfig {
hacl_src_dir: &'static str,
cross: bool,
config_flags: Vec<&'static str>,
make_flags: Vec<&'static str>,
env: HashMap<String, String>,
}

#[allow(dead_code)]
impl BuildConfig {
fn new(hacl_src_dir: &'static str, cross: bool) -> Self {
Self {
hacl_src_dir,
cross,
config_flags: vec![],
make_flags: vec![],
env: HashMap::new(),
}
}
fn set_config_flags(&mut self, config_flags: Vec<&'static str>) -> &mut Self {
self.config_flags = config_flags;
self
}
fn set_cross_config_flags(&mut self, config_flags: Vec<&'static str>) -> &mut Self {
if self.cross {
self.config_flags = config_flags;
}
self
}
fn set_make_flags(&mut self, make_flags: Vec<&'static str>) -> &mut Self {
self.make_flags = make_flags;
self
}
fn set_cross_make_flags(&mut self, make_flags: Vec<&'static str>) -> &mut Self {
if self.cross {
self.make_flags = make_flags;
}
self
}
fn set_env(&mut self, env: HashMap<String, String>) -> &mut Self {
self.env = env;
self
}
fn set_cross_env(&mut self, env: HashMap<String, String>) -> &mut Self {
if self.cross {
self.env = env;
}
self
}
}

fn main() {
Expand All @@ -74,21 +132,34 @@ fn main() {
let out_path = Path::new(&out_dir);
let profile = env::var("PROFILE").unwrap();
let target = env::var("TARGET").unwrap();
let host = env::var("HOST").unwrap();
let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string());
let _target_path = Path::new(&home_dir)
.join("..")
.join(&target_dir)
.join(&profile);

let cross = target != host;
// Pre-populate config with some commonly used values.
let mut cfg = BuildConfig::new("gcc-compatible", cross);

// Make sure we can build for the given OS and architecture.
let build_config = match target.as_str() {
// No 32-bit support on any platform for now.
"x86_64-apple-darwin" => BuildConfig {
hacl_src_dir: "gcc-compatible",
},
"x86_64-unknown-linux-gnu" => BuildConfig {
hacl_src_dir: "gcc-compatible",
},
"x86_64-apple-darwin" => cfg.set_cross_config_flags(vec!["-target", "x86_64-apple-darwin"]),
"x86_64-unknown-linux-gnu" => {
cfg.set_cross_config_flags(vec!["-target", "x86_64-unknown-linux-gnu"])
}
// ARM32 v7 (e.g. raspberry pi 3)
// TODO: set TOOLCHAIN
"armv7-unknown-linux-gnueabihf" => {
cfg.set_cross_config_flags(vec!["-target", "arm32-none-linux-gnu"])
}
// ARM64 Linux
// TODO: set TOOLCHAIN
"aarch64-unknown-linux-gnu" => {
cfg.set_cross_config_flags(vec!["-target", "aarch64-none-linux-gnu"])
}
// Only MSVC builds are supported on Windows.
"x86_64-pc-windows-msvc" => panic!("Target '{:?}' is not supported yet.", target),
// TODO: Which Android versions do we want to support?
Expand All @@ -104,31 +175,31 @@ fn main() {
let mode = "static";
let name = "evercrypt";

let hacl_src_path_str = hacl_src_path.to_str().unwrap();

// Set up rustc link environment
println!(
"cargo:rustc-link-search=native={}",
hacl_src_path.to_str().unwrap()
);
println!("cargo:rustc-link-search=native={}", hacl_src_path_str);
println!("cargo:rustc-link-lib={}={}", mode, name);
println!(
"cargo:rustc-env=DYLD_LIBRARY_PATH={}",
hacl_src_path.to_str().unwrap()
);
println!(
"cargo:rustc-env=LD_LIBRARY_PATH={}",
hacl_src_path.to_str().unwrap()
);
println!("cargo:rustc-env=DYLD_LIBRARY_PATH={}", hacl_src_path_str);
println!("cargo:rustc-env=LD_LIBRARY_PATH={}", hacl_src_path_str);

// HACL/Evercrypt header paths
let kremlin_include = hacl_dir.join("dist").join("kremlin").join("include");
let kremlib_minimal = hacl_dir
.join("dist")
.join("kremlin")
.join("kremlib")
.join("dist")
.join("minimal");
let hacl_includes = vec![
"-Ihacl-star/dist/".to_owned() + build_config.hacl_src_dir,
"-Ihacl-star/dist/kremlin/include".to_string(),
"-Ihacl-star/dist/kremlin/kremlib/dist/minimal".to_string(),
"-I".to_owned() + hacl_src_path_str,
"-I".to_owned() + kremlin_include.to_str().unwrap(),
"-I".to_owned() + kremlib_minimal.to_str().unwrap(),
];

// Build hacl/evercrypt
copy_hacl_to_out(&out_path);
build_hacl(&hacl_src_path);
build_hacl(&hacl_src_path, &build_config);

let bindings = bindgen::Builder::default()
// Header to wrap HACL/Evercrypt headers
Expand Down
2 changes: 1 addition & 1 deletion evercrypt-sys/hacl-star

0 comments on commit 581e505

Please sign in to comment.