Skip to content

Commit a38631f

Browse files
committed
Auto merge of #616 - Arvamer:linux_input_types, r=alexcrichton
Add structs defined in linux/input.h I was using definitions for these structs from `ioctl` but because @cmr decide to deprecate his crate (and yanked all versions :() I think that `libc` is the best place for them. In original C header, primitive types uses aliases like `__u16` or `__s32`; for now I replaced them with Rust's counterparts but I'm not sure if it is ok, especially because tests were failing for `u64` (`unsigned long long` vs `unsigned long` on x86_64). Also, should I do something special with union in `ff_effect`? I would like also to add all constants form `linux/input.h` and `linux/input-event-codes.h` if this PR will be accepted.
2 parents 2f28640 + 495d22a commit a38631f

File tree

15 files changed

+151
-3
lines changed

15 files changed

+151
-3
lines changed

ci/docker/i686-unknown-linux-musl/Dockerfile

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ RUN curl https://www.musl-libc.org/releases/musl-1.1.15.tar.gz | \
1818
CC=gcc CFLAGS=-m32 ./configure --prefix=/musl-i686 --disable-shared --target=i686 && \
1919
make CROSS_COMPILE= install -j4 && \
2020
cd .. && \
21-
rm -rf musl-1.1.15
21+
rm -rf musl-1.1.15 && \
22+
# Install linux kernel headers sanitized for use with musl
23+
curl -L https://github.com/sabotage-linux/kernel-headers/archive/v3.12.6-5.tar.gz | \
24+
tar xzf - && \
25+
cd kernel-headers-3.12.6-5 && \
26+
make ARCH=i386 prefix=/musl-i686 install -j4 && \
27+
cd .. && \
28+
rm -rf kernel-headers-3.12.6-5
2229
ENV PATH=$PATH:/musl-i686/bin:/rust/bin \
2330
CC_i686_unknown_linux_musl=musl-gcc

ci/docker/x86_64-unknown-linux-musl/Dockerfile

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@ RUN curl https://www.musl-libc.org/releases/musl-1.1.15.tar.gz | \
99
./configure --prefix=/musl-x86_64 && \
1010
make install -j4 && \
1111
cd .. && \
12-
rm -rf musl-1.1.15
12+
rm -rf musl-1.1.15 && \
13+
# Install linux kernel headers sanitized for use with musl
14+
curl -L https://github.com/sabotage-linux/kernel-headers/archive/v3.12.6-5.tar.gz | \
15+
tar xzf - && \
16+
cd kernel-headers-3.12.6-5 && \
17+
make ARCH=x86_64 prefix=/musl-x86_64 install -j4 && \
18+
cd .. && \
19+
rm -rf kernel-headers-3.12.6-5
1320
ENV PATH=$PATH:/musl-x86_64/bin:/rust/bin

libc-test/build.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ fn main() {
181181
cfg.header("sys/fsuid.h");
182182
cfg.header("pty.h");
183183
cfg.header("shadow.h");
184+
cfg.header("linux/input.h");
184185
if x86_64 {
185186
cfg.header("sys/io.h");
186187
}
@@ -301,6 +302,9 @@ fn main() {
301302
}
302303
}
303304
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
305+
"type_" if linux &&
306+
(struct_ == "input_event" || struct_ == "input_mask" ||
307+
struct_ == "ff_effect") => "type".to_string(),
304308
s => s.to_string(),
305309
}
306310
});
@@ -329,6 +333,10 @@ fn main() {
329333
// This is actually a union, not a struct
330334
"sigval" => true,
331335

336+
// Linux kernel headers used on musl are too old to have this
337+
// definition. Because it's tested on other Linux targets, skip it.
338+
"input_mask" if musl => true,
339+
332340
_ => false
333341
}
334342
});
@@ -551,7 +559,9 @@ fn main() {
551559
// aio_buf is "volatile void*" and Rust doesn't understand volatile
552560
(struct_ == "aiocb" && field == "aio_buf") ||
553561
// stack_t.ss_sp's type changed from FreeBSD 10 to 11 in svn r294930
554-
(freebsd && struct_ == "stack_t" && field == "ss_sp")
562+
(freebsd && struct_ == "stack_t" && field == "ss_sp") ||
563+
// this one is an anonymous union
564+
(linux && struct_ == "ff_effect" && field == "u")
555565
});
556566

