Skip to content

Commit

Permalink
Automate generation of Windows bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Jul 31, 2024
1 parent be61df4 commit b10696e
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 61 deletions.
88 changes: 80 additions & 8 deletions .github/workflows/sys-bindings-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,58 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-go@v4
with:
go-version: '>=1.18'
go-version: '>=1.20'
- name: Install current Bash on macOS
if: runner.os == 'macOS'
run: brew install bash coreutils
- name: No-prefix build for ${{ matrix.os }}
env:
AWS_LC_SYS_NO_PREFIX: "1"
run: |
cargo test -p aws-lc-sys --features bindgen,ssl
cargo test -p aws-lc-sys --features bindgen
- name: Collect symbols
run: |
./scripts/build/collect_symbols.sh -c aws-lc-sys
- name: Commit & Push changes
run: ./scripts/ci/ci_add_commit_rebase_push.sh "Symbols from ${{ matrix.os }}"
collect-windows-symbols-and-commit:
if: github.repository == 'aws/aws-lc-rs'
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
target:
- 'aarch64-pc-windows-msvc'
- 'x86_64-pc-windows-msvc'
- 'x86_64-pc-windows-gnu'
- 'i686-pc-windows-msvc'
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
ref: ${{ github.ref_name }}
- uses: dtolnay/rust-toolchain@master
id: toolchain
with:
toolchain: stable
target: ${{ matrix.target }}
- if: contains(matrix.target, 'x86') || contains(matrix.target, 'i686')
uses: ilammy/setup-nasm@v1
- uses: actions/setup-go@v4
with:
go-version: '>=1.20'
- name: No-prefix build for ${{ matrix.target }}
env:
AWS_LC_SYS_NO_PREFIX: "1"
run: |
cargo ${{ (matrix.target == 'aarch64-pc-windows-msvc' && 'build') || 'test' }} -p aws-lc-sys --features bindgen --target ${{ matrix.target }}
- name: Collect symbols
shell: bash
run: |
./scripts/build/collect_symbols.sh -c aws-lc-sys -t ${{ matrix.target }}
- name: Commit & Push changes
shell: bash
run: ./scripts/ci/ci_add_commit_rebase_push.sh "Symbols from ${{ matrix.target }}"
collect-cross-symbols-and-commit:
if: github.repository == 'aws/aws-lc-rs'
runs-on: ubuntu-latest
Expand All @@ -69,21 +107,21 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-go@v4
with:
go-version: '>=1.18'
go-version: '>=1.20'
- name: Install cross
run: cargo install cross --locked --git https://github.com/cross-rs/cross
- name: No-prefix build for ${{ matrix.target }}
env:
AWS_LC_SYS_NO_PREFIX: "1"
run: |
cross test -p aws-lc-sys --features bindgen,ssl --target ${{ matrix.target }}
cross test -p aws-lc-sys --features bindgen --target ${{ matrix.target }}
- name: Collect symbols
run: |
./scripts/build/collect_symbols.sh -c aws-lc-sys -t ${{ matrix.target }}
- name: Commit & Push changes
run: ./scripts/ci/ci_add_commit_rebase_push.sh "Symbols for ${{ matrix.target }}"
generate-headers-and-commit:
needs: [ collect-cross-symbols-and-commit, collect-symbols-and-commit ]
needs: [ collect-cross-symbols-and-commit, collect-symbols-and-commit, collect-windows-symbols-and-commit ]
if: github.repository == 'aws/aws-lc-rs'
runs-on: ubuntu-latest
steps:
Expand All @@ -97,7 +135,7 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-go@v4
with:
go-version: '>=1.18'
go-version: '>=1.20'
- name: Generate Prefix Headers
run: ./scripts/generate/_generate_prefix_headers.sh -c aws-lc-sys
- name: Update sys-crate metadata
Expand Down Expand Up @@ -125,9 +163,43 @@ jobs:
env:
AWS_LC_SYS_INTERNAL_BINDGEN: "1"
run: |
cargo test -p aws-lc-sys --features bindgen,ssl
cargo test -p aws-lc-sys --features bindgen
- name: Commit & Push changes
run: ./scripts/ci/ci_add_commit_rebase_push.sh "Generated bindings from ${{ matrix.os }}"
generate-windows-bindings-and-commit:
needs: generate-headers-and-commit
if: github.repository == 'aws/aws-lc-rs'
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
target:
- 'aarch64-pc-windows-msvc'
- 'x86_64-pc-windows-msvc'
- 'x86_64-pc-windows-gnu'
- 'i686-pc-windows-msvc'
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
ref: ${{ github.ref_name }}
- uses: dtolnay/rust-toolchain@master
id: toolchain
with:
toolchain: stable
target: ${{ matrix.target }}
- if: contains(matrix.target, 'x86') || contains(matrix.target, 'i686')
uses: ilammy/setup-nasm@v1
- uses: actions/setup-go@v4
with:
go-version: '>=1.20'
- name: Generate bindings for ${{ matrix.target }}
env:
AWS_LC_SYS_INTERNAL_BINDGEN: "1"
run: |
cargo test -p aws-lc-sys --features bindgen --target ${{ matrix.target }}
- name: Commit & Push changes
run: ./scripts/ci/ci_add_commit_rebase_push.sh "Generated bindings for ${{ matrix.target }}"
generate-cross-bindings-and-commit:
needs: generate-headers-and-commit
if: github.repository == 'aws/aws-lc-rs'
Expand All @@ -148,7 +220,7 @@ jobs:
env:
AWS_LC_SYS_INTERNAL_BINDGEN: "1"
run: |
cross test -p aws-lc-sys --features bindgen,ssl --target ${{ matrix.target }}
cross test -p aws-lc-sys --features bindgen --target ${{ matrix.target }}
- name: Commit & Push changes
run: ./scripts/ci/ci_add_commit_rebase_push.sh "Generated bindings for ${{ matrix.target }}"
collect-src-and-commit:
Expand Down
4 changes: 2 additions & 2 deletions aws-lc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ dunce = "1.0"
fs_extra = "1.3"
cc = { version = "1.0.83", features = ["parallel"] }

