Skip to content

Commit 2f0c556

Browse files
authored
Reorgnize the cargo features for clarity. (#142)
Put rustc-dep-of-std way down at the bottom, group things more logically, and add more comments.
1 parent ba24ecd commit 2f0c556

File tree

9 files changed

+64
-49
lines changed

9 files changed

+64
-49
lines changed

Cargo.toml

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -58,56 +58,41 @@ features = ["param"]
5858
assert_cmd = "2.0.12"
5959

6060
[features]
61-
default = ["std", "log", "libc", "errno", "thread", "init-fini-arrays", "program-at-exit", "thread-at-exit"]
62-
std = ["rustix/std", "bitflags/std", "alloc"]
63-
rustc-dep-of-std = [
64-
"dep:core",
65-
"dep:alloc",
66-
"linux-raw-sys/rustc-dep-of-std",
67-
"bitflags/rustc-dep-of-std",
68-
"rustix/rustc-dep-of-std",
69-
"unwinding?/rustc-dep-of-std",
70-
"libc?/rustc-dep-of-std",
71-
"rustix-futex-sync/rustc-dep-of-std",
72-
]
61+
# By default, origin coexists with libc and assume std exists and enables most
62+
# features. To have origin avoid using libc, disable the default features and
63+
# enable either "origin-start" or "external-start".
64+
default = ["std", "log", "libc", "errno", "signal", "init-fini-arrays", "program-at-exit", "thread-at-exit"]
65+
66+
# If you're using nightly Rust, enable this feature to let origin use
67+
# nightly-only features, which include proper support for unwinding, better
68+
# safety checks, and better optimizations.
69+
nightly = ["unwinding"]
70+
71+
# Enable optimizations that reduce code size (at the cost of performance).
72+
optimize_for_size = []
7373

7474
# Use origin's implementation of program and thread startup and shutdown as
75-
# well as signal handler registration.
75+
# well as signal handler registration. To use this, disable the default
76+
# features and enable exactly one of "origin-start" or "external-start".
7677
#
7778
# To use threads, it is also necessary to enable the "thread" feature.
7879
# To use signals, it is also necessary to enable the "signal" feature.
7980
take-charge = ["rustix/use-explicitly-provided-auxv", "rustix/runtime"]
8081

81-
# Use origin's `_start` definition.
82+
# Enable "take-charge" mode using origin's `_start` definition.
8283
origin-start = ["take-charge"]
8384

84-
# Don't use origin's `_start` definition, but export a `start` function which
85-
# is meant to be run very early in program startup and passed a pointer to
86-
# the initial stack. Don't enable this when enabling "origin-start".
85+
# Enable "take-charge" mode using an exported `start` function which is meant
86+
# to be run very early in program startup and passed a pointer to the initial
87+
# stack. Don't enable this when enabling "origin-start".
8788
external-start = ["take-charge"]
8889

89-
# The loggers depend on a `.init_array` entry to initialize themselves, and
90-
# `env_logger` needs it so that `c-scape` can initialize environment variables
91-
# and make `RUST_LOG` available.
92-
atomic-dbg-logger = ["atomic-dbg/log", "init-array"]
93-
env_logger = ["dep:env_logger", "init-array"]
94-
95-
# Disable logging.
96-
max_level_off = ["log/max_level_off"]
97-
98-
# Enable features which depend on the Rust global allocator, such as functions
99-
# that return owned strings or `Vec`s.
100-
alloc = ["rustix/alloc", "smallvec"]
101-
10290
# Enable support for threads.
10391
thread = ["rustix/thread", "rustix/mm", "param", "rustix/process", "rustix/runtime", "rustix-futex-sync"]
10492

10593
# Enable support for signal handlers.
10694
signal = ["rustix/runtime"]
10795

108-
# Have origin call `rustix::param::init`.
109-
param = ["rustix/param"]
110-
11196
# Enable support for ELF `.init_array` and `.fini_array`.
11297
init-fini-arrays = ["init-array", "fini-array"]
11398

@@ -123,6 +108,21 @@ program-at-exit = ["alloc"]
123108
# Enable support for `origin::thread::at_exit`.
124109
thread-at-exit = ["alloc", "thread"]
125110

111+
# Have origin call `atomic_dbg::log::init()` on startup.
112+
#
113+
# To have origin emit log messages for the things it does, additionally enable the
114+
# "log" feature.
115+
atomic-dbg-logger = ["atomic-dbg/log", "init-array"]
116+
117+
# Have origin call `env_logger::init()` on startup.
118+
#
119+
# To have origin emit log messages for the things it does, additionally enable the
120+
# "log" feature.
121+
env_logger = ["dep:env_logger", "init-array"]
122+
123+
# Disable logging.
124+
max_level_off = ["log/max_level_off"]
125+
126126
# Enable highly experimental support for performing startup-time relocations,
127127
# needed to support statically-linked PIE executables.
128128
experimental-relocate = ["rustix/mm", "rustix/runtime"]
@@ -133,13 +133,8 @@ experimental-relocate = ["rustix/mm", "rustix/runtime"]
133133
# until a dynamic linker is written in Rust.
134134
unstable-errno = ["thread"]
135135

136-
# If you're using nightly Rust, enable this feature to let origin use
137-
# nightly-only features, which include proper support for unwinding, better
138-
# safety checks, and better optimizations.
139-
nightly = ["unwinding"]
140-
141-
# Enable optimizations that reduce code size (at the cost of performance).
142-
optimize_for_size = []
136+
# Have origin call `rustix::param::init` on startup.
137+
param = ["rustix/param"]
143138

144139
# Provide a `#[lang = eh_personality]` function suitable for unwinding (for
145140
# no-std).
@@ -176,5 +171,25 @@ panic-handler-abort = ["unwinding?/panic-handler-dummy"]
176171
# Enable this to define the `getauxval` function.
177172
getauxval = ["rustix/param"]
178173

174+
# Enable features which depend on Rust's std.
175+
std = ["rustix/std", "bitflags/std", "alloc"]
176+
177+
# Enable features which depend on the Rust global allocator, such as functions
178+
# that return owned strings or `Vec`s.
179+
alloc = ["rustix/alloc", "smallvec"]
180+
181+
# Use this iff you're experimenting with using origin from within Rust's
182+
# standard library implementation.
183+
rustc-dep-of-std = [
184+
"dep:core",
185+
"dep:alloc",
186+
"linux-raw-sys/rustc-dep-of-std",
187+
"bitflags/rustc-dep-of-std",
188+
"rustix/rustc-dep-of-std",
189+
"unwinding?/rustc-dep-of-std",
190+
"libc?/rustc-dep-of-std",
191+
"rustix-futex-sync/rustc-dep-of-std",
192+
]
193+
179194
[package.metadata.docs.rs]
180-
features = ["origin-start", "thread", "signal", "program-at-exit", "thread-at-exit", "nightly"]
195+
features = ["origin-start", "signal", "program-at-exit", "thread-at-exit", "nightly"]

example-crates/external-start/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77
[dependencies]
88
# Origin can be depended on just like any other crate. For no_std, disable
99
# the default features, and the desired features.
10-
origin = { path = "../..", default-features = false, features = ["take-charge", "external-start", "thread", "alloc", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort", "nightly"] }
10+
origin = { path = "../..", default-features = false, features = ["external-start", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort", "nightly"] }
1111

1212
# Ensure that libc gets linked.
1313
libc = { version = "0.2", default-features = false }

example-crates/no-std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77
[dependencies]
88
# Origin can be depended on just like any other crate. For no_std, disable
99
# the default features. And enable "libc" to enable the libc implementations.
10-
origin = { path = "../..", default-features = false, features = ["libc", "thread", "alloc", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort", "nightly"] }
10+
origin = { path = "../..", default-features = false, features = ["libc", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort", "nightly"] }
1111

1212
# Crates to help writing no_std code.
1313
atomic-dbg = { version = "0.1.8", default-features = false }

example-crates/origin-start-dynamic-linker/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ crate-type = ["cdylib"]
1010
[dependencies]
1111
# Origin can be depended on just like any other crate. For no_std, disable
1212
# the default features, and the desired features.
13-
origin = { path = "../..", default-features = false, features = ["origin-start", "thread", "alloc", "program-at-exit", "thread-at-exit", "experimental-relocate", "eh-personality-continue", "panic-handler-abort", "nightly"] }
13+
origin = { path = "../..", default-features = false, features = ["origin-start", "program-at-exit", "thread-at-exit", "experimental-relocate", "eh-personality-continue", "panic-handler-abort", "nightly"] }
1414

1515
# Crates to help writing no_std code.
1616
atomic-dbg = { version = "0.1.8", default-features = false }

example-crates/origin-start-lto/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77
[dependencies]
88
# Origin can be depended on just like any other crate. For no_std, disable
99
# the default features, and the desired features.
10-
origin = { path = "../..", default-features = false, features = ["origin-start", "thread", "alloc", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort", "nightly"] }
10+
origin = { path = "../..", default-features = false, features = ["origin-start", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort", "nightly"] }
1111

1212
# Crates to help writing no_std code.
1313
atomic-dbg = { version = "0.1.8", default-features = false }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
This crate is similar to the [origin-start example], except that it doesn't
2-
enable the "alloc" feature, so it doesn't get a global allocator.
2+
enable the "alloc" feature, and it doesn't declare a global allocator.
33

44
[origin-start example]: https://github.com/sunfishcode/origin/blob/main/example-crates/origin-start/README.md

example-crates/origin-start-stable/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77
[dependencies]
88
# Origin can be depended on just like any other crate. For no_std, disable
99
# the default features, and the desired features.
10-
origin = { path = "../..", default-features = false, features = ["origin-start", "thread", "alloc", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort"] }
10+
origin = { path = "../..", default-features = false, features = ["origin-start", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort"] }
1111

1212
# Crates to help writing no_std code.
1313
atomic-dbg = { version = "0.1.8", default-features = false }

example-crates/origin-start/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77
[dependencies]
88
# Origin can be depended on just like any other crate. For no_std, disable
99
# the default features, and the desired features.
10-
origin = { path = "../..", default-features = false, features = ["origin-start", "thread", "alloc", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort", "nightly"] }
10+
origin = { path = "../..", default-features = false, features = ["origin-start", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort", "nightly"] }
1111

1212
# Crates to help writing no_std code.
1313
atomic-dbg = { version = "0.1.8", default-features = false }

test-crates/origin-start/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
publish = false
66

77
[dependencies]
8-
origin = { path = "../..", default-features = false, features = ["origin-start", "thread", "alloc", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort", "nightly"] }
8+
origin = { path = "../..", default-features = false, features = ["origin-start", "program-at-exit", "thread-at-exit", "eh-personality-continue", "panic-handler-abort", "nightly"] }
99
atomic-dbg = { version = "0.1.8", default-features = false }
1010
rustix-dlmalloc = { version = "0.1.0", features = ["global"] }
1111
rustix = { version = "0.38", default-features = false, features = ["thread"] }

0 commit comments

Comments
 (0)