feat: embed version and git hash in USB serial number#864
Conversation
Size Report
|
6af3e38 to
7306942
Compare
|
iirc Vial needs |
4974e8b to
25f27ca
Compare
|
@HaoboGu I had only checked the web UI which worked fine. Adjusted now. |
| #[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.
There was a problem hiding this comment.
Right, I had only tested this with my local copy which is all Git based. Simplified it to the crate version.
`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 `vial:f64c2b3c;rmk:<version>`, which lets Vial discover the keyboard. Non-Vial builds get `rmk:<version>`. The `vial:` marker is placed first because BLE serial number characteristics are length limited, so a trailing marker can be truncated. - `config/device.rs`: add `pub const RMK_BUILD_INFO`, cfg-gated to prefix `vial:f64c2b3c;` for Vial builds; use it as the default `serial_number` - `config/mod.rs`: re-export it as `rmk::config::RMK_BUILD_INFO` - `ble/mod.rs`: truncate the serial at a char boundary instead of calling `unwrap()` on `heapless::String::try_from`, which panics when the serial exceeds the 20-byte characteristic
…ult()` All `use_rust` examples had `serial_number: "vial:f64c2b3c:000001"` set explicitly. `DeviceConfig::default()` now stamps `serial_number` with `RMK_BUILD_INFO` (`vial:f64c2b3c;rmk:<version>` 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), this includes the `vial:f64c2b3c;` prefix. 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;` prefix in Vial builds, and how to override `serial_number` explicitly for custom values.
25f27ca to
6e93cc4
Compare
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:", ...)