Skip to content

changed(pacs)!: Build PACs on demand and update PAC APIs - #1013

Draft
jbeaurivage wants to merge 15 commits into
atsamd-rs:masterfrom
jbeaurivage:pacs-on-demand
Draft

changed(pacs)!: Build PACs on demand and update PAC APIs#1013
jbeaurivage wants to merge 15 commits into
atsamd-rs:masterfrom
jbeaurivage:pacs-on-demand

Conversation

@jbeaurivage

@jbeaurivage jbeaurivage commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

The pre-generated PACs sitting in the repo have always been a pain point. This PR enables generating the PAC code at build-time using a build.rs scripts, which enormously reduces the number of files in the PAC crates. It also means we no longer need to run an update-pacs script whenever we update SVDs or svd2rust version, which is now a build-time dependency.

Currently the svd2rust dependency is at 0.37.1, which is the latest version.

I created a new helper library, atsamd-hal-pacs-builder, which contains the PAC generation code. It also uses svdtools, and much nicer YAML-based SVD patch templates rather than XSLT, which don't have good, pure-rust library offerings. The individual build.rs scripts just contain glue to call the codegen function. The PACs' lib.rs is now just this:

#![no_std]
#![allow(clippy::all)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(unsafe_op_in_unsafe_fn)]

include!(concat!(env!("OUT_DIR"), "/pac.rs"));

pub use __pac_impl::generic::*;
pub use __pac_impl::*;

I also updated the SVDs to the latest version provided by Microchip for SAMD21 and SAMD51 targets only. We are still waiting on Microchip to update the remaining chips we support so that the PAC APIs remain compatible.

The new SVD+svd2rust combo brings in relatively significant API changes, so this will be a breaking change for PACs and the HAL.

Notes

  1. Deleting the generated PAC code from the repo obviously creates an absolutely monstrous git diff. I'll try to contain the file deletions and SVD updates to their own commits, so we can make a more palatable diff from the other commits in the PR for review.
  2. We are also waiting for svd-parser to make a new release. We need these changes to be released to crates.io for the new PACs to be accepted by svd2rust. Currently I'm patching the dependency to the git version in the workspace Cargo.toml, but I don't think that's allowed if we want to release atsamd-hal-pacs-builder to crates.io. svd-parser released!

Checklist

  • SAMD11 SVD > v2.7.195
  • SAMD21 SVD v3.8.270, 2026-02-11
  • SAME51 SVD v3.9.276, 2026-06-11
  • SAME51 SVD > v3.9.267
  • SAME53 SVD > v3.10.248
  • SAME54 SVD > v3.11.261
  • svd-parser release > 0.14.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant