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. |
There was a problem hiding this comment.
I think the yaml-serde thing does show an obstacle though: we are bound by our dependencies. If a core dependency of some libdatadog crate doesn't support no_std, that might be a problem (as an example, there's still no activity on the yaml-serde PR from upstream). That being said, we can just not support no_std in that specific case, if there's no choice.
| ## 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>
| 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. |
There was a problem hiding this comment.
Just as a note, with the right build options (basically LTO for both the static library and the end consumer), dead-code elimination can be pretty close to what you'd have using libdatadog as a direct dependency, or so I would expect. Even without that, the linker does perform some dead-code elimination, so you don't get all of std automatically (nor necessarily all the surface used by the static library). But it's true that good code elimination is more fragile when consuming an already built static library.
| 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. |
There was a problem hiding this comment.
I think the yaml-serde thing does show an obstacle though: we are bound by our dependencies. If a core dependency of some libdatadog crate doesn't support no_std, that might be a problem (as an example, there's still no activity on the yaml-serde PR from upstream). That being said, we can just not support no_std in that specific case, if there's no choice.
| 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. | ||
|
|
||
| The first concrete driver in this workspace is `libdd-library-config` (prototyped in the sibling worktree `no-std-library-config`), but the case generalises: data structures, parsers, protocol definitions, error types, and signal-handler-adjacent code all benefit. The exceptions — sockets, files, threads, processes — are real but bounded. |
There was a problem hiding this comment.
While talking about datastructures: there's no HashMap implementation in alloc, forcing the use of BTreeMap or something similar, which has different (and often worse, although not always) performance characteristics.
| - **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. | ||
| - **Cognitive overhead in opted-in crates.** Contributors have to use `core::`/`alloc::` and gate `std`-only code. We consider this a feature: it forces the same discipline we'd want at code-review time anyway. | ||
| - **Adding a dependency becomes a small research task.** Does it support `no_std`? With which features? Mostly this is good — it discourages casual dependency growth — but it is friction. | ||
| - **Forks accumulate maintenance debt.** This risk is real and should be weighed carefully before adopting or maintaining a fork. |
There was a problem hiding this comment.
This is the first time forks are mentioned. Does this refer to forking a dependency to make it no_std if upstream is unwilling/unresponsive? I think this is a bad idea in general, the maintenance work is going to be unbearable with security implications, and this potentially duplicates some dependencies for dd-trace-rs end-users.
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.