• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

examples/H03-May-2022-285208

src/H03-May-2022-153124

.cargo-checksum.jsonH A D03-May-202289 11

.gitignoreH A D18-Oct-201518 32

.travis.ymlH A D18-Oct-2015306 2419

Cargo.tomlH A D05-Nov-2015470 2016

LICENSEH A D18-Oct-20151 KiB2117

README.mdH A D18-Oct-20153.1 KiB8159

build.rsH A D18-Oct-20151.4 KiB4938

cross-build.shH A D16-Apr-2015334 105

README.md

1# Libudev Rust Bindings
2
3The `libudev-sys` crate provides declarations and linkage for the `libudev` C library. Following the
4`*-sys` package conventions, the `libudev-sys` crate does not define higher-level abstractions over
5the native `libudev` library functions.
6
7## Dependencies
8In order to use the `libudev-sys` crate, you must have a Linux system with the `libudev` library
9installed where it can be found by `pkg-config`. To install `libudev` on Debian-based Linux
10distributions, execute the following command:
11
12```
13sudo apt-get install libudev-dev
14```
15
16`libudev` is a Linux-specific package. It is not available for Windows, OSX, or other operating
17systems.
18
19### Cross-Compiling
20To link to a cross-compiled version of the native `libudev` library, it's necessary to set several
21environment variables to configure `pkg-config` to work with a cross-compiler's sysroot. [Autotools
22Mythbuster](https://autotools.io/) has a good explanation of [supporting
23cross-compilation](https://autotools.io/pkgconfig/cross-compiling.html) with `pkg-config`.
24
25However, Rust's [`pkg-config` build helper](https://github.com/alexcrichton/pkg-config-rs) doesn't
26support calling a `$CHOST`-prefixed `pkg-config`. It will always call `pkg-config` without a prefix.
27To cross-compile `libudev-sys` with the `pkg-config` build helper, one must define the environment
28variables `PKG_CONFIG_DIR`, `PKG_CONFIG_LIBDIR`, and `PKG_CONFIG_SYSROOT_DIR` for the *default*
29`pkg-config`. It's also necessary to set `PKG_CONFIG_ALLOW_CROSS` to tell Rust's `pkg-config` helper
30that it's okay to proceed with a cross-compile.
31
32To adapt the `pkg-config` wrapper in the Autotools Mythbuster guide so that it works with Rust, one
33will end up with a script similar to the following:
34
35```sh
36#!/bin/sh
37
38SYSROOT=/build/root
39
40export PKG_CONFIG_DIR=
41export PKG_CONFIG_LIBDIR=${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig
42export PKG_CONFIG_SYSROOT_DIR=${SYSROOT}
43export PKG_CONFIG_ALLOW_CROSS=1
44
45cargo build
46```
47
48## Usage
49Add `libudev-sys` as a dependency in `Cargo.toml`:
50
51```toml
52[dependencies]
53libudev-sys = "0.1.1"
54```
55
56Import the `libudev_sys` crate and use the functions as they're defined in the native `libudev`
57library. See the [`libudev` API documention](http://www.freedesktop.org/software/systemd/libudev/)
58for more usage information.
59
60```rust
61extern crate libudev_sys as ffi;
62```
63
64The `libudev-sys` build script detects the presence of native `libudev` functions and exports the
65functions found to exist. `libudev-sys` exports this information from its build script, which Cargo
66will provide to the build scripts of dependent packages in the form of environment variables:
67
68* `DEP_LIBUDEV_HWDB={true,false}`: The native `libudev` library has `udev_hwdb_*` functions. They will be
69  exported by `libudev-sys`.
70
71### Finding Help
72Since `libudev-sys` does nothing more than export symbols from the native `libudev` library, the
73best source for help is the information already available for the native `libudev`:
74
75* [API Documentation](http://www.freedesktop.org/software/systemd/libudev/)
76
77## License
78Copyright © 2015 David Cuddeback
79
80Distributed under the [MIT License](LICENSE).
81