Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Nov 14, 2023
1 parent 84088c7 commit f38db66
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 2,350 deletions.
90 changes: 48 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- master
- develop # TODO: remove before merging to master
- gen # XXX
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
Expand All @@ -12,7 +12,7 @@ jobs:
format:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
Expand All @@ -37,7 +37,7 @@ jobs:
doc:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: sudo apt-get install -y libwayland-dev
- name: Setup Rust
uses: actions-rs/toolchain@v1
Expand Down Expand Up @@ -149,6 +149,10 @@ jobs:
os: ubuntu-22.04
rust: stable
target: aarch64-unknown-linux-gnu
- task: bindings
os: ubuntu-22.04
rust: stable
target: riscv64gc-unknown-linux-gnu
# Test channels
- task: channels
os: ubuntu-22.04
Expand All @@ -164,46 +168,19 @@ jobs:
target: x86_64-unknown-linux-gnu
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Setup linux toolchain
if: contains(matrix.target, '-linux-') && startsWith(matrix.target, 'x86_64-')
run: |
sudo apt-get update -y
sudo apt-get install -y libdrm-dev libgbm-dev libwayland-dev
- name: Setup cross linux toolchain
- uses: actions/checkout@v3
- name: Setup linux cross toolchain
if: contains(matrix.target, '-linux-') && !startsWith(matrix.target, 'x86_64-')
run: |
case "${{ matrix.target }}" in
i686-*) SYSTEM_ARCH=i386 ;;
arm*) SYSTEM_ARCH=armhf ;;
aarch64*) SYSTEM_ARCH=arm64 ;;
esac
GCC_TARGET=$(printf "${{ matrix.target }}" | sed 's/-unknown-/-/' | sed 's/arm[^-]*/arm/g')
ENV_TARGET=$(printf "${{ matrix.target }}" | tr '-' '_')
ENV_TARGET_UC=$(printf "${ENV_TARGET}" | tr '[[:lower:]]' '[[:upper:]]')
sudo rm -f /etc/apt/sources.list.d/*.list
case "${{ matrix.target }}" in
arm* | aarch64*)
sudo tee /etc/apt/sources.list << EOF
deb [arch=i386,amd64] http://archive.ubuntu.com/ubuntu/ jammy main universe
deb [arch=i386,amd64] http://archive.ubuntu.com/ubuntu/ jammy-updates main universe
deb [arch=i386,amd64] http://security.ubuntu.com/ubuntu/ jammy-security main universe
deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ jammy main universe
deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main universe
deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ jammy-security main universe
EOF
;;
esac
sudo dpkg --add-architecture ${SYSTEM_ARCH}
dpkg --print-foreign-architectures
GCC_TARGET=$(printf "${{ matrix.target }}" | sed 's/-unknown-/-/;s/arm[^-]*/arm/;s/riscv[^-]*/riscv64/')
ENV_TARGET=$(printf "${{ matrix.target }}" | tr '-' '_' | tr '[[:lower:]]' '[[:upper:]]')
sudo apt-get update -y
sudo apt-get upgrade -y --fix-broken
sudo apt-get install -y libdrm-dev:${SYSTEM_ARCH} libgbm-dev:${SYSTEM_ARCH} libwayland-dev:${SYSTEM_ARCH} gcc-${GCC_TARGET} pkg-config
echo "CARGO_TARGET_${ENV_TARGET_UC}_LINKER=${GCC_TARGET}-gcc" >> $GITHUB_ENV
sudo apt-get install -y gcc-${GCC_TARGET} pkg-config
echo "CARGO_TARGET_${ENV_TARGET}_LINKER=${GCC_TARGET}-gcc" >> $GITHUB_ENV
echo "BINDGEN_EXTRA_CLANG_ARGS=--sysroot=/usr/${GCC_TARGET}" >> $GITHUB_ENV
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
echo "PKG_CONFIG_${ENV_TARGET}=${GCC_TARGET}-pkg-config" >> $GITHUB_ENV
echo "PKG_CONFIG=${GCC_TARGET}-pkg-config" >> $GITHUB_ENV
echo "BINDGEN_EXTRA_CLANG_ARGS=--sysroot=/usr/${GCC_TARGET}" >> $GITHUB_ENV
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -262,17 +239,46 @@ jobs:
command: test
args: --all --target ${{ matrix.target }}

