Giter Site home page Giter Site logo

sensors-sys's Introduction

crates.io docs.rs license

sensors-sys: Unsafe Rust bindings for libsensors

lm-sensors provides user-space support for the hardware monitoring drivers in Linux.

This crate is Linux-specific. Building it for non-Linux platforms, or for the Linux kernel, results in an empty crate.

This crate links to libsensors, and requires it to be installed. See below for example installation instructions.

Installing libsensors

This crate links to libsensors, and requires it to be installed.

The library, its C header files, and the clang compiler need to be installed on the build machine. On Debian, for example, one can install that as follows:

$ sudo apt install clang libsensors-dev

If the library is linked dynamically (most typical configuration), then it needs to be installed on the target computer in order to run the resulting program. On Debian, for example, one can install it as follows:

$ sudo apt install libsensors5

Supported environment variables

This crate depends on some environment variables, and variants of those. For each environment variable (e.g., CC), the following are the accepted variants of it:

  • <var>_<target>, e.g., CC_aarch64-unknown-linux-gnu.
  • <var>_<target-with-underscores>, e.g., CC_aarch64_unknown_linux_gnu.
  • TARGET_<var>, e.g., TARGET_CC.
  • <var>, e.g., CC.

The following environment variables (and their variants) affect how this crate is built:

  • LMSENSORS_STATIC
  • LMSENSORS_PATH
  • LMSENSORS_INCLUDE_DIR
  • LMSENSORS_LIB_DIR
  • CC
  • CFLAGS

Dynamic or static linking

This crate links to libsensors dynamically if possible, except when targeting platforms based on the musl C library.

This behavior can be changed either by setting the environment variable LMSENSORS_STATIC to 1, or by enabling the crate feature static. If both are defined, then the value of LMSENSORS_STATIC takes precedence.

Setting LMSENSORS_STATIC to 0 mandates dynamic linking.

Finding lm-sensors library and headers

By default, this crate finds lm-sensors headers and library based on the default target C compiler.

This behavior can be changed by:

  • Either defining the environment variable LMSENSORS_PATH to the path of a directory containing the sub-directories include and lib where the headers and library are installed.
  • Or by defining one or both of the environment variables LMSENSORS_INCLUDE_DIR and LMSENSORS_LIB_DIR to paths to the directories where headers and library are present. If LMSENSORS_PATH is also defined, then LMSENSORS_INCLUDE_DIR and LMSENSORS_LIB_DIR take precedence.

Depending on this crate

This crate provides the following variables to other crates that depend on it:

  • DEP_LMSENSORS_INCLUDE: Path of the directory where library C header files reside.
  • DEP_LMSENSORS_LIB: Path of the directory where the library binary resides.

Documentation-only build mode

The documentation-only build mode allows building documentation even if libsensors and its headers are unavailable. To build in this mode, set the environment variable DOCS_RS to 1:

$ env DOCS_RS=1 cargo doc --open

The generated documentation is based on libsensors version 3.6.0.

โš ๏ธ The generated crate might be unusable in this mode.

Versioning

This project adheres to Semantic Versioning. The CHANGELOG.md file details notable changes over time.

sensors-sys's People

Contributors

koutheir avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

zebp

sensors-sys's Issues

fatal error: 'sensors/sensors.h' file not found when using LMSENSORS_INCLUDE_DIR

I want to generate binding from this version of lm-sensors to get PWM support (i know i will need to fork lm-sensors),
but i get an error when compiling this crate.

This is the env vars i set:

$ export LMSENSORS_INCLUDE_DIR=/home/lenaic/Documents/fan-control-rs/lib/include/
$ export LMSENSORS_LIB_DIR=/home/lenaic/Documents/fan-control-rs/lib/lib
$ export LMSENSORS_STATIC=1

sensors-sys take them into account, i added a dbg!(&include_dir); in the build.rs file to be sure, and this is what is show:

 [/home/lenaic/Documents/sensors-sys/build.rs:80] &include_dir = Some(
      "/home/lenaic/Documents/fan-control-rs/lib/include/",
  )

Include files are here, libs too.

$ ls /home/lenaic/Documents/fan-control-rs/lib/include/sensors/
error.h  sensors.h

And this is the error:

  /home/lenaic/Documents/sensors-sys/sensors-sys.h:2:10: fatal error: 'sensors/sensors.h' file not found
  thread 'main' panicked at /home/lenaic/Documents/sensors-sys/build.rs:371:39:
  sensors-sys: Failed to generate Rust bindings for 'sensors/sensors.h' and other headers: ClangDiagnostic("/home/lenaic/Documents/sensors-sys/sensors-sys.h:2:10: fatal error: 'sensors/sensors.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Is it possible that builder.generate() have no access to ENV var?

let bindings = builder.generate().expect(

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.