[FL-1171] Remove core-rs (#429)

* core-rs: remove core-rs
* docker: remove rust syntax check

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
gornekich 2021-04-27 19:07:34 +03:00 committed by GitHub
parent b28863ae04
commit 3c990e2f50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 1 additions and 1022 deletions

2
core-rs/.gitignore vendored
View file

@ -1,2 +0,0 @@
/target
/.idea

552
core-rs/Cargo.lock generated
View file

@ -1,552 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86"
dependencies = [
"memchr",
]
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "bindgen"
version = "0.55.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75b13ce559e6433d360c26305643803cb52cfbabbc2b9c47ce04a58493dfb443"
dependencies = [
"bitflags",
"cexpr",
"cfg-if",
"clang-sys",
"clap",
"env_logger",
"lazy_static",
"lazycell",
"log",
"peeking_take_while",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"which",
]
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "cbindgen"
version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e783d38a7700989e0209d0b0ed224c34ade92d3603da0cf15dc502ebada685a6"
dependencies = [
"clap",
"heck",
"log",
"proc-macro2",
"quote",
"serde",
"serde_json",
"syn",
"tempfile",
"toml",
]
[[package]]
name = "cexpr"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27"
dependencies = [
"nom",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "clang-sys"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9da1484c6a890e374ca5086062d4847e0a2c1e5eba9afa5d48c09e8eb39b2519"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "clap"
version = "2.33.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "env_logger"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "flipper-core"
version = "0.1.0"
dependencies = [
"cbindgen",
"flipper-f1-sys",
]
[[package]]
name = "flipper-f1-sys"
version = "0.1.0"
dependencies = [
"bindgen",
]
[[package]]
name = "getrandom"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9"
dependencies = [
"libc",
]
[[package]]
name = "humantime"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
dependencies = [
"quick-error",
]
[[package]]
name = "itoa"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3"
[[package]]
name = "libloading"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2443d8f0478b16759158b2f66d525991a05491138bc05814ef52a250148ef4f9"
dependencies = [
"cfg-if",
"winapi",
]
[[package]]
name = "log"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
"memchr",
"version_check",
]
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "ppv-lite86"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20"
[[package]]
name = "proc-macro2"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom",
"libc",
"rand_chacha",
"rand_core",
"rand_hc",
]
[[package]]
name = "rand_chacha"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"getrandom",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "regex"
version = "1.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
"thread_local",
]
[[package]]
name = "regex-syntax"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
[[package]]
name = "remove_dir_all"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
"winapi",
]
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "serde"
version = "1.0.115"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.115"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "shlex"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "syn"
version = "1.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "tempfile"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
dependencies = [
"cfg-if",
"libc",
"rand",
"redox_syscall",
"remove_dir_all",
"winapi",
]
[[package]]
name = "termcolor"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "thread_local"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
dependencies = [
"lazy_static",
]
[[package]]
name = "toml"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
dependencies = [
"serde",
]
[[package]]
name = "unicode-segmentation"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "unicode-xid"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "which"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724"
dependencies = [
"libc",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View file

@ -1,14 +0,0 @@
[workspace]
members = [
"flipper-core",
"flipper-f1-sys",
]
[profile.release]
codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size on Flash
lto = true # better optimizations
panic = "abort"
[profile.dev]
panic = "abort"

View file

@ -1,42 +0,0 @@
#######################################
# Rust library
#######################################
#######################################
# Rust library
#######################################
RUST_LIB_SRC = $(realpath $(PROJECT_DIR)/../core-rs)
RUST_LIB_NAME = flipper_core
ifeq ($(ARCH), 'x86_64')
RUST_LIB_TARGET = x86_64-unknown-linux-gnu
else
RUST_LIB_TARGET = thumbv7em-none-eabihf
endif
RUST_LIB_FLAGS = --target=$(RUST_LIB_TARGET)
ifeq ($(DEBUG), 1)
RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/debug
else
RUST_LIB_FLAGS += --release
RUST_LIB_PATH = $(RUST_LIB_SRC)/target/$(RUST_LIB_TARGET)/release
endif
RUST_LIB_CMD = cd $(RUST_LIB_SRC) && cargo build -p flipper-core $(RUST_LIB_FLAGS)
LD_FLAGS += -l$(RUST_LIB_NAME)
LD_FLAGS += -L$(RUST_LIB_PATH)
$(RUST_LIB_PATH)/lib$(RUST_LIB_NAME).a: rust_lib
rust_lib:
$(RUST_LIB_CMD)
clean:
-rm -fR $(BUILD_DIR)
cd $(RUST_LIB_SRC) && cargo clean

View file

@ -1,3 +0,0 @@
/bindings
/target
/Cargo.lock

View file

@ -1,23 +0,0 @@
[package]
name = "flipper-core"
version = "0.1.0"
authors = ["Vadim Kaushan <admin@disasm.info>"]
edition = "2018"
[lib]
crate-type = ["staticlib"]
[target.'cfg(target_arch = "arm")'.dependencies]
flipper-f1-sys = { path = "../flipper-f1-sys" }
[build-dependencies]
cbindgen = "0.14"
[profile.release]
codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size on Flash
lto = true # better optimizations
panic = "abort"
[profile.dev]
panic = "abort"

View file

@ -1,15 +0,0 @@
use std::env;
use std::path::Path;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let pkg_name = env::var("CARGO_PKG_NAME").unwrap();
cbindgen::generate(&crate_dir)
.expect("Unable to generate cbindgen bindings")
.write_to_file(
Path::new(&crate_dir)
.join("bindings")
.join(format!("{}.h", pkg_name)),
);
}

