Skip to content

Commit f56cdd8

Browse files
committed
try to generate bindings for other platforms in the CI, use target specific bindings dirs
1 parent 6cb47dc commit f56cdd8

File tree

10 files changed

+49
-5
lines changed

10 files changed

+49
-5
lines changed

.github/workflows/CI.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,32 @@ jobs:
6161
cargo build --examples --features "${CI_BUILD_FEATURES} ${{matrix.feature}}" ${{matrix.build_mode}}
6262
cargo test --features "${CI_BUILD_FEATURES} ${{matrix.feature}}" ${{matrix.build_mode}}
6363
64+
build-bindgen:
65+
name: build and generate bindings
66+
runs-on: ${{ matrix.os }}
67+
strategy:
68+
fail-fast: false
69+
matrix:
70+
os: [macos-latest, ubuntu-latest, windows-latest]
71+
steps:
72+
- uses: actions/checkout@v2
73+
- name: Build SDL2
74+
shell: bash
75+
env:
76+
RUSTFLAGS: "--cfg update_pregenerated_bindings"
77+
CI_BUILD_FEATURES: "mixer,ttf,gfx,image,bindgen,bundled"
78+
RUST_TEST_THREADS: 1
79+
run: |
80+
set -xeuo pipefail
81+
rustc --version
82+
cargo --version
83+
cargo build --features "${CI_BUILD_FEATURES}"
84+
cargo build --examples --features "${CI_BUILD_FEATURES}"
85+
cargo test --features "${CI_BUILD_FEATURES}"
86+
# dump generated bindings
87+
git add sdl2-sys/bindings/
88+
git diff --cached
89+
6490
build-linux:
6591
name: build linux pkg-config
6692
runs-on: ubuntu-24.04

sdl2-sys/sdl_bindings.rs renamed to sdl2-sys/bindings/x86_64-unknown-linux-gnu/sdl_bindings.rs

File renamed without changes.

sdl2-sys/sdl_gfx_framerate_bindings.rs renamed to sdl2-sys/bindings/x86_64-unknown-linux-gnu/sdl_gfx_framerate_bindings.rs

File renamed without changes.

sdl2-sys/sdl_gfx_imagefilter_bindings.rs renamed to sdl2-sys/bindings/x86_64-unknown-linux-gnu/sdl_gfx_imagefilter_bindings.rs

File renamed without changes.

sdl2-sys/sdl_gfx_primitives_bindings.rs renamed to sdl2-sys/bindings/x86_64-unknown-linux-gnu/sdl_gfx_primitives_bindings.rs

File renamed without changes.

sdl2-sys/sdl_gfx_rotozoom_bindings.rs renamed to sdl2-sys/bindings/x86_64-unknown-linux-gnu/sdl_gfx_rotozoom_bindings.rs

File renamed without changes.

sdl2-sys/sdl_image_bindings.rs renamed to sdl2-sys/bindings/x86_64-unknown-linux-gnu/sdl_image_bindings.rs

File renamed without changes.

sdl2-sys/sdl_mixer_bindings.rs renamed to sdl2-sys/bindings/x86_64-unknown-linux-gnu/sdl_mixer_bindings.rs

File renamed without changes.

sdl2-sys/sdl_ttf_bindings.rs renamed to sdl2-sys/bindings/x86_64-unknown-linux-gnu/sdl_ttf_bindings.rs

File renamed without changes.

sdl2-sys/build.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern crate pkg_config;
1616
))]
1717
compile_error!("Enable 'bindgen' and 'bundled' features when using update_pregenerated_bindings");
1818

19+
use std::io::ErrorKind;
1920
use std::path::{Path, PathBuf};
2021
use std::process::Command;
2122
use std::{env, fs, io};
@@ -558,7 +559,7 @@ fn main() {
558559

559560
#[cfg(not(feature = "bindgen"))]
560561
{
561-
copy_pregenerated_bindings();
562+
copy_pregenerated_bindings(target.as_str());
562563
println!("cargo:include={}", sdl2_includes);
563564
}
564565

@@ -574,10 +575,21 @@ fn main() {
574575
}
575576
}
576577

578+
fn bindings_dir(mut base: PathBuf, target: &str) -> PathBuf {
579+
base.push("bindings");
580+
base.push(target);
581+
582+
base
583+
}
584+
577585
#[cfg(any(not(feature = "bindgen"), update_pregenerated_bindings))]
578-
fn copy_pregenerated_bindings() {
586+
fn copy_pregenerated_bindings(target: &str) {
579587
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
580-
let crate_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
588+
let crate_path = bindings_dir(
589+
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()),
590+
target,
591+
);
592+
581593
fs::copy(
582594
crate_path.join("sdl_bindings.rs"),
583595
out_path.join("sdl_bindings.rs"),
@@ -642,7 +654,13 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
642654
#[cfg(not(update_pregenerated_bindings))]
643655
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
644656
#[cfg(update_pregenerated_bindings)]
645-
let out_path = PathBuf::from(".");
657+
let out_path = bindings_dir(PathBuf::from("."), target);
658+
659+
#[cfg(update_pregenerated_bindings)]
660+
match fs::create_dir(&out_path) {
661+
Err(err) if err.kind() == io::ErrorKind::AlreadyExists => {}
662+
res => res.expect("unable to create bindings dir"),
663+
}
646664

647665
let mut all_bindings = bindgen::builder()
648666
// enable no_std-friendly output by only using core definitions
@@ -836,7 +854,7 @@ fn generate_bindings(target: &str, host: &str, headers_paths: &[String]) {
836854
}
837855

838856
#[cfg(update_pregenerated_bindings)]
839-
copy_pregenerated_bindings();
857+
copy_pregenerated_bindings(target);
840858
}
841859

842860
fn get_os_from_triple(triple: &str) -> Option<&str> {

0 commit comments

Comments
 (0)