Skip to content

Commit

Permalink
Use bindgen to automatically generate boring-sys
Browse files Browse the repository at this point in the history
This ensures that all the Rust functions, types and constants
always match the actual BoringSSL definitions.

It also removes quite a lot of manually maintained code, as well
as the need for systest.

The value for `SslOptions::ALL`, for example, was wrong. On current
BoringSSL versions, this is a no-op, and is set to `0`.

Clearing it does nothing. So, the `clear_ctx_options` test, that
passed by accident, was adjusted to use a different option.

The `libc` crate is not required, as we only use it for types that
are already defined in the standard library. It was removed from
`boring-sys`. The same can be done to other crates later.
  • Loading branch information
jedisct1 committed Feb 12, 2021
1 parent 0c9166d commit 05c6a41
Show file tree
Hide file tree
Showing 46 changed files with 197 additions and 4,192 deletions.
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

0 comments on commit 05c6a41

Please sign in to comment.