View file

@ -1,4 +0,0 @@
language = "C"
[export]
item_types = ["functions"]

View file

@ -1,39 +0,0 @@
#![no_std]
#[cfg(target_arch = "arm")]
use flipper_f1_sys::hal::{huart1, HAL_UART_Transmit_IT};
#[no_mangle]
pub extern "C" fn add(a: u32, b: u32) -> u32 {
a + b
}
#[no_mangle]
pub extern "C" fn rust_uart_write() {
let string = "Rust test string\n";
let bytes = string.as_bytes();
#[cfg(target_arch = "arm")]
unsafe {
HAL_UART_Transmit_IT(&mut huart1, bytes.as_ptr() as *mut _, bytes.len() as u16);
}
#[cfg(not(target_arch = "arm"))]
unsafe {
extern "C" {
fn write(handle: i32, ptr: *const u8, size: usize) -> isize;
}
write(1, bytes.as_ptr(), bytes.len());
}
}
mod aux {
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {
continue;
}
}
}

View file

@ -1,2 +0,0 @@
/target
/Cargo.lock

View file

@ -1,12 +0,0 @@
[package]
name = "flipper-f1-sys"
version = "0.1.0"
authors = ["Vadim Kaushan <admin@disasm.info>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
[build-dependencies]
bindgen = "0.55"

View file

@ -1,288 +0,0 @@
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
fn main() {
println!("cargo:rerun-if-env-changed=FORCE_BINDGEN");
let generator = BindingsGenerator::new();
generator.generate_cmsis_os_bindings();
generator.generate_stm32_hal_bindings();
generator.generate_stm32_hal_statics();
}
struct BindingsGenerator {
clib_dir: PathBuf,
workspace_dir: PathBuf,
out_dir: PathBuf,
gcc_include_dir: PathBuf,
force_bindgen: bool,
}
impl BindingsGenerator {
pub fn new() -> Self {
let out_dir = env::var("OUT_DIR").unwrap();
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let workspace_dir = Path::new(&crate_dir).parent().unwrap();
let clib_dir = workspace_dir.parent().unwrap().join("target_f1");
assert!(clib_dir.is_dir());
let force_bindgen: bool = std::env::var_os("FORCE_BINDGEN").is_some();
let gcc_include_dir = detect_gcc_inclide_dir();
Self {
clib_dir: clib_dir.to_path_buf(),
workspace_dir: workspace_dir.to_path_buf(),
out_dir: Path::new(&out_dir).to_path_buf(),
gcc_include_dir,
force_bindgen,
}
}
fn builder(&self) -> bindgen::Builder {
let stm32_sdk_includes = [
"Inc",
"Drivers/STM32L4xx_HAL_Driver/Inc",
"Drivers/STM32L4xx_HAL_Driver/Inc/Legacy",
"Middlewares/Third_Party/FreeRTOS/Source/include",
"Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS",
"Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F",
"Drivers/CMSIS/Device/ST/STM32L4xx/Include",
"Drivers/CMSIS/Include",
"Middlewares/ST/STM32_USB_Device_Library/Core/Inc",
"Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc",
];
let stm32_sdk_includes = stm32_sdk_includes
.iter()
.map(|stm32_include| format!("{}/{}", self.clib_dir.to_string_lossy(), stm32_include));
let flipper_core_bindings = self.workspace_dir.join("flipper-core").join("bindings");
let includes = [
// This are bindings generated by cbindgen nearby
&flipper_core_bindings.to_string_lossy(),
&self.gcc_include_dir.to_string_lossy(),
];
#[rustfmt::skip]
return bindgen::Builder::default()
.use_core()
.ctypes_prefix("self")
.blacklist_type("__uint8_t")
.blacklist_type("__uint32_t")
.blacklist_type("c_int")
.blacklist_type("__int32_t")
// TODO there's no .no_debug method, to disable only for specific type
.derive_debug(false)
.clang_arg("-DUSE_HAL_DRIVER")
.clang_arg("-DSTM32L476xx")
.clang_arg("-DBUTON_INVERT=false")
.clang_arg("-DDEBUG_UART=huart1")
.clang_args(
(includes.iter().map(|x| From::from(x as &str)).chain(stm32_sdk_includes))
.map(|include| format!("-I{}", include))
)
.clang_arg("--target=thumbv7em-none-eabihf")
.clang_arg("--verbose")
//.clang_arg("-nostdinc")
;
}
pub fn generate_cmsis_os_bindings(&self) {
let result_path = self.out_dir.join("cmsis_os_bindings.rs");
let should_build = !result_path.is_file() || self.force_bindgen;
if !should_build {
return;
}
println!("cargo:warning=writing cmsis os bindings");
#[rustfmt::skip]
let builder = self.builder()
.whitelist_recursively(false)
.header(format!("{}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS/cmsis_os.h", self.clib_dir.to_string_lossy()))
.whitelist_type("osStatus")
.rustified_enum("osStatus")
.whitelist_type("osEvent")
.whitelist_type("os_pthread")
.whitelist_type("osThreadId")
.opaque_type("osThreadId")
.whitelist_type("os_thread_def")
.whitelist_type("osThreadDef_t")
.whitelist_type("osStaticThreadDef_t")
.opaque_type("osStaticThreadDef_t")
.whitelist_type("osPriority")
.rustified_enum("osPriority")
.whitelist_function("osThreadCreate")
.whitelist_function("osThreadGetId")
.whitelist_function("osThreadTerminate")
.whitelist_function("osThreadYield")
.whitelist_type("osMutexId")
.opaque_type("osMutexId")
.whitelist_type("os_mutex_def")
.whitelist_type("osMutexDef_t")
.whitelist_type("osStaticMutexDef_t")
.opaque_type("osStaticMutexDef_t")
.whitelist_function("osMutexCreate")
.whitelist_function("osMutexWait")
.whitelist_function("osMutexRelease")
.whitelist_type("osSemaphoreId")
.opaque_type("osSemaphoreId")
.whitelist_type("os_semaphore_def")
.whitelist_type("osSemaphoreDef_t")
.whitelist_type("osStaticSemaphoreDef_t")
.opaque_type("osStaticSemaphoreDef_t")
.whitelist_function("osSemaphoreCreate")
.whitelist_function("osSemaphoreWait")
.whitelist_function("osSemaphoreRelease")
.whitelist_type("osMessageQId")
.opaque_type("osMessageQId")
.whitelist_type("osMailQId")
.opaque_type("osMailQId")
.whitelist_type("os_mailQ_def")
.whitelist_type("osMailQDef_t")
.whitelist_type("os_mailQ_cb")
.whitelist_function("osMailCreate")
.whitelist_function("osMailAlloc")
.whitelist_function("osMailFree")
.whitelist_function("osMailPut")
.whitelist_function("osMailGet")
.whitelist_var("osWaitForever")
.whitelist_function("osDelay")
// TODO for some reason, bindgen wont generate osKernelSysTickFrequency
.whitelist_var("osKernelSysTickFrequency")
.whitelist_function("osKernelSysTick")
;
let bindings = builder.generate().expect("Unable to generate bindings");
bindings
.write_to_file(result_path)
.expect("Couldn't write bindings!");
}
pub fn generate_stm32_hal_bindings(&self) {
let result_path = self.out_dir.join("stm32_hal_bindings.rs");
let should_build = !result_path.is_file() || self.force_bindgen;
if !should_build {
return;
}
println!("cargo:warning=writing STM32 HAL bindings");
#[rustfmt::skip]
let builder = self.builder()
.whitelist_recursively(false)
.header(format!("{}/Drivers/STM32L4xx_HAL_Driver/Inc/stm32l4xx_hal.h", self.clib_dir.to_string_lossy()))
.whitelist_type("HAL_StatusTypeDef")
.rustified_enum("HAL_StatusTypeDef")
.whitelist_type("GPIO_TypeDef")
.opaque_type("GPIO_TypeDef")
.whitelist_type("GPIO_PinState")
.rustified_enum("GPIO_PinState")
.whitelist_function("HAL_GPIO_WritePin")
.whitelist_function("HAL_GPIO_TogglePin")
.whitelist_function("HAL_GPIO_ReadPin")
.whitelist_type("UART_HandleTypeDef")
.opaque_type("UART_HandleTypeDef")
.whitelist_function("HAL_UART_Transmit_IT")
.whitelist_type("SPI_HandleTypeDef")
.opaque_type("SPI_HandleTypeDef")
.whitelist_function("HAL_SPI_Transmit_IT")
.whitelist_function("HAL_SPI_Receive_IT")
.whitelist_function("HAL_SPI_TransmitReceive_IT")
.whitelist_type("ADC_HandleTypeDef")
.opaque_type("ADC_HandleTypeDef")
.whitelist_type("COMP_HandleTypeDef")
.opaque_type("COMP_HandleTypeDef")
.whitelist_type("DAC_HandleTypeDef")
.opaque_type("DAC_HandleTypeDef")
.whitelist_type("TIM_HandleTypeDef")
.opaque_type("TIM_HandleTypeDef")
;
let bindings = builder.generate().expect("Unable to generate bindings");
bindings
.write_to_file(result_path)
.expect("Couldn't write bindings!");
}
pub fn generate_stm32_hal_statics(&self) {
let result_path = self.out_dir.join("stm32_hal_statics.rs");
let should_build = !result_path.is_file() || self.force_bindgen;
if !should_build {
return;
}
println!("cargo:warning=writing STM32 HAL bindings");
#[rustfmt::skip]
let builder = self.builder()
.whitelist_recursively(false)
.header(format!("{}/Src/main.c", self.clib_dir.to_string_lossy()))
.whitelist_var(".*_Pin")
.whitelist_var(".*_Port")
.whitelist_var("HAL_.*_Pin")
.whitelist_var("HAL_.*_Port")
.whitelist_var("hadc[0-9]+")
.whitelist_var("hcomp[0-9]+")
.whitelist_var("hdac[0-9]+")
.whitelist_var("hspi[0-9]+")
.whitelist_var("htim[0-9]+")
.whitelist_var("huart[0-9]+")
;
let bindings = builder.generate().expect("Unable to generate bindings");
bindings
.write_to_file(result_path)
.expect("Couldn't write bindings!");
}
}
fn detect_gcc_inclide_dir() -> PathBuf {
let base_path = Path::new("/usr/lib/gcc/arm-none-eabi");
if !base_path.is_dir() {
panic!("Can't find arm-none-eabi-gcc lib directory");
}
let entries = fs::read_dir(base_path).expect("Can't read arm-none-eabi-gcc lib directory");
for entry in entries {
let entry = entry.expect("Can't read dir entry");
let path = entry.path();
if path.is_dir() {
let include_dir = path.join("include");
if include_dir.is_dir() {
return include_dir.to_path_buf();
}
}
}
panic!("Can't find arm-none-eabi-gcc include directory");
}

View file

@ -1,19 +0,0 @@
#![no_std]
#![allow(dead_code)]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
pub mod cmsis_os {
#[allow(non_camel_case_types)]
pub use core::ffi::c_void;
#[allow(non_camel_case_types)]
pub type c_char = i8;
include!(concat!(env!("OUT_DIR"), "/cmsis_os_bindings.rs"));
}
pub mod hal {
include!(concat!(env!("OUT_DIR"), "/stm32_hal_bindings.rs"));
include!(concat!(env!("OUT_DIR"), "/stm32_hal_statics.rs"));
}

View file

@ -22,19 +22,13 @@ $CLANG_FORMAT_BIN --version
$CLANG_FORMAT_BIN --verbose -style=file -n --Werror --ferror-limit=0 $C_FILES
c_syntax_rc=$?
echo "RUN RUST SYNTAX CHECK"
cd $PROJECT_DIR/core-rs && cargo fmt -- --check
rust_syntax_rc=$?
if [[ $rust_syntax_rc -eq 0 ]] && [[ $c_syntax_rc -eq 0 ]]; then
if [[ $c_syntax_rc -eq 0 ]]; then
echo "Code looks fine for me!"
exit 0
fi
read -p "Do you want fix syntax? (y/n): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
cd $PROJECT_DIR/core-rs && cargo fmt --
cd $PROJECT_DIR
# We use root in container and clang-format rewriting files. We'll need change owner to original