Skip to content

Commit

Permalink
Adapt CI to the new build system
Browse files Browse the repository at this point in the history
The temporary SVD files are now generated in $OUT_DIR/svd instead of a
temp directory, so that we can upload them for inspection as part of the
CI output.
  • Loading branch information
LuigiPiucco committed Jan 8, 2025
1 parent 0b724f9 commit 0d3187c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 44 deletions.
43 changes: 5 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,13 @@ jobs:
toolchain: stable

# Rust Dependencies
- name: Cache Cargo installed binaries
uses: actions/cache@v4
id: cache-cargo
with:
path: ~/cargo-bin
key: rust-tools-20250106-001
- name: Install svd2rust
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install svd2rust --version 0.28.0 --locked
- name: Install cargo-form
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install form --version 0.8.0 --locked
- name: Install atdf2svd
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install atdf2svd --version 0.5.0 --locked
- name: Install svdtools
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install svdtools --version 0.4.0 --locked
- name: Copy tools to cache directory
if: steps.cache-cargo.outputs.cache-hit != 'true'
run: |
mkdir ~/cargo-bin
cp ~/.cargo/bin/svd2rust ~/cargo-bin
cp ~/.cargo/bin/form ~/cargo-bin
cp ~/.cargo/bin/atdf2svd ~/cargo-bin
cp ~/.cargo/bin/svdtools ~/cargo-bin
- name: Put new cargo binary directory into path
run: echo "$HOME/cargo-bin" >> $GITHUB_PATH

- name: Install Nightly Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-08-08
components: rustfmt
toolchain: nightly-2025-01-08
components: rust-src,rustfmt

# Actual test run
- name: Generate chip description sources
run: make RUSTUP_TOOLCHAIN=nightly-2023-08-08
- name: Test-compile the crate
run: cargo check --all-features

Expand All @@ -73,7 +42,7 @@ jobs:
with:
name: avr-device
path: |
svd/
target/avr-atmega328p/debug/build/avr-device-*/out/svd/
target/package/avr-device-*.crate
macros/target/package/avr-device-macros-*.crate
Expand All @@ -86,11 +55,9 @@ jobs:
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-12-28
toolchain: nightly-2025-01-08
components: rust-src,rustfmt
- name: Install AVR gcc, binutils, and libc
run: sudo apt-get install -y avr-libc binutils-avr gcc-avr
- name: Build ATmega328P example
run: cd examples/atmega328p && cargo build
- name: Check ATmega328P formatting
run: cd examples/atmega328p && cargo fmt --check
run: cargo build --example atmega328p --features atmega328p,rt
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include = [
"/src/**/*.rs",
"/vendor/*.atdf",
"/vendor/LICENSE",
"/examples/**/src/*.rs"
]

[package.metadata.docs.rs]
Expand Down
16 changes: 10 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ fn build_mcu_module(mcu: &str) {
let patch_file = patch_dir.join(format!("{}.yaml", mcu));
println!("cargo::rerun-if-changed={}", patch_file.display());

let out_dir = env::var("OUT_DIR").unwrap();
// Get a temporary directory to work inside.
let temp_dir = env::temp_dir().join(format!("avr-device-build-{}", mcu));
ensure_directory(&temp_dir);
let svd_dir = Path::new(&out_dir).join("svd");
ensure_directory(&svd_dir);
let svd_unpatched_dir = svd_dir.join("unpatched");
ensure_directory(&svd_unpatched_dir);
let svd_patched_dir = svd_dir.join("patched");
ensure_directory(&svd_patched_dir);

// Apply atdf2svd.
let atdf_reader = File::open(&atdf_file).unwrap();
Expand All @@ -88,7 +93,7 @@ fn build_mcu_module(mcu: &str) {
panic!("Failed to parse \"{}\"!", atdf_file.display());
}
};
let svd_file = temp_dir.join("unpatched.svd");
let svd_file = svd_unpatched_dir.join(mcu).with_extension("svd");
let svd_writer = File::create(&svd_file).unwrap();
if let Err(what) = svd::generate(&atdf_parsed, svd_writer) {
let _ = what.format(&mut io::stdout());
Expand All @@ -107,9 +112,9 @@ _include:
svd_file.display(),
patch_file.display()
);
let includer_file = temp_dir.join("patch.yaml");
let includer_file = svd_dir.join("patch.yaml");
fs::write(&includer_file, &includer_content).unwrap();
let svd_patched_file = temp_dir.join("patched.svd");
let svd_patched_file = svd_patched_dir.join(mcu).with_extension("svd");
patch::process_file(
&includer_file,
Some(&svd_patched_file),
Expand All @@ -126,7 +131,6 @@ _include:
}

// Apply svd2rust.
let out_dir = env::var("OUT_DIR").unwrap();
let pac_dir = Path::new(&out_dir).join("pac");
ensure_directory(&pac_dir);
let mut svd2rust_config = config::Config::default();
Expand Down

0 comments on commit 0d3187c

Please sign in to comment.