[target.'cfg(any(all(any(target_arch = "x86_64", target_arch = "aarch64"), any(target_os = "linux", target_os = "macos"), any(target_env = "gnu", target_env = "musl", target_env = "")), all(target_arch = "x86", target_os = "linux", target_env = "gnu")))'.build-dependencies]
[target.'cfg(all(not(feature="ssl"),any(all(any(target_arch="x86_64",target_arch="aarch64"),any(target_os="linux",target_os="macos",target_os="windows"),any(target_env="gnu",target_env="musl",target_env="msvc",target_env="")),all(target_arch="x86",target_os="windows",target_env="msvc"),all(target_arch="x86",target_os="linux",target_env="gnu"))))'.build-dependencies]
bindgen = { version = "0.69.2", optional = true }

[target.'cfg(not(any(all(any(target_arch = "x86_64", target_arch = "aarch64"), any(target_os = "linux", target_os = "macos"), any(target_env = "gnu", target_env = "musl", target_env = "")), all(target_arch = "x86", target_os = "linux", target_env = "gnu"))))'.build-dependencies]
[target.'cfg(not(all(not(feature="ssl"),any(all(any(target_arch="x86_64",target_arch="aarch64"),any(target_os="linux",target_os="macos",target_os="windows"),any(target_env="gnu",target_env="musl",target_env="msvc",target_env="")),all(target_arch="x86",target_os="windows",target_env="msvc"),all(target_arch="x86",target_os="linux",target_env="gnu")))))'.build-dependencies]
bindgen = { version = "0.69.2" }

[dependencies]
Expand Down
8 changes: 4 additions & 4 deletions aws-lc-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl CmakeBuilder {

// See issue: https://github.com/aws/aws-lc-rs/issues/453
if target_os() == "windows" {
Self::configure_windows(&mut cmake_cfg);
self.configure_windows(&mut cmake_cfg);
}

// If the build environment vendor is Apple
Expand Down Expand Up @@ -200,13 +200,13 @@ impl CmakeBuilder {
}

if target_env() == "ohos" {
Self::configure_open_harmony(&mut cmake_cfg);
self.configure_open_harmony(&mut cmake_cfg);
}

cmake_cfg
}

