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

Add github actions CI #10

Merged
merged 1 commit into from
Jun 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
pull_request:
push:
branches: [master]

env:
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-Cdebuginfo=0 --deny=warnings"
RUSTDOCFLAGS: "--deny=warnings"

jobs:
fmt:
name: Check Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hecrj/setup-rust-action@v1
with:
rust-version: nightly
components: rustfmt
- name: Check Formatting
run: cargo +nightly fmt --all -- --check

tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
rust_version: ["1.64", stable, nightly]

steps:
- uses: actions/checkout@v3

- uses: hecrj/setup-rust-action@v1
with:
rust-version: ${{ matrix.rust_version }}

- name: Check documentation
run: cargo doc --no-deps --document-private-items

- name: Run tests
run: cargo test --verbose
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ repository = "https://github.com/rust-windowing/xkbcommon-dl"
authors = ["Francesca Frangipane <francesca@comfysoft.net>"]
license = "MIT"
description = "Dynamically loaded xkbcommon and xkbcommon-x11 Rust bindings."
edition = "2018"
edition = "2021"
rust-version = "1.64"

[badges]

[features]
x11 = []

[dependencies]
dlib = "0.5"
lazy_static = "1.0"
bitflags = "2.3.1"
dlib = "0.5"
log = "0.4"
once_cell = "1.17"
86 changes: 47 additions & 39 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
#![allow(dead_code, non_camel_case_types)]
#![cfg_attr(rustfmt, rustfmt_skip)]

use dlib::dlopen_external_library;
use lazy_static::lazy_static;
use std::os::raw::{c_char, c_int, c_uint, c_void};

use bitflags::bitflags;
use dlib::dlopen_external_library;
use log::info;
use once_cell::sync::Lazy;

pub mod keysyms;

#[cfg(feature = "x11")]
pub mod x11;

use log::info;

use std::os::raw::{c_char, c_int, c_uint, c_void};
pub const XKB_MOD_NAME_SHIFT: &[u8] = b"Shift\0";
pub const XKB_MOD_NAME_CAPS: &[u8] = b"Lock\0";
pub const XKB_MOD_NAME_CTRL: &[u8] = b"Control\0";
pub const XKB_MOD_NAME_ALT: &[u8] = b"Mod1\0";
pub const XKB_MOD_NAME_NUM: &[u8] = b"Mod2\0";
pub const XKB_MOD_NAME_LOGO: &[u8] = b"Mod4\0";

pub const XKB_MOD_NAME_SHIFT : &'static [u8] = b"Shift\0";
pub const XKB_MOD_NAME_CAPS : &'static [u8] = b"Lock\0";
pub const XKB_MOD_NAME_CTRL : &'static [u8] = b"Control\0";
pub const XKB_MOD_NAME_ALT : &'static [u8] = b"Mod1\0";
pub const XKB_MOD_NAME_NUM : &'static [u8] = b"Mod2\0";
pub const XKB_MOD_NAME_LOGO : &'static [u8] = b"Mod4\0";

pub const XKB_LED_NAME_CAPS : &'static [u8] = b"Caps Lock\0";
pub const XKB_LED_NAME_NUM : &'static [u8] = b"Num Lock\0";
pub const XKB_LED_NAME_SCROLL : &'static [u8] = b"Scroll Lock\0";
pub const XKB_LED_NAME_CAPS: &[u8] = b"Caps Lock\0";
pub const XKB_LED_NAME_NUM: &[u8] = b"Num Lock\0";
pub const XKB_LED_NAME_SCROLL: &[u8] = b"Scroll Lock\0";

pub struct xkb_context;
pub struct xkb_keymap;
Expand All @@ -42,18 +40,18 @@ pub type xkb_led_index_t = u32;
pub type xkb_led_mask_t = u32;
pub type xkb_keymap_key_iter_t = Option<extern "C" fn(*mut xkb_keymap, xkb_keycode_t, *mut c_void)>;

pub const XKB_KEYCODE_INVALID :u32 = 0xffffffff;
pub const XKB_LAYOUT_INVALID :u32 = 0xffffffff;
pub const XKB_LEVEL_INVALID :u32 = 0xffffffff;
pub const XKB_MOD_INVALID :u32 = 0xffffffff;
pub const XKB_LED_INVALID :u32 = 0xffffffff;
pub const XKB_KEYCODE_MAX :u32 = 0xffffffff - 1;
pub const XKB_KEYCODE_INVALID: u32 = 0xffffffff;
pub const XKB_LAYOUT_INVALID: u32 = 0xffffffff;
pub const XKB_LEVEL_INVALID: u32 = 0xffffffff;
pub const XKB_MOD_INVALID: u32 = 0xffffffff;
pub const XKB_LED_INVALID: u32 = 0xffffffff;
pub const XKB_KEYCODE_MAX: u32 = 0xffffffff - 1;

