diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b2b7ee099..2035c96dc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -142,4 +142,4 @@ jobs: with: toolchain: stable - name: Generate pregenerated metapac - run: cd stm32-metapac/gen; cargo run --release + run: cd stm32-metapac-gen; cargo run --release diff --git a/Cargo.example.toml b/Cargo.example.toml index c615d29ad..cbb221e7b 100644 --- a/Cargo.example.toml +++ b/Cargo.example.toml @@ -47,6 +47,12 @@ members = [ #"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] codegen-units = 1 debug = 2 diff --git a/stm32-metapac/gen/Cargo.toml b/stm32-metapac-gen/Cargo.toml similarity index 100% rename from stm32-metapac/gen/Cargo.toml rename to stm32-metapac-gen/Cargo.toml diff --git a/stm32-metapac/gen/src/assets/build.rs b/stm32-metapac-gen/src/assets/build.rs similarity index 100% rename from stm32-metapac/gen/src/assets/build.rs rename to stm32-metapac-gen/src/assets/build.rs diff --git a/stm32-metapac/gen/src/assets/lib_inner.rs b/stm32-metapac-gen/src/assets/lib_inner.rs similarity index 100% rename from stm32-metapac/gen/src/assets/lib_inner.rs rename to stm32-metapac-gen/src/assets/lib_inner.rs diff --git a/stm32-metapac/gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs similarity index 97% rename from stm32-metapac/gen/src/lib.rs rename to stm32-metapac-gen/src/lib.rs index 8eae49111..978f70b92 100644 --- a/stm32-metapac/gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs @@ -128,18 +128,17 @@ fn find_reg_for_field<'c>( } fn make_peripheral_counts(out: &mut String, data: &HashMap) { - write!(out, - "#[macro_export] + write!( + out, + "#[macro_export] macro_rules! peripheral_count {{ - ").unwrap(); + " + ) + .unwrap(); for (name, count) in data { - write!(out, - "({}) => ({});\n", - name, count, - ).unwrap(); + write!(out, "({}) => ({});\n", name, count,).unwrap(); } - write!(out, - " }}\n").unwrap(); + write!(out, " }}\n").unwrap(); } fn make_table(out: &mut String, name: &str, data: &Vec>) { @@ -155,7 +154,7 @@ macro_rules! {} {{ ", name, name ) - .unwrap(); + .unwrap(); for row in data { write!(out, " __{}_inner!(({}));\n", name, row.join(",")).unwrap(); @@ -166,7 +165,7 @@ macro_rules! {} {{ " }}; }}" ) - .unwrap(); + .unwrap(); } pub struct Options { @@ -341,7 +340,7 @@ pub fn gen(options: Options) { peripherals_table.push(peripheral_row); if let Some(old_version) = - peripheral_versions.insert(bi.module.clone(), bi.version.clone()) + peripheral_versions.insert(bi.module.clone(), bi.version.clone()) { if old_version != bi.version { panic!( @@ -487,7 +486,11 @@ pub fn gen(options: Options) { make_table(&mut extra, "peripherals", &peripherals_table); make_table(&mut extra, "peripheral_versions", &peripheral_version_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, "dma_channels", &dma_channels_table); make_table(&mut extra, "dma_requests", &dma_requests_table); @@ -500,7 +503,7 @@ pub fn gen(options: Options) { "#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n", module, version, module ) - .unwrap(); + .unwrap(); } // Cleanups! @@ -538,7 +541,7 @@ pub fn gen(options: Options) { "PROVIDE({} = DefaultHandler);\n", name.to_ascii_uppercase() ) - .unwrap(); + .unwrap(); } File::create(chip_dir.join("device.x")) @@ -566,7 +569,7 @@ pub fn gen(options: Options) { transform::NameKind::Enum => format!("vals::{}", s), _ => s.to_string(), }) - .unwrap(); + .unwrap(); transform::sort::Sort {}.run(&mut ir).unwrap(); transform::Sanitize {}.run(&mut ir).unwrap(); @@ -577,7 +580,7 @@ pub fn gen(options: Options) { .join("src/peripherals") .join(format!("{}_{}.rs", module, version)), ) - .unwrap(); + .unwrap(); let data = items.to_string().replace("] ", "]\n"); // Remove inner attributes like #![no_std] @@ -600,14 +603,14 @@ pub fn gen(options: Options) { "#[cfg_attr(feature=\"{}_{}\", path = \"chips/{}_{}/pac.rs\")]", x, c, x, c ) - .unwrap(); + .unwrap(); } else { write!( &mut paths, "#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]", x, x ) - .unwrap(); + .unwrap(); } } let mut contents: Vec = Vec::new(); @@ -618,7 +621,7 @@ pub fn gen(options: Options) { // Generate src/lib.rs 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 mut contents: Vec = Vec::new(); contents.extend(&librs[..i]); @@ -630,13 +633,13 @@ pub fn gen(options: Options) { out_dir.join("src").join("common.rs"), generate::COMMON_MODULE, ) - .unwrap(); + .unwrap(); // Generate Cargo.toml const BUILDDEP_BEGIN: &[u8] = b"# BEGIN 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 end = bytes_find(&contents, BUILDDEP_END).unwrap() + BUILDDEP_END.len(); contents.drain(begin..end); diff --git a/stm32-metapac/gen/src/main.rs b/stm32-metapac-gen/src/main.rs similarity index 90% rename from stm32-metapac/gen/src/main.rs rename to stm32-metapac-gen/src/main.rs index bb76b9167..31f684046 100644 --- a/stm32-metapac/gen/src/main.rs +++ b/stm32-metapac-gen/src/main.rs @@ -3,7 +3,7 @@ use stm32_metapac_gen::*; fn main() { 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")) .unwrap() diff --git a/stm32-metapac/Cargo.toml b/stm32-metapac/Cargo.toml index 79f1c3746..2e01d5183 100644 --- a/stm32-metapac/Cargo.toml +++ b/stm32-metapac/Cargo.toml @@ -11,7 +11,7 @@ cortex-m-rt = { version = "0.6.8", optional = true } # BEGIN BUILD DEPENDENCIES # These are removed when generating the pre-generated crate using the tool at gen/. [build-dependencies] -stm32-metapac-gen = { path = "./gen" } +stm32-metapac-gen = { path = "../stm32-metapac-gen" } regex = "1.5.4" # END BUILD DEPENDENCIES diff --git a/stm32-metapac/gen/.vscode/settings.json b/stm32-metapac/gen/.vscode/settings.json deleted file mode 100644 index 23fd35f0e..000000000 --- a/stm32-metapac/gen/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "editor.formatOnSave": true -} \ No newline at end of file