fn configure_windows(cmake_cfg: &mut cmake::Config) {
fn configure_windows(&self, cmake_cfg: &mut cmake::Config) {
match (target_env().as_str(), target_arch().as_str()) {
("msvc", "aarch64") => {
cmake_cfg.generator_toolset(format!(
Expand Down Expand Up @@ -238,7 +238,7 @@ impl CmakeBuilder {
}
}

fn configure_open_harmony(cmake_cfg: &mut cmake::Config) {
fn configure_open_harmony(&self, cmake_cfg: &mut cmake::Config) {
const OHOS_NDK_HOME: &str = "OHOS_NDK_HOME";
if let Ok(ndk) = env::var(OHOS_NDK_HOME) {
cmake_cfg.define(
Expand Down
93 changes: 64 additions & 29 deletions aws-lc-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ use cmake_builder::CmakeBuilder;

#[cfg(any(
feature = "bindgen",
not(any(
all(
any(target_arch = "x86_64", target_arch = "aarch64"),
any(target_os = "linux", target_os = "macos"),
any(target_env = "gnu", target_env = "musl", target_env = "")
),
all(target_arch = "x86", target_os = "linux", target_env = "gnu")
not(all(
not(feature = "ssl"),
any(
all(
any(target_arch = "x86_64", target_arch = "aarch64"),
any(target_os = "linux", target_os = "macos", target_os = "windows"),
any(
target_env = "gnu",
target_env = "musl",
target_env = "msvc",
target_env = ""
)
),
all(target_arch = "x86", target_os = "windows", target_env = "msvc"),
all(target_arch = "x86", target_os = "linux", target_env = "gnu")
)
))
))]
mod bindgen;
Expand Down Expand Up @@ -170,13 +179,22 @@ fn execute_command(executable: &OsStr, args: &[&OsStr]) -> TestCommandResult {

#[cfg(any(
feature = "bindgen",
not(any(
all(
any(target_arch = "x86_64", target_arch = "aarch64"),
any(target_os = "linux", target_os = "macos"),
any(target_env = "gnu", target_env = "musl", target_env = "")
),
all(target_arch = "x86", target_os = "linux", target_env = "gnu")
not(all(
not(feature = "ssl"),
any(
all(
any(target_arch = "x86_64", target_arch = "aarch64"),
any(target_os = "linux", target_os = "macos", target_os = "windows"),
any(
target_env = "gnu",
target_env = "musl",
target_env = "msvc",
target_env = ""
)
),
all(target_arch = "x86", target_os = "windows", target_env = "msvc"),
all(target_arch = "x86", target_os = "linux", target_env = "gnu")
)
))
))]
fn generate_bindings(manifest_dir: &Path, prefix: &Option<String>, bindings_path: &PathBuf) {
Expand Down Expand Up @@ -327,13 +345,17 @@ fn initialize() {
if !is_external_bindgen() && (is_internal_bindgen() || !has_bindgen_feature()) {
let target = target();
let supported_platform = match target.as_str() {
"i686-unknown-linux-gnu"
| "x86_64-unknown-linux-gnu"
"aarch64-apple-darwin"
| "aarch64-pc-windows-msvc"
| "aarch64-unknown-linux-gnu"
| "x86_64-unknown-linux-musl"
| "aarch64-unknown-linux-musl"
| "i686-pc-windows-msvc"
| "i686-unknown-linux-gnu"
| "x86_64-apple-darwin"
| "aarch64-apple-darwin" => Some(target),
| "x86_64-pc-windows-gnu"
| "x86_64-pc-windows-msvc"
| "x86_64-unknown-linux-gnu"
| "x86_64-unknown-linux-musl" => Some(target),
_ => None,
};
if let Some(platform) = supported_platform {
Expand Down Expand Up @@ -382,13 +404,17 @@ fn prepare_cargo_cfg() {
// Also remove `#![allow(unexpected_cfgs)]` from src/lib.rs
/*
println!("cargo::rustc-check-cfg=cfg(use_bindgen_generated)");
println!("cargo::rustc-check-cfg=cfg(i686_unknown_linux_gnu)");
println!("cargo::rustc-check-cfg=cfg(x86_64_unknown_linux_gnu)");
println!("cargo::rustc-check-cfg=cfg(aarch64_apple_darwin)");
println!("cargo::rustc-check-cfg=cfg(aarch64_pc_windows_msvc)");
println!("cargo::rustc-check-cfg=cfg(aarch64_unknown_linux_gnu)");
println!("cargo::rustc-check-cfg=cfg(x86_64_unknown_linux_musl)");
println!("cargo::rustc-check-cfg=cfg(aarch64_unknown_linux_musl)");
println!("cargo::rustc-check-cfg=cfg(i686_pc_windows_msvc)");
println!("cargo::rustc-check-cfg=cfg(i686_unknown_linux_gnu)");
println!("cargo::rustc-check-cfg=cfg(x86_64_apple_darwin)");
println!("cargo::rustc-check-cfg=cfg(aarch64_apple_darwin)");
println!("cargo::rustc-check-cfg=cfg(x86_64_pc-windows-gnu)");
println!("cargo::rustc-check-cfg=cfg(x86_64_pc_windows_msvc)");
println!("cargo::rustc-check-cfg=cfg(x86_64_unknown_linux_gnu)");
println!("cargo::rustc-check-cfg=cfg(x86_64_unknown_linux_musl)");
*/
}

Expand Down Expand Up @@ -427,13 +453,22 @@ fn main() {
} else if is_bindgen_required() {
#[cfg(any(
feature = "bindgen",
not(any(
all(
any(target_arch = "x86_64", target_arch = "aarch64"),
any(target_os = "linux", target_os = "macos"),
any(target_env = "gnu", target_env = "musl", target_env = "")
),
all(target_arch = "x86", target_os = "linux", target_env = "gnu")
not(all(
not(feature = "ssl"),
any(
all(
any(target_arch = "x86_64", target_arch = "aarch64"),
any(target_os = "linux", target_os = "macos", target_os = "windows"),
any(
target_env = "gnu",
target_env = "musl",
target_env = "msvc",
target_env = ""
)
),
all(target_arch = "x86", target_os = "windows", target_env = "msvc"),
all(target_arch = "x86", target_os = "linux", target_env = "gnu")
)
))
))]
if !is_external_bindgen() {
Expand Down
Loading

0 comments on commit b10696e

Please sign in to comment.