557567
cfg.skip_field(move |struct_, field| {

src/unix/notbsd/linux/mips/mips32.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub type ino_t = u32;
1010
pub type blkcnt_t = i32;
1111
pub type blksize_t = i32;
1212
pub type nlink_t = u32;
13+
pub type __u64 = ::c_ulonglong;
1314

1415
s! {
1516
pub struct aiocb {

src/unix/notbsd/linux/mips/mips64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub type suseconds_t = i64;
1010
pub type time_t = i64;
1111
pub type wchar_t = i32;
1212
pub type clock_t = i64;
13+
pub type __u64 = ::c_ulong;
1314

1415
s! {
1516
pub struct aiocb {

src/unix/notbsd/linux/mod.rs

+113
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ pub type nfds_t = ::c_ulong;
1919
pub type nl_item = ::c_int;
2020
pub type idtype_t = ::c_uint;
2121

22+
pub type __u8 = ::c_uchar;
23+
pub type __u16 = ::c_ushort;
24+
pub type __s16 = ::c_short;
25+
pub type __u32 = ::c_uint;
26+
pub type __s32 = ::c_int;
27+
2228
pub enum fpos64_t {} // TODO: fill this out with a struct
2329

2430
s! {
@@ -231,6 +237,113 @@ s! {
231237
pub sem_op: ::c_short,
232238
pub sem_flg: ::c_short,
233239
}
240+
241+
pub struct input_event {
242+
pub time: ::timeval,
243+
pub type_: ::__u16,
244+
pub code: ::__u16,
245+
pub value: ::__s32,
246+
}
247+
248+
pub struct input_id {
249+
pub bustype: ::__u16,
250+
pub vendor: ::__u16,
251+
pub product: ::__u16,
252+
pub version: ::__u16,
253+
}
254+
255+
pub struct input_absinfo {
256+
pub value: ::__s32,
257+
pub minimum: ::__s32,
258+
pub maximum: ::__s32,
259+
pub fuzz: ::__s32,
260+
pub flat: ::__s32,
261+
pub resolution: ::__s32,
262+
}
263+
264+
pub struct input_keymap_entry {
265+
pub flags: ::__u8,
266+
pub len: ::__u8,
267+
pub index: ::__u16,
268+
pub keycode: ::__u32,
269+
pub scancode: [::__u8; 32],
270+
}
271+
272+
pub struct input_mask {
273+
pub type_: ::__u32,
274+
pub codes_size: ::__u32,
275+
pub codes_ptr: ::__u64,
276+
}
277+
278+
pub struct ff_replay {
279+
pub length: ::__u16,
280+
pub delay: ::__u16,
281+
}
282+
283+
pub struct ff_trigger {
284+
pub button: ::__u16,
285+
pub interval: ::__u16,
286+
}
287+
288+
pub struct ff_envelope {
289+
pub attack_length: ::__u16,
290+
pub attack_level: ::__u16,
291+
pub fade_length: ::__u16,
292+
pub fade_level: ::__u16,
293+
}
294+
295+
pub struct ff_constant_effect {
296+
pub level: ::__s16,
297+
pub envelope: ff_envelope,
298+
}
299+
300+
pub struct ff_ramp_effect {
301+
pub start_level: ::__s16,
302+
pub end_level: ::__s16,
303+
pub envelope: ff_envelope,
304+
}
305+
306+
pub struct ff_condition_effect {
307+
pub right_saturation: ::__u16,
308+
pub left_saturation: ::__u16,
309+
310+
pub right_coeff: ::__s16,
311+
pub left_coeff: ::__s16,
312+
313+
pub deadband: ::__u16,
314+
pub center: ::__s16,
315+
}
316+
317+
pub struct ff_periodic_effect {
318+
pub waveform: ::__u16,
319+
pub period: ::__u16,
320+
pub magnitude: ::__s16,
321+
pub offset: ::__s16,
322+
pub phase: ::__u16,
323+
324+
pub envelope: ff_envelope,
325+
326+
pub custom_len: ::__u32,
327+
pub custom_data: *mut ::__s16,
328+
}
329+
330+
pub struct ff_rumble_effect {
331+
pub strong_magnitude: ::__u16,
332+
pub weak_magnitude: ::__u16,
333+
}
334+
335+
pub struct ff_effect {
336+
pub type_: ::__u16,
337+
pub id: ::__s16,
338+
pub direction: ::__u16,
339+
pub trigger: ff_trigger,
340+
pub replay: ff_replay,
341+
// FIXME this is actually a union
342+
#[cfg(target_pointer_width = "64")]
343+
pub u: [u64; 4],
344+
#[cfg(target_pointer_width = "32")]
345+
pub u: [u32; 7],
346+
}
234347
}
235348

236349
pub const ABDAY_1: ::nl_item = 0x20000;

src/unix/notbsd/linux/musl/b32/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub type c_long = i32;
22
pub type c_ulong = u32;
33
pub type nlink_t = u32;
4+
pub type __u64 = ::c_ulonglong;
45

56
s! {
67
pub struct pthread_attr_t {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub type c_char = u8;
2+
pub type __u64 = ::c_ulonglong;
23

34
pub const SYS_perf_event_open: ::c_long = 241;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub type c_char = u8;
2+
pub type __u64 = ::c_ulong;
23

34
pub const SYS_perf_event_open: ::c_long = 319;

src/unix/notbsd/linux/musl/b64/x86_64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub type c_char = i8;
2+
pub type __u64 = ::c_ulonglong;
23

34
s! {
45
pub struct mcontext_t {

src/unix/notbsd/linux/other/b32/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub type __fsword_t = i32;
1212

1313
pub type blksize_t = i32;
1414
pub type nlink_t = u32;
15+
pub type __u64 = ::c_ulonglong;
1516

1617
s! {
1718
pub struct stat {

src/unix/notbsd/linux/other/b64/aarch64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub type wchar_t = u32;
55
pub type nlink_t = u32;
66
pub type blksize_t = i32;
77
pub type suseconds_t = i64;
8+
pub type __u64 = ::c_ulonglong;
89

910
s! {
1011
pub struct stat {

src/unix/notbsd/linux/other/b64/powerpc64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub type wchar_t = i32;
55
pub type nlink_t = u64;
66
pub type blksize_t = i64;
77
pub type suseconds_t = i64;
8+
pub type __u64 = ::c_ulong;
89

910
s! {
1011
pub struct stat {

src/unix/notbsd/linux/other/b64/sparc64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub type wchar_t = i32;
55
pub type nlink_t = u32;
66
pub type blksize_t = i64;
77
pub type suseconds_t = i32;
8+
pub type __u64 = ::c_ulonglong;
89

910
s! {
1011
pub struct stat {

src/unix/notbsd/linux/other/b64/x86_64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub type nlink_t = u64;
66
pub type blksize_t = i64;
77
pub type greg_t = i64;
88
pub type suseconds_t = i64;
9+
pub type __u64 = ::c_ulonglong;
910

1011
s! {
1112
pub struct stat {

0 commit comments

Comments
 (0)