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 bindgen build zephyr-sys #76337

Merged
merged 18 commits into from
Sep 6, 2024
Merged

Commits on Aug 27, 2024

  1. rust: Create zephyr-sys for low-level bindings

    With a lot of work done by Mario Jaun <mario.jaun@zuehlke.com>.
    
    Use the rust-bindgen tool to extract bindings from the Zephyr header files.
    The tool is run with the exact configuration of the current build, and
    therefore the bindings will match the current target.  The ifdefs and such
    are not translated into the Rust code, and this must be generated live for
    each build.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 27, 2024
    Configuration menu
    Copy the full SHA
    aaf40b5 View commit details
    Browse the repository at this point in the history
  2. rust: Use zephyr-sys to get bindings

    Instead of trying to manually generate the bindings, use those generated by
    bindgen in the zephyr-sys crate.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 27, 2024
    Configuration menu
    Copy the full SHA
    9f71cc7 View commit details
    Browse the repository at this point in the history
  3. rust: Convert k_str_out to bindgen one

    Remove the manual k_str_out wrapper, and use the one generated by bindgen.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 27, 2024
    Configuration menu
    Copy the full SHA
    1d9d675 View commit details
    Browse the repository at this point in the history
  4. include: Add dummy field for Rust as well as CPP

    For CPP builds, a few structs that end up empty in some configurations will
    generate compile errors.  With the Rust tools, bindgen ends up producing
    empty structsw for these as well.  Although the code compiles, it generates
    warnings.  For now, add CONFIG_RUST to the ifdef checks so that these
    structs don't end up empty with Rust either.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 27, 2024
    Configuration menu
    Copy the full SHA
    2046760 View commit details
    Browse the repository at this point in the history
  5. cmake: rust: Compile the bindgen wrapper

    When compiling Rust programs, the bindgen utility generates a wrapper file
    to expand inline functions, as these otherwise cannot be accessed from
    rust.  Pass a consistent name to the cargo build, and add it to our source
    build so that this wrapper get compiled.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 27, 2024
    Configuration menu
    Copy the full SHA
    b1d3ec3 View commit details
    Browse the repository at this point in the history
  6. rust: zephyr-sys: Use absolute path for wrapper

    Change the header passed into bindgen to be an absolute path.  This will
    cause the generated wrapper to refer to this file also using an absolute
    path.  As such, remove the explicit include path added as part of the
    build.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 27, 2024
    Configuration menu
    Copy the full SHA
    865cf5e View commit details
    Browse the repository at this point in the history
  7. doc: rust: Add docs on bindings

    Add documentation on the bindings between Rust and C, and the bindgen
    tool used to generate them.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 27, 2024
    Configuration menu
    Copy the full SHA
    2c3432a View commit details
    Browse the repository at this point in the history
  8. rust: Export zephyr-sys as zephyr::raw

    Re-export all of the bindgen generated bindings in the zephyr-sys crate
    into `zephyr::raw`.  This keeps things easier, as users of `zephyr` only
    need to worry about the single `zephyr` crate.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 27, 2024
    Configuration menu
    Copy the full SHA
    f26c50e View commit details
    Browse the repository at this point in the history

Commits on Aug 28, 2024

  1. cmake: rust: Fix typo on variable name

    Fix `WRAPPER_FiLE` to `WRAPPER_FILE`.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 28, 2024
    Configuration menu
    Copy the full SHA
    fd2061b View commit details
    Browse the repository at this point in the history
  2. rust: Suppress warning about improper C types

    Zephyr takes advantage of a gcc/clang extension that allows structs that
    have no elements.  Rust is perfectly happy with this (it is quite common
    in Rust code), but generates a warning when a struct containing no
    elements is passed to C code.
    
    For now, suppress this warning on the generated bindings.  This has the
    disadvantage of suppressing it entirely, which might possibly detect
    other cases of invalid structs.  However, the bindings are
    auto-generated from C structs so should always be valid.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 28, 2024
    Configuration menu
    Copy the full SHA
    e825732 View commit details
    Browse the repository at this point in the history
  3. Revert "include: Add dummy field for Rust as well as CPP"

    This reverts commit 2046760.
    
    Put these back so we get the zero element structures when using just
    rust and not CPP.  A subsequent patch will suppress the warning.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 28, 2024
    Configuration menu
    Copy the full SHA
    90b90c2 View commit details
    Browse the repository at this point in the history
  4. rust: Workaround gcc/clang differences with soft fp

    GCC automatically defines a `__SOFTFP__` define on targets that are
    using software floating point.  The clang compiler does not do this by
    default, so check this, and define it.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 28, 2024
    Configuration menu
    Copy the full SHA
    23dad4d View commit details
    Browse the repository at this point in the history
  5. rust: zephyr-sys: Fixup clang targets for RISCV

    Rustc for RISCV encodes optional features on the CPU available as part
    of the target tuple.  Clang, on the other hand does not.  In order to be
    able to use libclang with bindgen on RISCV, we need to simplify the
    target tuples a bit.  Do this by just matching 'riscv32' or 'riscv64'
    and then passing in a generic tuple.  We aren't generating any code, and
    the structs should always match between the targets.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 28, 2024
    Configuration menu
    Copy the full SHA
    3373f4e View commit details
    Browse the repository at this point in the history
  6. .gitignore: Ignore Rust 'target' directories

    Although the Cmake rules to build Rust applications keeps the target
    directory inside of the build directory, some IDE tools may generate a
    target directory while editing the code.  Ignore these so they never get
    checked in.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 28, 2024
    Configuration menu
    Copy the full SHA
    7a95c12 View commit details
    Browse the repository at this point in the history

Commits on Aug 29, 2024

  1. cmake: rust: Add header dependencies to cargo

    With bindgen needing to read the headers, make sure CMake knows about
    this.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Aug 29, 2024
    Configuration menu
    Copy the full SHA
    eb68555 View commit details
    Browse the repository at this point in the history

Commits on Sep 5, 2024

  1. doc: develop: rust: Various cleanups to docs

    Minor fixes to the documentation from review feedback.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    6cd9a68 View commit details
    Browse the repository at this point in the history
  2. cmake: rust: Remove redundant call

    Remove a redundant call that does exactly what the previous function
    call accomplishes.
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    2966c8f View commit details
    Browse the repository at this point in the history
  3. cmake: rust: Comment typo fix

    Fix a mispelled word "al" -> "all".
    
    Signed-off-by: David Brown <david.brown@linaro.org>
    d3zd3z committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    7a8dbb1 View commit details
    Browse the repository at this point in the history