1. It works!!! That’s amazing.
To Just Work™ was the whole point
I tested it on the Demo project as well as my own, which is largely based on the demo project.
I can try to investigate pebble-rust-2026 exports that can be shrunk.
I investigated this a bunch, some major offenders are the global callback handlers for some reason, as well as parts of the layer handling (on stable, 1K in a few functions). Not really things that can be removed, and I didn’t see how to improve the code itself. May be related to complex Vec operations in a few cases (e.g. swap_remove). Most of these functions shrunk by almost 2x in “nightly” mode (with build_std, using optimize_for_size for the standard library, and many other unstable size optimization flags).
A major issue is actually the panic handler, since thanks to retrieving the panic message, it will pull in the entire formatting infrastructure, which adds at least 2-3K on Aplite. Using -Cpanic=immediate-abort (nightly-only), or disabling the Debug machinery both get rid of this, but maybe we can make this configurable from the outside too? So the panic handler is an almost-noop (maybe a single cheap log_c_str("Panicked!") call) if the user chooses to enable a certain feature flag.
3. Would be nice if we don’t need to specify the path on the output of `cargo pebble build`.
To be fair I didn’t investigate this a lot, so I’ll see how pebble actually detects this. A major goal with cargo-pebble was to avoid having all three target, build, and node_modules directories, so it would be unfortunate if we had to add back the build directory, but I’ll consider it if it improves the DX.
As far as I know the build directory is fully configurable from wscript, so not sure how this works in practice?
4. `touch_service_is_enabled` and others are not defined when compiling for e.g. diorite
I have a few thoughts for how to solve this situation. First, it’s important to note that within pebble-rust-2026, it’s probably pretty hard to detect which build we’re running under, even with bindgen. This is complicated by the fact that currently up to 4 platforms share one Rust target and therefore one build.rs/bindgen invocation.
- Add feature flags for each platform, which configures various internals of pebble-rust-2026, and makes only the appropriate functionality available. This usually means the user has to have the same feature flags on their own project and pass them through, so they can do #[cfg] in their own code. This would also mean that cargo pebble would have to enable the appropriate feature flags, which is easy enough to handle in the custom wscript. (This is actually a main reason I wanted to have a “common” wscript, so that we as tool authors can make improvements which all users will automatically benefit from once they update!) FYI this approach has precedent in how esp-rs, the officially supported Rust SDK for ESP32, handles it, see e.g. here
- Add macros à la
cfg_select! which would only generate the code for the appropriate platform. This would allow the user to avoid having lots of feature flags, but also require cfg options (either features, or even better a raw option like pebble_platform) on pebble-rust-2026, set from build.rs based on bindgen information (? not sure if that’s possible) or other environment information. I’m not 100% sure how to thread the platform information through the entire stack (pebble build → wscript → cargo → rustc → build.rs → bindgen → proc-macro) in this case, and it would also require non-cargo-pebble users to possibly do extra work or use more advanced wscript configuration, similar to what cargo-pebble uses. This really depends on whether you want pebble-rust-2026 to keep working “easily” with custom build configurations, or make cargo-pebble a hard dependency. I don’t have an opinion on this, I’m usually for more flexibility when possible.
- Do both :3 (macros for selection, but also feature flags for pebble-rust-2026 which can be inherited by the user if desired)
In any case I think this will require splitting the Rust build from a maximum of 3 currently to one build per platform. Especially once the new build directory layout is finished, they should all run in parallel properly, so I don’t think this will impact cold compile times all that much (hot compile times are decently fast anyways, I currently get 6 seconds of total build time which includes several slow npm invocations and whatever waf and pebble-tool are doing).
I would be interested in combining everyone’s Rust-Pebble efforts! I’ve reserved pebble-rust on Codeberg, in case you’re open to transferring the pebble-rust-2026 repos (including the demo repo) over there. I would also transfer the cargo-pebble repo there, and accept other people’s Rust projects if they’re intended for a general audience.