Fix "can't find crate for std" for stm32-metapac-gen deps.

This commit is contained in:
Dario Nieuwenhuis 2021-07-13 05:47:10 +02:00
parent 549ddf7fc8
commit 1d64421fb4
9 changed files with 34 additions and 28 deletions

View File

@ -142,4 +142,4 @@ jobs:
with: with:
toolchain: stable toolchain: stable
- name: Generate pregenerated metapac - name: Generate pregenerated metapac
run: cd stm32-metapac/gen; cargo run --release run: cd stm32-metapac-gen; cargo run --release

View File

@ -47,6 +47,12 @@ members = [
#"examples/std", #"examples/std",
] ]
exclude = [
# This is only built as a build-dependency, for the host. It shouldn't
# get built for the target.
"stm32-metapac-gen"
]
[profile.dev] [profile.dev]
codegen-units = 1 codegen-units = 1
debug = 2 debug = 2

View File

@ -128,18 +128,17 @@ fn find_reg_for_field<'c>(
} }
fn make_peripheral_counts(out: &mut String, data: &HashMap<String, u8>) { fn make_peripheral_counts(out: &mut String, data: &HashMap<String, u8>) {
write!(out, write!(
out,
"#[macro_export] "#[macro_export]
macro_rules! peripheral_count {{ macro_rules! peripheral_count {{
").unwrap(); "
)
.unwrap();
for (name, count) in data { for (name, count) in data {
write!(out, write!(out, "({}) => ({});\n", name, count,).unwrap();
"({}) => ({});\n",
name, count,
).unwrap();
} }
write!(out, write!(out, " }}\n").unwrap();
" }}\n").unwrap();
} }
fn make_table(out: &mut String, name: &str, data: &Vec<Vec<String>>) { fn make_table(out: &mut String, name: &str, data: &Vec<Vec<String>>) {
@ -487,7 +486,11 @@ pub fn gen(options: Options) {
make_table(&mut extra, "peripherals", &peripherals_table); make_table(&mut extra, "peripherals", &peripherals_table);
make_table(&mut extra, "peripheral_versions", &peripheral_version_table); make_table(&mut extra, "peripheral_versions", &peripheral_version_table);
make_table(&mut extra, "peripheral_pins", &peripheral_pins_table); make_table(&mut extra, "peripheral_pins", &peripheral_pins_table);
make_table(&mut extra, "peripheral_dma_channels", &peripheral_dma_channels_table); make_table(
&mut extra,
"peripheral_dma_channels",
&peripheral_dma_channels_table,
);
make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table); make_table(&mut extra, "peripheral_rcc", &peripheral_rcc_table);
make_table(&mut extra, "dma_channels", &dma_channels_table); make_table(&mut extra, "dma_channels", &dma_channels_table);
make_table(&mut extra, "dma_requests", &dma_requests_table); make_table(&mut extra, "dma_requests", &dma_requests_table);
@ -618,7 +621,7 @@ pub fn gen(options: Options) {
// Generate src/lib.rs // Generate src/lib.rs
const CUT_MARKER: &[u8] = b"// GEN CUT HERE"; const CUT_MARKER: &[u8] = b"// GEN CUT HERE";
let librs = include_bytes!("../../src/lib.rs"); let librs = include_bytes!("../../stm32-metapac/src/lib.rs");
let i = bytes_find(librs, CUT_MARKER).unwrap(); let i = bytes_find(librs, CUT_MARKER).unwrap();
let mut contents: Vec<u8> = Vec::new(); let mut contents: Vec<u8> = Vec::new();
contents.extend(&librs[..i]); contents.extend(&librs[..i]);
@ -636,7 +639,7 @@ pub fn gen(options: Options) {
const BUILDDEP_BEGIN: &[u8] = b"# BEGIN BUILD DEPENDENCIES"; const BUILDDEP_BEGIN: &[u8] = b"# BEGIN BUILD DEPENDENCIES";
const BUILDDEP_END: &[u8] = b"# END BUILD DEPENDENCIES"; const BUILDDEP_END: &[u8] = b"# END BUILD DEPENDENCIES";
let mut contents = include_bytes!("../../Cargo.toml").to_vec(); let mut contents = include_bytes!("../../stm32-metapac/Cargo.toml").to_vec();
let begin = bytes_find(&contents, BUILDDEP_BEGIN).unwrap(); let begin = bytes_find(&contents, BUILDDEP_BEGIN).unwrap();
let end = bytes_find(&contents, BUILDDEP_END).unwrap() + BUILDDEP_END.len(); let end = bytes_find(&contents, BUILDDEP_END).unwrap() + BUILDDEP_END.len();
contents.drain(begin..end); contents.drain(begin..end);

View File

@ -3,7 +3,7 @@ use stm32_metapac_gen::*;
fn main() { fn main() {
let out_dir = PathBuf::from("out"); let out_dir = PathBuf::from("out");
let data_dir = PathBuf::from("../../stm32-data/data"); let data_dir = PathBuf::from("../stm32-data/data");
let chips = std::fs::read_dir(data_dir.join("chips")) let chips = std::fs::read_dir(data_dir.join("chips"))
.unwrap() .unwrap()

View File

@ -11,7 +11,7 @@ cortex-m-rt = { version = "0.6.8", optional = true }
# BEGIN BUILD DEPENDENCIES # BEGIN BUILD DEPENDENCIES
# These are removed when generating the pre-generated crate using the tool at gen/. # These are removed when generating the pre-generated crate using the tool at gen/.
[build-dependencies] [build-dependencies]
stm32-metapac-gen = { path = "./gen" } stm32-metapac-gen = { path = "../stm32-metapac-gen" }
regex = "1.5.4" regex = "1.5.4"
# END BUILD DEPENDENCIES # END BUILD DEPENDENCIES

View File

@ -1,3 +0,0 @@
{
"editor.formatOnSave": true
}