#device-tree #compiler #build #cargo #cargo-build #platform #dtc

app cargo-dtc

Devicetree Compiler packaged for building with cargo

7 releases (stable)

1.7.5 Oct 24, 2024
1.7.3 Aug 20, 2024
1.7.2 Jul 30, 2024
1.7.1 Jul 22, 2024

#61 in Cargo plugins

Download history 349/week @ 2024-07-27 32/week @ 2024-08-03 9/week @ 2024-08-10 248/week @ 2024-08-17 74/week @ 2024-08-24 8/week @ 2024-08-31 77/week @ 2024-09-07 209/week @ 2024-09-14 25/week @ 2024-09-21 29/week @ 2024-09-28 9/week @ 2024-10-05 15/week @ 2024-10-12 299/week @ 2024-10-19 45/week @ 2024-10-26 42/week @ 2024-11-02 8/week @ 2024-11-09

395 downloads per month

GPL-2.0-or-later

325KB
9K SLoC

C 9K SLoC // 0.1% comments Rust 88 SLoC // 0.0% comments

Devicetree Compiler for Rust

Wrap the dtc source code in Rust to make it easier to build for non-Posix platforms.

The binary is named cargo-dtc to avoid conflicts with the original dtc binary.

Licensing

This project wraps the GPL2-licensed dtc code. As such, this project is also licensed under GPL2.

Development Process

Generated files (namely the flex and bison grammar files) were generated and the resulting file copied to dtc. Original files may be consulted from the original source.

Any non-Posix code was adapted to build under more strict compilers.

The main() was renamed to dtc_main() and is wrapped by Rust.

Changes from dtc

The original version of dtc is available as a submodule in the dtc-orig directory. The code in this directory is unused, and it serves to provide a reference for the changes made to the original code.

The following changes were made:

  • The directory structure was reorganized to be more idiomatic for Rust.
  • Preprocessed versions of dtc-lexer.lex.l and dtc-parser.tab.y were copied to dtc/src/ and are used to avoid needing to install flex and bison.
  • To work around __VA_ARGS__ in MSVC, the CHECK_ENTRY() macro inserts a NULL element at the start of the array. checks.c was modified to ignore the first element.
  • The ternary operator in treesource.c was modified to be C99 compliant.
  • The main() function was renamed to dtc_main() and is wrapped by Rust.
  • strcasecmp is renamed to _stricmp inside dtc.c via a macro.
  • On Windows, getopt.c was taken from https://github.com/Chunde/getopt-for-windows as a drop-in replacement for the one from glibc.
  • On Windows, dirent.h was taken from https://github.com/tronkko/dirent.
  • On Windows, a fake unistd.h was added that renames main and chain-includes dirent.h to define S_ISDIR and S_ISREG.
  • On other platforms, build.rs performs the rename of main.
  • A fake version_gen.h gets generated indicating it comes from Rust.

A note on version numbers

The version numbers are, unfortunately, out of sync with upstream. This will continue until upstream dtc reaches version 1.8.0.

No runtime deps

~0–280KB