Repository navigation
[major] Remove "alloc" feature from default feature list of all Patina crates - #1685
Conversation
ℹ️ QEMU Validation Skipped - PR Branch UnavailableThe Patina QEMU PR validation workflow did not run because the PR branch is no longer accessible. Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/30833255931
This comment was automatically generated by the Patina QEMU PR Validation Post workflow. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
makubacki
left a comment
There was a problem hiding this comment.
I agree with the change. Especially after sorting through similar issues last week. However, I think this should target the major branch given it is a breaking change and given the immediate code changes made in #1677, it shouldn't' be urgent.
|
Sure Michael, will get this into major branch. |
…ncies explicit
**TIL:**
Behavior of `--all-features` with explicit package vs without explicit package,
```
cargo clippy --all-features --tests
workspace
crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary
crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib
cargo clippy -p crate_a --all-features --tests
workspace
crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary
crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib
```
NOTE: --tests is nothing special here any target can be picked
**Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies
by ensuring the "alloc" feature is not enabled. Since Patina currently includes
"alloc" in its default feature set, the MM Supervisor branch had to explicitly
remove it from its default features(`default = []`) and also by not defining an
explicit `#[global_allocator]`. Because `default-features = false` only affects
a direct dependency, not transitive dependencies
Now with `default=[]` in place on patina sdk in feature/supv branch,
Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to
run `cargo clippy --tests` did not break the build with or without
--all-features because in both cases c_ptr.rs is fully stubbed out as patina
sdk is neither built with test feature(remember this is a dependency to whatever
crate is being built) nor alloc(since we have set default=[]).
```
sdk\patina\src\lib.rs
#[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now
extern crate alloc;
#[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now
pub mod boot_services;
sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now
use alloc::boxed::Box;
```
After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo
clippy --tests` will break the build with or without `--all-features` because in
both the cases c_ptr.rs is always present and `extern crate alloc` is always
absent as neither test feature(again remember this is a dependency to whatever
crate is being built) nor alloc(since we have set default=[]).
```
sdk\patina\src\lib.rs
#[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now
extern crate alloc;
pub mod base; <----- NOT STUBBED OUT
sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT
use alloc::boxed::Box;
```
Resulting in below error:
```
error[E0433]: cannot find module or crate `alloc` in this scope
--> sdk\patina\src\base\c_ptr.rs:9:5
|
9 | use alloc::boxed::Box;
| ^^^^^ use of unresolved module or unlinked crate `alloc`
```
While restoring the feature gate on `c_ptr` fixes this immediate issue(also done
in OpenDevicePartnership#1677), debugging feature
related failures like this is not a very pleasant experience. In particular,
`--all-features` only applies to the package being built and does not propagate
to dependencies. To some extent `cargo hack` makes it easier to run failing
command on individual packages but that brings in its own set of new challenges.
After spending a considerable amount of time untangling the dependencies and
understanding the root cause, it seems that disabling the default feature set
across all Patina crates would alleviate some of the debugging pain.
Benefits:
1. Patina crates no longer assume the presence of the `alloc` feature.
2. Crates within Patina repo are nothing special and they have to explicitly
declare the required feature set, making feature usage easier to audit and
maintain.
```
E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev
patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors)
...
├── patina feature "default" <----
vs
E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev
patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors)
...
├── patina feature "alloc" <----
```
3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks.
Please note that #[global_allocator] should still be avoided so that the
compiler can flag any dependent code paths that require heap allocations.
This is a breaking change because existing consumers relying on Patina's default
feature set will need to explicitly enable the required features. Most existing
crates have already been updated as part of this commit.
bd56c7f to
c054b5b
Compare
|
Added @Javagedes since he's looking at additive feature changes. |
|
Overall I don't agree with disabling default features across patina. That is very uncommon across the ecosystem. In my opinion the answer is that if you don't think the feature should be enabled by default, then we should not have it in the default features list. But there are some features that should realistically be always on (alloc features for example). Regardless of my opinion and whether you follow through with this, there are three features that are not additive, so if any of them are swapped from enabled to disabled by default, will cause breaking changes:
|
The |
I should have looked at the PR more closely. The PR title is poorely worded. This is not disabling all default features across the patina crates. This is simply removing However I still don't understand why you cannot just do |
|
Thanks Joey, let me update the title. I was more furious after scratching my head debugging it, hence the title 😄
The problem is not about the direct usage of a dependency. It is the indirect inclusion of "alloc" crate which is a pain to debug and isolate. default-features=false only prevent an immediate dependency to not include its default feature set but it does not prevent a transitive dependency to include its defaults. On top that, it works fine for normal |
Yes, the |
Agreed, this PR only makes the dependency on "alloc" crate explicit but does not prevent any alloc feature usage from a transitive dependency(though it makes auditing the dependency tree via "cargo tree" slightly better to pin point). Why a crate needs a dependency on "alloc" is a different question which requires more scrutiny and if needed should be isolated with a feature guard as already done in #1677 |
…a crates (#1685) ## Description **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? ## How This Was Tested `cargo make all` and validated on hardware platform. ## Integration Instructions All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
…a crates (#1685) ## Description **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? ## How This Was Tested `cargo make all` and validated on hardware platform. ## Integration Instructions All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
…a crates (#1685) ## Description **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? ## How This Was Tested `cargo make all` and validated on hardware platform. ## Integration Instructions All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
…a crates (#1685) **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs extern crate alloc; pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? `cargo make all` and validated on hardware platform. All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
…a crates (#1685) ## Description **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? ## How This Was Tested `cargo make all` and validated on hardware platform. ## Integration Instructions All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
…#1685) **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs extern crate alloc; pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? `cargo make all` and validated on hardware platform. All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
…a crates (#1685) ## Description **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? ## How This Was Tested `cargo make all` and validated on hardware platform. ## Integration Instructions All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
…a crates (#1685) ## Description **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? ## How This Was Tested `cargo make all` and validated on hardware platform. ## Integration Instructions All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
…a crates (#1685) ## Description **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs #[cfg(any(test, feature = "alloc"))] <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? ## How This Was Tested `cargo make all` and validated on hardware platform. ## Integration Instructions All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
…#1685) **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs extern crate alloc; pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? `cargo make all` and validated on hardware platform. All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
…#1685) **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs extern crate alloc; pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? `cargo make all` and validated on hardware platform. All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
…#1685) **Background:** Behavior of `--all-features` with explicit package vs without explicit package: ``` cargo clippy --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- all features defined in crate_b are enabled and built as a lib cargo clippy -p crate_a --all-features --tests workspace crate a(feature fa) <--- all features defined in crate_a are enabled and built as a test binary crate b(feature fb) <--- only features selected when specifying crate_b as dependency are enabled(if non selected, default features are applied) and built as a lib ``` **NOTE:** `--tests` is nothing special here any target can be picked **Problem:** Rust MM Supervisor avoids hidden heap allocations from dependencies by ensuring the "alloc" feature is not enabled. Since Patina currently includes "alloc" in its default feature set, the MM Supervisor branch had to explicitly remove it from its default features(`default = []`) and also by not defining an explicit `#[global_allocator]`. Because `default-features = false` only affects a direct dependency, not transitive dependencies Now with `default=[]` in place on patina sdk in feature/supv branch, Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to run `cargo clippy --tests` did not break the build with or without --all-features because in both cases c_ptr.rs is fully stubbed out as patina sdk is neither built with test feature(remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs extern crate alloc; pub mod boot_services; sdk\patina\src\boot_services\c_ptr.rs <----- stubbed out because patina sdk is a dependency for whatever test crate is being built right now use alloc::boxed::Box; ``` After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run `cargo clippy --tests` will break the build with or without `--all-features` because in both the cases c_ptr.rs is always present and `extern crate alloc` is always absent as neither test feature(again remember this is a dependency to whatever crate is being built) nor alloc(since we have set default=[]). ``` sdk\patina\src\lib.rs extern crate alloc; pub mod base; <----- NOT STUBBED OUT sdk\patina\src\base\c_ptr.rs <----- NOT STUBBED OUT use alloc::boxed::Box; ``` Resulting in below error: ``` error[E0433]: cannot find module or crate `alloc` in this scope --> sdk\patina\src\base\c_ptr.rs:9:5 | 9 | use alloc::boxed::Box; | ^^^^^ use of unresolved module or unlinked crate `alloc` ``` While restoring the feature gate on `c_ptr` fixes this immediate issue(also done in #1677), debugging "feature" related failures like this is not a very pleasant experience. In particular, `--all-features` only applies to the package being built and does not propagate to dependencies. To some extent `cargo hack` makes it easier to run failing command on individual packages but that brings in its own set of new challenges. After spending a considerable amount of time untangling the dependencies and finding the root cause, it seems that removing "alloc" from the default feature set across all Patina crates would alleviate some of the debugging pain. **Benefits:** 1. Patina crates no longer assume the presence of the `alloc` feature. 2. Crates within Patina repo are nothing special and they have to explicitly declare the required feature set, making feature usage easier to audit and maintain. ``` E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "default" <---- vs E:\repos\patina>cargo tree -e features -p patina_ffs_extractors -e=no-dev patina_ffs_extractors v23.0.1 (E:\repos\patina\sdk\patina_ffs_extractors) ... ├── patina feature "alloc" <---- ``` 3. Rust MM Supervisor can now opt out of `alloc` without requiring any hacks. Please note that #[global_allocator] should still be avoided so that the compiler can flag any dependent code paths that require heap allocations. This is a breaking change because existing consumers relying on Patina's default feature set will need to explicitly enable the required features. Most existing crates have already been updated as part of this commit. - [ ] Impacts functionality? - [ ] Impacts security? - [x] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? `cargo make all` and validated on hardware platform. All external crates relying on patina crates will need to add "alloc" to the features list like below `patina = { workspace = true, features = ["alloc"] }`
Description
Background: Behavior of
--all-featureswith explicit package vs without explicit package:NOTE:
--testsis nothing special here any target can be pickedProblem: Rust MM Supervisor avoids hidden heap allocations from dependencies
by ensuring the "alloc" feature is not enabled. Since Patina currently includes
"alloc" in its default feature set, the MM Supervisor branch had to explicitly
remove it from its default features(
default = []) and also by not defining anexplicit
#[global_allocator]. Becausedefault-features = falseonly affectsa direct dependency, not transitive dependencies
Now with
default=[]in place on patina sdk in feature/supv branch,Before the SDK refactor, c_ptr.rs is gated as shown below. Which means trying to
run
cargo clippy --testsdid not break the build with or without--all-features because in both cases c_ptr.rs is fully stubbed out as patina
sdk is neither built with test feature(remember this is a dependency to whatever
crate is being built) nor alloc(since we have set default=[]).
After the SDK refactor, c_ptr.rs is NOT gated. Which means trying to run
cargo clippy --testswill break the build with or without--all-featuresbecause inboth the cases c_ptr.rs is always present and
extern crate allocis alwaysabsent as neither test feature(again remember this is a dependency to whatever
crate is being built) nor alloc(since we have set default=[]).
Resulting in below error:
While restoring the feature gate on
c_ptrfixes this immediate issue(also donein #1677), debugging "feature"
related failures like this is not a very pleasant experience. In particular,
--all-featuresonly applies to the package being built and does not propagateto dependencies. To some extent
cargo hackmakes it easier to run failingcommand on individual packages but that brings in its own set of new challenges.
After spending a considerable amount of time untangling the dependencies and
finding the root cause, it seems that removing "alloc" from the default feature set
across all Patina crates would alleviate some of the debugging pain.
Benefits:
Patina crates no longer assume the presence of the
allocfeature.Crates within Patina repo are nothing special and they have to explicitly
declare the required feature set, making feature usage easier to audit and
maintain.
Rust MM Supervisor can now opt out of
allocwithout requiring any hacks.Please note that #[global_allocator] should still be avoided so that the
compiler can flag any dependent code paths that require heap allocations.
This is a breaking change because existing consumers relying on Patina's default
feature set will need to explicitly enable the required features. Most existing
crates have already been updated as part of this commit.
How This Was Tested
cargo make alland validated on hardware platform.Integration Instructions
All external crates relying on patina crates will need to add "alloc" to the features list like below
patina = { workspace = true, features = ["alloc"] }