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!(
"#[macro_export] out,
"#[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>>) {
@ -155,7 +154,7 @@ macro_rules! {} {{
", ",
name, name name, name
) )
.unwrap(); .unwrap();
for row in data { for row in data {
write!(out, " __{}_inner!(({}));\n", name, row.join(",")).unwrap(); write!(out, " __{}_inner!(({}));\n", name, row.join(",")).unwrap();
@ -166,7 +165,7 @@ macro_rules! {} {{
" }}; " }};
}}" }}"
) )
.unwrap(); .unwrap();
} }
pub struct Options { pub struct Options {
@ -341,7 +340,7 @@ pub fn gen(options: Options) {
peripherals_table.push(peripheral_row); peripherals_table.push(peripheral_row);
if let Some(old_version) = 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 { if old_version != bi.version {
panic!( panic!(
@ -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);
@ -500,7 +503,7 @@ pub fn gen(options: Options) {
"#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n", "#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n",
module, version, module module, version, module
) )
.unwrap(); .unwrap();
} }
// Cleanups! // Cleanups!
@ -538,7 +541,7 @@ pub fn gen(options: Options) {
"PROVIDE({} = DefaultHandler);\n", "PROVIDE({} = DefaultHandler);\n",
name.to_ascii_uppercase() name.to_ascii_uppercase()
) )
.unwrap(); .unwrap();
} }
File::create(chip_dir.join("device.x")) File::create(chip_dir.join("device.x"))
@ -566,7 +569,7 @@ pub fn gen(options: Options) {
transform::NameKind::Enum => format!("vals::{}", s), transform::NameKind::Enum => format!("vals::{}", s),
_ => s.to_string(), _ => s.to_string(),
}) })
.unwrap(); .unwrap();
transform::sort::Sort {}.run(&mut ir).unwrap(); transform::sort::Sort {}.run(&mut ir).unwrap();
transform::Sanitize {}.run(&mut ir).unwrap(); transform::Sanitize {}.run(&mut ir).unwrap();
@ -577,7 +580,7 @@ pub fn gen(options: Options) {
.join("src/peripherals") .join("src/peripherals")
.join(format!("{}_{}.rs", module, version)), .join(format!("{}_{}.rs", module, version)),
) )
.unwrap(); .unwrap();
let data = items.to_string().replace("] ", "]\n"); let data = items.to_string().replace("] ", "]\n");
// Remove inner attributes like #![no_std] // Remove inner attributes like #![no_std]
@ -600,14 +603,14 @@ pub fn gen(options: Options) {
"#[cfg_attr(feature=\"{}_{}\", path = \"chips/{}_{}/pac.rs\")]", "#[cfg_attr(feature=\"{}_{}\", path = \"chips/{}_{}/pac.rs\")]",
x, c, x, c x, c, x, c
) )
.unwrap(); .unwrap();
} else { } else {
write!( write!(
&mut paths, &mut paths,
"#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]", "#[cfg_attr(feature=\"{}\", path = \"chips/{}/pac.rs\")]",
x, x x, x
) )
.unwrap(); .unwrap();
} }
} }
let mut contents: Vec<u8> = Vec::new(); let mut contents: Vec<u8> = Vec::new();
@ -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]);
@ -630,13 +633,13 @@ pub fn gen(options: Options) {
out_dir.join("src").join("common.rs"), out_dir.join("src").join("common.rs"),
generate::COMMON_MODULE, generate::COMMON_MODULE,
) )
.unwrap(); .unwrap();
// Generate Cargo.toml // Generate Cargo.toml
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
}