feat: embed version and git hash in USB serial number#864
Conversation
Size Report
|
6af3e38 to
7306942
Compare
|
iirc Vial needs |
7306942 to
4974e8b
Compare
`DeviceConfig::default()` now sets `serial_number` to `RMK_BUILD_INFO` instead of the static string `"vial:f64c2b3c:000001"`. For Vial builds (the default), `RMK_BUILD_INFO` is `rmk:<version>-<git-hash>;vial:f64c2b3c`, which lets Vial discover the keyboard. Non-Vial builds get `rmk:<version>-<git-hash>`. - `build.rs`: extract `get_git_hash()` helper, emit `RMK_GIT_HASH` env var - `config/device.rs`: add `pub const RMK_BUILD_INFO`, cfg-gated to include `";vial:f64c2b3c"` for Vial builds; use as default `serial_number` - `config/mod.rs`: re-export `RMK_BUILD_INFO` as `rmk::config::RMK_BUILD_INFO` Downstream firmware can extend the stamp with their own build info: `const_format::concatcp!(rmk::config::RMK_BUILD_INFO, ";my-fw:", ...)`
…ult()` All `use_rust` examples had `serial_number: "vial:f64c2b3c:000001"` set explicitly. `DeviceConfig::default()` now stamps `serial_number` with `RMK_BUILD_INFO` (`rmk:<version>-<git-hash>;vial:f64c2b3c` for Vial builds), so the field is redundant. Remove it from all 16 examples.
…` path When `serial_number` is absent from `keyboard.toml`, `Identity` resolves to `None` and the macro codegen emits `::rmk::config::RMK_BUILD_INFO`. This gives `use_config` keyboards the same version-stamped serial as `use_rust` keyboards. For Vial builds (the default) that includes the `;vial:f64c2b3c` suffix. An explicit `serial_number` in `keyboard.toml` is still emitted verbatim.
`keyboard_device.mdx` covers the default `RMK_BUILD_INFO` serial stamp, the `;vial:f64c2b3c` suffix in Vial builds, and how downstream firmware can extend the stamp via `concatcp!` or a custom `build.rs` env var.
4974e8b to
25f27ca
Compare
|
@HaoboGu I had only checked the web UI which worked fine. Adjusted now. |
| <Tab label={<Rust />}> | ||
|
|
||
| ```rust title="main.rs" | ||
| use const_format::concatcp; |
There was a problem hiding this comment.
This introduces extra dependency, I think it's unnecessary?
|
|
||
| To make your keyboard to be recognized by Vial, the `serial_number` shall start with `vial:f64c2b3c:` | ||
| If `serial_number` is omitted, RMK embeds a version stamp automatically. For Vial builds (the | ||
| default), this is `rmk:<version>-<git-hash>;vial:f64c2b3c`, which lets Vial discover the |
There was a problem hiding this comment.
I prefer to have vial:f64c2b3c at the beginning(or because it might be dropped in BLE. There's length limitation in BLE's serial.
| #[cfg(feature = "vial")] | ||
| pub const RMK_BUILD_INFO: &str = concat!( | ||
| "rmk:", | ||
| env!("CARGO_PKG_VERSION"), |
There was a problem hiding this comment.
There are several thoughts about the BUILD_INFO, I think it can be improved to cover:
- When using RMK version from git or local path, the
CARGO_PKG_VERSIONwill point to the version inCargo.tomlof used RMK, which is not accurate. - When the workspace is dirty(for example, using a local RMK with edits), the RMK_GIT_HASH is not accurate too.
- When using crates.io version,
CARGO_PKG_VERSIONandRMK_GIT_HASHare always fixed -- that means we can remove either of them.
| common::set_target_cfgs(&mut cfgs); | ||
|
|
||
| println!("cargo:rerun-if-changed=build.rs"); | ||
| println!("cargo:rerun-if-changed=.git/HEAD"); |
There was a problem hiding this comment.
This means ALWAYS rebuild RMK in user space -- which is not correct. This is because that there's no .git/HEAD under rmk folder.
And I don't think use this to monitoring commit changes is correct, .git/HEAD won't change when committing code.
This PR changes the serial number from the static string (
vial:f64c2b3c:000001) and replaces it with a build-time stamp of the formrmk:<version>-<git-hash>(with or withoutvial:...based on feature flags). Allowing users to know what they have flashed on their devices.Vial's
util.pylooks for the string, anywhere in the serial.Downstream firmware wanting to append their own build info can use
const_format::concatcp!(rmk::config::RMK_BUILD_INFO, ";my-fw:", ...)