Skip to content
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

Generate bindings once for all platforms and architectures #176

Merged
merged 3 commits into from
Nov 3, 2023
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
126 changes: 67 additions & 59 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -22,7 +22,7 @@ jobs:
default: true
override: true
- name: Cargo cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
Expand All @@ -37,7 +37,7 @@ jobs:
doc:
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 @@ -47,7 +47,7 @@ jobs:
default: true
override: true
- name: Cargo cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
Expand All @@ -63,7 +63,7 @@ jobs:
check:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- run: |
sudo apt-get update -y
sudo apt-get install -y libdrm-dev
Expand All @@ -79,14 +79,14 @@ jobs:
default: true
override: true
- name: Cargo cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-rust_1.65.0-${{ hashFiles('**/Cargo.toml') }}
- name: Build cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-build-rust_1.65.0-check-${{ hashFiles('**/Cargo.toml') }}
Expand All @@ -99,7 +99,7 @@ jobs:
check-minimal:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- run: |
sudo apt-get update -y
sudo apt-get install -y libdrm-dev
Expand All @@ -114,14 +114,14 @@ jobs:
default: true
override: true
- name: Cargo cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-rust_nightly-${{ hashFiles('**/Cargo.toml') }}
- name: Build cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-build-rust_nightly-check-minimal-${{ hashFiles('**/Cargo.toml') }}
Expand Down Expand Up @@ -161,6 +161,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 @@ -176,47 +180,23 @@ 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
- 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-mark hold grub-efi-amd64-signed
sudo apt-get upgrade -y --fix-broken
sudo apt-get install -y libdrm-dev:${SYSTEM_ARCH} gcc-${GCC_TARGET} pkg-config
echo "CARGO_TARGET_${ENV_TARGET_UC}_LINKER=${GCC_TARGET}-gcc" >> $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
sudo apt-get install -y gcc-${GCC_TARGET}
echo "CARGO_TARGET_${ENV_TARGET}_LINKER=${GCC_TARGET}-gcc" >> $GITHUB_ENV
echo "BINDGEN_EXTRA_CLANG_ARGS=--sysroot=/usr/${GCC_TARGET}" >> $GITHUB_ENV
- name: Fetch drm headers
run: |
mkdir drm
wget -O drm/drm.h https://github.com/torvalds/linux/raw/master/include/uapi/drm/drm.h
wget -O drm/drm_mode.h https://github.com/torvalds/linux/raw/master/include/uapi/drm/drm_mode.h
echo "LIBDRM_INCLUDE_PATH=${PWD}/drm" >> $GITHUB_ENV
echo "BINDGEN_EXTRA_CLANG_ARGS=-D __user= ${BINDGEN_EXTRA_CLANG_ARGS}" >> $GITHUB_ENV
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
Expand All @@ -227,14 +207,14 @@ jobs:
default: true
override: true
- name: Cargo cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-rust_${{ matrix.rust }}-${{ hashFiles('**/Cargo.toml') }}
- name: Build cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-build-rust_${{ matrix.rust }}-target_${{ matrix.target }}-${{ hashFiles('**/Cargo.toml') }}
Expand All @@ -249,15 +229,14 @@ jobs:
with:
command: build
args: --manifest-path drm-ffi/drm-sys/Cargo.toml --target ${{ matrix.target }} --features update_bindings
- name: Copy bindings
run: cp drm-ffi/drm-sys/src/bindings.rs bindings-${{ matrix.target }}.rs
- name: Upload bindings
if: matrix.task == 'bindings'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: bindings
path: |
drm-ffi/drm-sys/${{ env.DRM_SYS_BINDINGS_FILE }}
LICENSE
README.md
path: bindings-*.rs
- name: Build
uses: actions-rs/cargo@v1
with:
Expand All @@ -273,17 +252,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 @@ -305,7 +313,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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
authors = ["Tyler Slabinski <[email protected]>", "Victoria Brekenfeld <[email protected]>"]
exclude = [".gitignore", ".github"]
rust-version = "1.65"
resolver = "2" # Required to separate dev-dependencies.nix features
edition = "2021"

[dependencies]
bitflags = "2"
Expand Down
1 change: 1 addition & 0 deletions drm-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.6.0"
license = "MIT"
authors = ["Tyler Slabinski <[email protected]>"]
rust-version = "1.65"
edition = "2021"

[dependencies]
drm-sys = { path = "drm-sys", version = "0.5.0" }
Expand Down
7 changes: 7 additions & 0 deletions drm-ffi/drm-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authors = ["Tyler Slabinski <[email protected]>"]
license = "MIT"
build = "build.rs"
rust-version = "1.65"
edition = "2021"

[features]
default = []
Expand All @@ -16,3 +17,9 @@ update_bindings = ["use_bindgen"]
[build-dependencies]
bindgen = { version = "0.66", optional = true }
pkg-config = { version = "0.3.19", optional = true }

[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
linux-raw-sys = { version = "0.6", default-features = false, features = ["general", "no_std"] }

[target.'cfg(not(any(target_os = "android", target_os = "linux")))'.dependencies]
libc = "0.2"
Loading
Loading