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 #67

Merged
merged 1 commit into from
Jan 17, 2024
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
114 changes: 67 additions & 47 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
Expand All @@ -36,7 +36,7 @@ jobs:
doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: |
sudo apt-get update -qqy
sudo apt-get install -qqy libudev-dev
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- run: |
sudo apt-get update -qqy
sudo apt-get install -qqy libudev-dev
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
check-minimal:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
Expand Down Expand Up @@ -172,7 +172,7 @@ jobs:
container: ubuntu:focal
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: |
TZ=Etc/UTC
ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime
Expand All @@ -182,41 +182,16 @@ jobs:
- name: Setup linux toolchain
if: contains(matrix.target, '-linux-') && startsWith(matrix.target, 'x86_64-')
run: |
sudo apt-get install -qqy libinput-dev
sudo apt-get install -y libinput-dev libudev-dev
- name: Setup cross linux 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/ focal main universe
deb [arch=i386,amd64] http://archive.ubuntu.com/ubuntu/ focal-updates main universe
deb [arch=i386,amd64] http://security.ubuntu.com/ubuntu/ focal-security main universe
deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ focal main universe
deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ focal-updates main universe
deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ focal-security main universe
EOF
;;
esac
sudo dpkg --add-architecture ${SYSTEM_ARCH}
dpkg --print-foreign-architectures
sudo apt-get update -qqy
sudo apt-get dist-upgrade -qqy --fix-broken
sudo apt-get install -qqy --fix-broken -o Debug::pkgProblemResolver=yes libinput-dev:${SYSTEM_ARCH} gcc-${GCC_TARGET} pkg-config-${GCC_TARGET}
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
echo "BINDGEN_EXTRA_CLANG_ARGS=\"-L/usr/lib/${GCC_TARGET} -L/lib/${GCC_TARGET}\"" >> $GITHUB_ENV
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 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} -isystem ${PWD}/.github/workflows/cross-include" >> $GITHUB_ENV
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -251,22 +226,33 @@ jobs:
with:
command: build
args: --manifest-path input-sys/Cargo.toml --target ${{ matrix.target }} --no-default-features --features update_bindings,libinput_1_11,libinput_1_14,libinput_1_15,libinput_1_19,libinput_1_21
- name: Copy bindings
run: |
for i in input-sys/src/bindings/*.rs
do
cp $i $(basename $i .rs)-${{ matrix.target }}.rs
done
- name: Upload bindings
if: matrix.task == 'bindings'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: bindings
path: |
input-sys/${{ env.INPUT_SYS_BINDINGS_FILE }}
LICENSE
README.md
path: gen_*.rs
- name: Build
if: contains(matrix.target, '-linux-') && startsWith(matrix.target, 'x86_64-')
uses: actions-rs/cargo@v1
with:
command: build
args: --target ${{ matrix.target }}
- name: Build
if: contains(matrix.target, '-linux-') && !startsWith(matrix.target, 'x86_64-')
uses: actions-rs/cargo@v1
with:
command: build
# Disable udev feature so we don't need library in cross-sysroot
args: --target ${{ matrix.target }} --no-default-features --features log,libinput_1_21
- name: Test
if: contains(matrix.target, '-linux-') && (startsWith(matrix.target, 'x86_64-') || startsWith(matrix.target, 'i686-'))
if: contains(matrix.target, '-linux-') && startsWith(matrix.target, 'x86_64-')
uses: actions-rs/cargo@v1
timeout-minutes: 12
env:
Expand All @@ -275,17 +261,51 @@ 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 gen_*.rs
do
base=$(echo ${i} | cut -f 1 -d -)
if cmp -s ${base}-x86_64-unknown-linux-gnu.rs ${i}
then
echo ${i} matches x86_64 bindings
else
echo ${i} does not match x86_64 bindings
diff ${base}-x86_64-unknown-linux-gnu.rs ${i}
code=1
fi
done
exit ${code}

# TODO copy x86
update-bindings:
if: ${{ github.event_name != 'pull_request' && !startsWith(github.ref, 'refs/tags/') }}
needs:
- test
- compare-bindings
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Download bindings
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: bindings
- name: Copy x86_64 bindings
run: |
for i in gen_*-x86_64-unknown-linux-gnu.rs
do
cp $i input-sys/src/bindings/$(basename i x86_64-unknown-linux-gnu.rs).rs
done
rm gen_*.rs
- name: Create pull request
uses: peter-evans/create-pull-request@v3
with:
Expand All @@ -307,7 +327,7 @@ jobs:
- test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/cross-include/libudev.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Placeholder to generate `libinput.h` bindings

struct udev;

struct udev_device;
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exclude = [".gitignore", ".rustfmt.toml", ".github"]
io-lifetimes = "1.0.3"
libc = "0.2"
bitflags = "2.4"
log = { version = "0.4", optional = true }
log = { version = "0.4.20", optional = true }

[dependencies.input-sys]
version = "1.17.0"
Expand Down
17 changes: 12 additions & 5 deletions input-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@ edition = "2018"
[lib]
path = "src/lib.rs"

[dependencies]
libc = "0.2"

[build-dependencies.bindgen]
version = "0.57"
version = "0.69"
optional = true

# Fix for non-existant feature on nightly `-Z minimal-versions`
[build-dependencies.proc-macro2]
version = "1.0.76"
optional = true

# Fix for `-Z minimal-versions`
[build-dependencies.regex]
version = "1.10"
optional = true

[features]
default = ["libinput_1_21"]
gen = ["bindgen"]
gen = ["bindgen", "proc-macro2", "regex"]
update_bindings = ["gen"]
libinput_1_11 = []
libinput_1_14 = []
Expand Down
36 changes: 10 additions & 26 deletions input-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ fn main() {
let version = lib_versions().next().unwrap();

let bind_name = format!("gen_{}_{}.rs", version.0, version.1);
let bindings_file = Path::new("src")
.join("platforms")
.join(&target_os)
.join(&target_arch)
.join(bind_name);
let bindings_file = Path::new("src").join("bindings").join(bind_name);

if !bindings_file.is_file() {
panic!(
Expand All @@ -62,10 +58,7 @@ fn main() {
);

#[cfg(feature = "update_bindings")]
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_dir = Path::new("src/bindings");

for version in lib_versions() {
let header = Path::new("include").join(format!(
Expand All @@ -80,9 +73,14 @@ fn main() {
false => "",
})
.header(header.display().to_string())
.ctypes_prefix("::libc")
.whitelist_type(r"^libinput_.*$")
.whitelist_function(r"^libinput_.*$")
.allowlist_type(r"^libinput_.*$")
.allowlist_function(r"^libinput_.*$")
// Requires `va_list`
// TODO Use `std::ffi::VaList` when stable?
.blocklist_type("libinput_log_handler")
.blocklist_function("libinput_log_set_handler")
.blocklist_type(".*va_list.*")
.layout_tests(false)
.generate()
.unwrap();

Expand All @@ -106,18 +104,4 @@ fn main() {
fs::copy(&bind_file, &dest_file).unwrap();
}
}

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

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, "INPUT_SYS_BINDINGS_FILE={}", dest_dir.display()).unwrap();
}
}
}
Loading
Loading