Skip to content

Use bindgen to automatically generate boring-sys #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
os: ubuntu-latest
- thing: i686-msvc
target: i686-pc-windows-msvc
rust: stable-i686-msvc
rust: stable-x86_64-msvc
os: windows-latest
- thing: x86_64-msvc
target: x86_64-pc-windows-msvc
Expand All @@ -143,10 +143,19 @@ jobs:
if: startsWith(matrix.os, 'windows')
run: choco install nasm
shell: cmd
- name: Install LLVM and Clang
if: startsWith(matrix.os, 'windows')
uses: KyleMayes/install-llvm-action@v1
with:
version: "11.0"
directory: ${{ runner.temp }}/llvm
- name: Set LIBCLANG_PATH
if: startsWith(matrix.os, 'windows')
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
- if: startsWith(matrix.os, 'windows')
# CI's Windows doesn't have require root certs
run: cargo test --workspace --exclude tokio-boring --exclude hyper-boring
name: Run tests (Windows)
- if: "!startsWith(matrix.os, 'windows')"
run: cargo test
name: Run tests (not Windows)
name: Run tests (not Windows)
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
members = [
"boring",
"boring-sys",
"systest",
"tokio-boring",
"hyper-boring"
]
5 changes: 2 additions & 3 deletions boring-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ documentation = "https://docs.rs/boring-sys"
links = "boringssl"
readme = "README.md"
categories = ["cryptography", "external-ffi-bindings"]
edition = "2018"
include = [
"/*.md",
"/*.toml",
Expand All @@ -25,8 +26,6 @@ include = [
"/src",
]

[dependencies]
libc = "0.2"

[build-dependencies]
bindgen = "0.57"
cmake = "0.1"
60 changes: 60 additions & 0 deletions boring-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ fn get_boringssl_cmake_config() -> cmake::Config {
}

fn main() {
use std::env;
use std::path::PathBuf;

let mut cfg = get_boringssl_cmake_config();

if cfg!(feature = "fuzzing") {
Expand All @@ -191,4 +194,61 @@ fn main() {
if cfg!(target_os = "macos") {
println!("cargo:rustc-cdylib-link-arg=-Wl,-undefined,dynamic_lookup");
}

let include_path = PathBuf::from("deps/boringssl/src/include");
let mut builder = bindgen::Builder::default()
.derive_copy(true)
.derive_debug(true)
.derive_default(true)
.derive_eq(true)
.default_enum_style(bindgen::EnumVariation::NewType { is_bitfield: false })
.default_macro_constant_type(bindgen::MacroTypeVariation::Signed)
.generate_comments(true)
.fit_macro_constants(false)
.size_t_is_usize(true)
.layout_tests(true)
.prepend_enum_name(true)
.rustfmt_bindings(true)
.clang_args(&["-I", include_path.to_str().unwrap()]);

let headers = [
"aes.h",
"asn1_mac.h",
"asn1t.h",
"blake2.h",
"blowfish.h",
"cast.h",
"chacha.h",
"cmac.h",
"cpu.h",
"curve25519.h",
"des.h",
"dtls1.h",
"hkdf.h",
"hrss.h",
"md4.h",
"md5.h",
"obj_mac.h",
"objects.h",
"opensslv.h",
"ossl_typ.h",
"pkcs12.h",
"poly1305.h",
"rand.h",
"rc4.h",
"ripemd.h",
"siphash.h",
"srtp.h",
"trust_token.h",
"x509v3.h",
];
for header in &headers {
builder = builder.header(include_path.join("openssl").join(header).to_str().unwrap());
}

let bindings = builder.generate().expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
35 changes: 0 additions & 35 deletions boring-sys/src/aes.rs

This file was deleted.

60 changes: 0 additions & 60 deletions boring-sys/src/asn1.rs

This file was deleted.

100 changes: 0 additions & 100 deletions boring-sys/src/bio.rs

This file was deleted.

Loading