Skip to content

Commit

Permalink
WIP github CI
Browse files Browse the repository at this point in the history
  • Loading branch information
shiro committed Nov 20, 2023
1 parent 1178e5f commit 8d205ed
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 108 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CI

on:
push:
branches:
- proto/rewrite
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ubuntu-latest
container:
image: ghcr.io/pyo3/maturin
strategy:
matrix:
target: [x86_64
# , x86, aarch64, armv7, s390x, ppc64le
]
steps:
- uses: actions/checkout@v3
# checkout sets permissions on .git, so we have to fix it
- name: Setup git config
run: git config --global --add safe.directory '*'
# - uses: actions/setup-python@v4
# with:
# python-version: '3.10'

- name: Setup build env
run: rustup default stable
- name: Build wheels
run: maturin build --release --out dist --find-interpreter

# - name: Build wheels
# uses: PyO3/maturin-action@v1
# with:
# target: ${{ matrix.target }}
# args: --release --out dist --find-interpreter
# sccache: 'true'
# manylinux: auto
# before-script-linux: "pwd; ls -la; git config --global --add safe.directory '*'"
# - name: Upload wheels
# uses: actions/upload-artifact@v3
# with:
# name: wheels
# path: dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux]
steps:
- name: debug print
run: whoami; pwd; ls -la
- uses: actions/download-artifact@v3
with:
name: wheels
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing *
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ proc-macro = true
[dependencies]
anyhow = "1.0"
clap = "4.4.8"
evdev-rs = { path = "evdev-rs", features = ["serde"] }
evdev-rs = { path = "evdev-rs", features = ["serde", "libevdev-1-10"] }
futures = "0.3"
input-linux-sys = "0.3.1"
itertools = "0.10.0"
Expand Down
4 changes: 3 additions & 1 deletion evdev-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ a library interface to the callers, thus avoiding erroneous ioctls, etc.

[features]
default = []
# Use features from libevdev version 1.10 and greater (libevdev_property_disable)
libevdev-1-10 = ["evdev-sys/libevdev-1-10"]

[dependencies]
serde = { version = "1.0", default-features = false, features=["derive"], optional = true }
evdev-sys = { path = "evdev-sys", version = "0.2.2" }
evdev-sys = { path = "evdev-sys", version = "0.2.5" }
libc = "0.2.67"
bitflags = "1.2.1"
log = "0.4.8"
Expand Down
5 changes: 4 additions & 1 deletion evdev-rs/evdev-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "evdev-sys"
version = "0.2.2"
version = "0.2.5"
authors = ["Nayan Deshmukh <[email protected]"]
build = "build.rs"
license = "MIT/Apache-2.0"
Expand All @@ -14,6 +14,9 @@ Raw bindings to libevdev
High level Rust bindings are available in the `evdev` crate
"""

[features]
libevdev-1-10 = []

[dependencies]
libc = "0.2.67"

Expand Down
88 changes: 67 additions & 21 deletions evdev-rs/evdev-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,61 +1,101 @@
use std::env;
use std::ffi::OsString;
use std::fs;
use std::path::{PathBuf, Path};
use std::path::{Path, PathBuf};
use std::process::Command;

fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "libevdev-1-10")]
// ver_str is string of the form "major.minor.patch"
fn parse_version(ver_str: &str) -> Option<(u32, u32, u32)> {
let mut major_minor_patch = ver_str
.split(".")
.map(|str| str.parse::<u32>().unwrap());
let major = major_minor_patch.next()?;
let minor = major_minor_patch.next()?;
let patch = major_minor_patch.next()?;
Some((major, minor, patch))
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
if env::var_os("TARGET") == env::var_os("HOST") {
match pkg_config::find_library("libevdev") {
let mut config = pkg_config::Config::new();
config.print_system_libs(false);

match config.probe("libevdev") {
Ok(lib) => {
// panic if feature 1.10 is enabled and the installed library
// is older than 1.10
#[cfg(feature = "libevdev-1-10")]
{
let (major, minor, patch) = parse_version(&lib.version)
.expect("Could not parse version information");
assert_eq!(major, 1, "evdev-rs works only with libevdev 1");
assert!(minor >= 10,
"Feature libevdev-1-10 was enabled, when compiling \
for a system with libevdev version {}.{}.{}",
major,
minor,
patch,
);
}
for path in &lib.include_paths {
println!("cargo:include={}", path.display());
}
return Ok(());
},
Err(e) => {
eprintln!(
"Couldn't find libevdev from pkgconfig ({:?}), \
compiling it from source...",
e
);
}
Err(e) => eprintln!(
"Couldn't find libevdev from pkgconfig ({:?}), \
compiling it from source...",
e
),
};
}

if !Path::new("libevdev/.git").exists() {
let mut download = Command::new("git");
download.args(&["submodule", "update", "--init", "--depth", "1"]);
run(&mut download)?;
run_ignore_error(&mut download)?;
}

let dst = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let src = env::current_dir()?;
let mut cp = Command::new("cp");
cp.arg("-r")
.arg(&src.join("libevdev/"))
.arg(&dst)
.current_dir(&src);
run(&mut cp)?;

println!("cargo:rustc-link-search={}/lib", dst.display());
println!("cargo:root={}", dst.display());
println!("cargo:include={}/include", dst.display());
println!("cargo:rerun-if-changed=libevdev/autogen.sh");
println!("cargo:rerun-if-changed=libevdev");

println!("cargo:rustc-link-lib=static=evdev");
let cfg = cc::Build::new();
let compiler = cfg.get_compiler();

fs::create_dir(&dst.join("build"))?;
if !&dst.join("build").exists() {
fs::create_dir(&dst.join("build"))?;
}

let mut autogen = Command::new("sh");
let mut cflags = OsString::new();
for arg in compiler.args() {
cflags.push(arg);
cflags.push(" ");
}
autogen.env("CC", compiler.path())
.env("CFLAGS", cflags)
.current_dir(&dst.join("build"))
.arg(src.join("libevdev/autogen.sh").to_str().unwrap()
.replace("C:\\", "/c/")
.replace("\\", "/"));
autogen
.env("CC", compiler.path())
.env("CFLAGS", cflags)
.current_dir(&dst.join("build"))
.arg(
dst.join("libevdev/autogen.sh")
.to_str()
.unwrap()
.replace("C:\\", "/c/")
.replace("\\", "/"),
);
if let Ok(h) = env::var("HOST") {
autogen.arg(format!("--host={}", h));
}
Expand All @@ -82,6 +122,12 @@ fn run(cmd: &mut Command) -> std::io::Result<()> {
Ok(())
}

fn run_ignore_error(cmd: &mut Command) -> std::io::Result<()> {
println!("running: {:?}", cmd);
let _ = cmd.status();
Ok(())
}

fn sanitize_sh(path: &Path) -> String {
let path = path.to_str().unwrap().replace("\\", "/");
return change_drive(&path).unwrap_or(path);
Expand All @@ -90,10 +136,10 @@ fn sanitize_sh(path: &Path) -> String {
let mut ch = s.chars();
let drive = ch.next().unwrap_or('C');
if ch.next() != Some(':') {
return None
return None;
}
if ch.next() != Some('/') {
return None
return None;
}
Some(format!("/{}/{}", drive, &s[drive.len_utf8() + 2..]))
}
Expand Down
Loading

0 comments on commit 8d205ed

Please sign in to comment.