chore(docs): RFC 0015 introduce no_std#1964
Conversation
Propose a workspace policy that prefers `no_std + alloc` and uses `std` only where it earns its keep. Motivated by signal safety, smaller artifacts, and tighter dependency hygiene.
666e263 to
6da17cf
Compare
|
🎯 Code Coverage (details) 🔗 Commit SHA: 1d89a15 | Docs | Datadog PR Page | Give us feedback! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1964 +/- ##
=========================================
Coverage 72.63% 72.63%
=========================================
Files 448 451 +3
Lines 73582 74687 +1105
=========================================
+ Hits 53444 54251 +807
- Misses 20138 20436 +298
🚀 New features to boost your workflow:
|
Artifact Size Benchmark Reportaarch64-alpine-linux-musl
aarch64-unknown-linux-gnu
libdatadog-x64-windows
libdatadog-x86-windows
x86_64-alpine-linux-musl
x86_64-unknown-linux-gnu
|
There was a problem hiding this comment.
Pull request overview
Adds a new RFC document (0015) proposing an opportunistic workspace policy to prefer no_std + alloc over std where it benefits consumers (signal safety, smaller artifacts, dependency hygiene), with concrete crate conventions, CI enforcement, initial migration candidates, and discussion of drawbacks/alternatives.
Changes:
- Adds
docs/RFCs/0015-no-std.mddescribing the rationale and policy for opportunisticno_stdadoption. - Documents per-crate conventions (feature flags, crate-root attributes, import patterns, dependencies, errors).
- Lists initial migration candidates (e.g.,
libdd-library-config,libdd-crashtrackercollector half) and out-of-scope crates.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Concretely, four things make `no_std` attractive for this workspace: | ||
|
|
||
| 1. **Signal safety by construction.** `core` and `alloc` (with a signal-safe allocator) are made of pure functions, integer math, and stack-allocated data. None of `std`'s mutex, thread-local, environment, file-descriptor, or panic-handler machinery is reachable. Code that runs in async-signal contexts — crashtracker, profiling samplers, anything called from a signal handler — is *much* easier to keep correct when `std::` is simply not in the import graph. The compiler enforces what code review otherwise has to. | ||
| 2. **Smaller artifacts.** Embedders linking libdatadog statically pay for everything `std` pulls in, whether they use it or not. `no_std + alloc` lets us ship the same functionality with substantially less code in the final binary, and noticeably faster compiles in the tree. | ||
| 3. **Frequently, it's a mechanical change.** A surprising amount of "make this `no_std`" work is replacing `std::` with `core::` and adding `extern crate alloc;`. yaml/yaml-serde#8 is a recent example: a near-mechanical patch turned an `std` crate into a `no_std + alloc` crate without changing its API. Many of our internal crates are in the same shape. |
| ## Drawbacks | ||
|
|
||
| - **Build matrix grows.** Each opted-in crate adds a `--no-default-features` build to CI. Real but bounded. | ||
| - **no_std rust ecosystem is large, but not all crates support it** Code willing to support `no_std` might have to do extra work to align dependencies with `no_std` requirements. |
|
|
||
| Concretely, four things make `no_std` attractive for this workspace: | ||
|
|
||
| 1. **Signal safety by construction.** `core` and `alloc` (with a signal-safe allocator) are made of pure functions, integer math, and stack-allocated data. None of `std`'s mutex, thread-local, environment, file-descriptor, or panic-handler machinery is reachable. Code that runs in async-signal contexts — crashtracker, profiling samplers, anything called from a signal handler — is *much* easier to keep correct when `std::` is simply not in the import graph. The compiler enforces what code review otherwise has to. |
There was a problem hiding this comment.
Not really. Just because you don't call signal-unsafe items doesn't make what you do signal safe. Yes, it's certainly easier, but it's not automatic. You still have to worry about reentrancy, atomicity, etc.
There was a problem hiding this comment.
Yeah, I framed it like it solves all problems :D
|
|
||
| ## The thesis | ||
|
|
||
| **Prefer `no_std + alloc`. Use `std` only where it is earning its keep.** |
There was a problem hiding this comment.
Why do we want alloc? We also shouldn't panic, and tons of users of alloc panic on allocation failure. What's the motivation for including alloc in the recommendation?
There was a problem hiding this comment.
I just found no_std + alloc is super easy to use and solving all my problems, and you really can have some safe'ish alloc implementations. and
Ideally people could target no_std and add alloc on top if needed.
tl;dr; alloc does make no_std quite bearable
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
What does this PR do?
Adds RFC 0015 proposing a workspace policy: prefer
no_std + alloc; usestdonly where it earns its keep.Motivation
no_stdis, for a lot of what libdatadog does, the better Rust.coremakes async-signal-unsafe items unreachable by construction (relevant for crashtracker and profiling samplers), embedders linking statically pay for less code, and once a crate isno_stdevery new dependency comes with a forced "what does this drag in?" review.Many migrations are mechanical (
std::→core::, see yaml/yaml-serde#8). #1770 is the in-flight reference implementation forlibdd-library-config.How to test the change?
Read it. Comment if you disagree.