compare-bindings:
needs:
- test
runs-on: ubuntu-22.04
steps:
- name: download bindings
uses: actions/download-artifact@v3
with:
name: bindings
- name: compare
run: |
code=0
for i in bindings-*.rs
do
if cmp -s bindings-x86_64-unknown-linux-gnu.rs ${i}
then
echo ${i} matches x86_64 bindings
else
echo ${i} does not match x86_64 bindings
diff bindings-x86_64-unknown-linux-gnu.rs ${i}
code=1
fi
done
exit ${code}
update-bindings:
if: ${{ github.event_name != 'pull_request' && !startsWith(github.ref, 'refs/tags/') }}
needs:
- test
- compare-bindings
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Download bindings
uses: actions/download-artifact@v2
- uses: actions/checkout@v3
- name: download bindings
uses: actions/download-artifact@v3
with:
name: bindings
- name: Copy x86_64 bindings
run: |
cp bindings-x86_64-unknown-linux-gnu.rs drm-ffi/drm-sys/src/bindings.rs
rm bindings-*.rs
- name: Create pull request
uses: peter-evans/create-pull-request@v3
with:
Expand All @@ -294,7 +300,7 @@ jobs:
- test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
Expand Down
55 changes: 10 additions & 45 deletions gbm-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
#[cfg(feature = "gen")]
extern crate bindgen;

use std::{env, path::Path};

#[cfg(not(feature = "gen"))]
fn main() {
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();

let bindings_file = Path::new("src")
.join("platforms")
.join(&target_os)
.join(&target_arch)
.join("gen.rs");

if bindings_file.is_file() {
println!(
"cargo:rustc-env=GBM_SYS_BINDINGS_PATH={}/{}",
target_os, target_arch
);
} else {
panic!(
"No prebuilt bindings for target OS `{}` and/or architecture `{}`. Try `gen` feature.",
target_os, target_arch
);
}
}
fn main() {}

#[cfg(feature = "gen")]
fn main() {
use std::{env, path::Path};

const TMP_BIND_PREFIX: &str = "__BINDGEN_TMP_";
const TMP_BIND_PREFIX_REG: &str = "_BINDGEN_TMP_.*";

Expand Down Expand Up @@ -112,31 +91,17 @@ fn main() {

// Generate the bindings
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("gen.rs");
let dest_path = Path::new(&out_dir).join("bindings.rs");

generated.write_to_file(dest_path).unwrap();

#[cfg(feature = "update_bindings")]
{
use std::{fs, io::Write};

let bind_file = Path::new(&out_dir).join("gen.rs");
let dest_dir = Path::new("src")
.join("platforms")
.join(env::var("CARGO_CFG_TARGET_OS").unwrap())
.join(env::var("CARGO_CFG_TARGET_ARCH").unwrap());
let dest_file = dest_dir.join("gen.rs");

fs::create_dir_all(&dest_dir).unwrap();
fs::copy(&bind_file, &dest_file).unwrap();

if let Ok(github_env) = env::var("GITHUB_ENV") {
let mut env_file = fs::OpenOptions::new()
.create(true)
.append(true)
.open(github_env)
.unwrap();
writeln!(env_file, "GBM_SYS_BINDINGS_FILE={}", dest_file.display()).unwrap();
}
use std::fs;

let bind_file = Path::new(&out_dir).join("bindings.rs");
let dest_file = "src/bindings.rs";

fs::copy(bind_file, dest_file).unwrap();
}
}
File renamed without changes.
8 changes: 2 additions & 6 deletions gbm-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@
extern crate libc;

#[cfg(feature = "gen")]
include!(concat!(env!("OUT_DIR"), "/gen.rs"));
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

#[cfg(not(feature = "gen"))]
include!(concat!(
"platforms/",
env!("GBM_SYS_BINDINGS_PATH"),
"/gen.rs"
));
include!("bindings.rs");

#[link(name = "gbm")]
extern "C" {}
Loading

0 comments on commit f38db66

Please sign in to comment.