#[repr(C)]
pub struct xkb_rule_names {
pub rules: *const c_char,
pub model: *const c_char,
pub layout: *const c_char,
pub rules: *const c_char,
pub model: *const c_char,
pub layout: *const c_char,
pub variant: *const c_char,
pub options: *const c_char,
}
Expand Down Expand Up @@ -284,20 +282,30 @@ functions:
fn xkb_compose_state_get_one_sym(*mut xkb_compose_state) -> xkb_keysym_t,
);

lazy_static!(
pub static ref XKBCOMMON_OPTION: Option<XkbCommon> = {
open_with_sonames(&["libxkbcommon.so", "libxkbcommon.so.0"], None, |name| unsafe { XkbCommon::open(name) })
};
pub static ref XKBCOMMON_HANDLE: &'static XkbCommon = {
XKBCOMMON_OPTION.as_ref().expect("Library libxkbcommon.so could not be loaded.")
};
pub static ref XKBCOMMON_COMPOSE_OPTION: Option<XkbCommonCompose> = {
open_with_sonames(&["libxkbcommon.so", "libxkbcommon.so.0"], Some("compose"), |name| unsafe { XkbCommonCompose::open(name) })
};
pub static ref XKBCOMMON_COMPOSE_HANDLE: &'static XkbCommonCompose = {
XKBCOMMON_COMPOSE_OPTION.as_ref().expect("Could not load compose module from libxkbcommon.so.")
};
);
pub static XKBCOMMON_OPTION: Lazy<Option<XkbCommon>> = Lazy::new(|| {
open_with_sonames(
&["libxkbcommon.so", "libxkbcommon.so.0"],
None,
|name| unsafe { XkbCommon::open(name) },
)
});
pub static XKBCOMMON_HANDLE: Lazy<&'static XkbCommon> = Lazy::new(|| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to not expose the Lazy type, since OnceLock is now in std and making the once_cell crate a public dependency is fragile. I'd prefer an approach like this:

pub fn xkbcommon_handle() -> &'static XkbCommon {
    static XKBCOMMON_HANDLE: OnceCell<XkbCommon> = OnceCell::new();
    XKBCOMMON_HANDLE.get_or_init(|| /* ... */)
}

This would need elinorbgr/dlib#21 to be released first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can open follow up for that, I wouldn't release this crate for a while.

The crate on its own is weird and its scope is sort of limited, as in for winit only.

XKBCOMMON_OPTION
.as_ref()
.expect("Library libxkbcommon.so could not be loaded.")
});
pub static XKBCOMMON_COMPOSE_OPTION: Lazy<Option<XkbCommonCompose>> = Lazy::new(|| {
open_with_sonames(
&["libxkbcommon.so", "libxkbcommon.so.0"],
Some("compose"),
|name| unsafe { XkbCommonCompose::open(name) },
)
});
pub static XKBCOMMON_COMPOSE_HANDLE: Lazy<&'static XkbCommonCompose> = Lazy::new(|| {
XKBCOMMON_COMPOSE_OPTION
.as_ref()
.expect("Could not load compose module from libxkbcommon.so.")
});

fn open_with_sonames<T, F>(names: &[&str], module: Option<&str>, open: F) -> Option<T>
where
Expand Down
28 changes: 14 additions & 14 deletions src/x11.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::os::raw::c_int;

use once_cell::sync::Lazy;

pub type xcb_connection_t = c_void;

use super::*;
Expand Down Expand Up @@ -40,17 +42,15 @@ functions:
) -> *mut xkb_state,
);

lazy_static!(
pub static ref XKBCOMMON_X11_OPTION: Option<XkbCommonX11> = {
open_with_sonames(
&["libxkbcommon-x11.so", "libxkbcommon-x11.so.0"],
None,
|name| unsafe { XkbCommonX11::open(name) },
)
};
pub static ref XKBCOMMON_X11_HANDLE: &'static XkbCommonX11 = {
XKBCOMMON_X11_OPTION
.as_ref()
.expect("Library libxkbcommon-x11.so could not be loaded.")
};
);
pub static XKBCOMMON_X11_OPTION: Lazy<Option<XkbCommonX11>> = Lazy::new(|| {
open_with_sonames(
&["libxkbcommon-x11.so", "libxkbcommon-x11.so.0"],
None,
|name| unsafe { XkbCommonX11::open(name) },
)
});
pub static XKBCOMMON_X11_HANDLE: Lazy<&'static XkbCommonX11> = Lazy::new(|| {
XKBCOMMON_X11_OPTION
.as_ref()
.expect("Library libxkbcommon-x11.so could not be loaded.")
});