Skip to content

Commit

Permalink
Reduce the complexity around all possible feature combinations (#107)
Browse files Browse the repository at this point in the history
* Unconditionally enable the set_thread_id feature

If set_current_id_after_a_fork is isn't used, --gc-sections will already
automatically remove it from the executable.

* Fix the compile time assertion about origin-program requiring either origin-start or external-start

Also move a couple of feature deps from origin-start/external-start to
origin-program.
  • Loading branch information
bjorn3 committed Feb 20, 2024
1 parent 5f3c81f commit 9b9b5f9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
11 changes: 4 additions & 7 deletions Cargo.toml
Expand Up @@ -65,29 +65,26 @@ rustc-dep-of-std = [
"dep:compiler_builtins",
]

# Enable the `set_current_id_after_a_fork` function.
set_thread_id = []

# Use origin's implementation of program startup and shutdown.
origin-program = []
origin-program = ["rustix/use-explicitly-provided-auxv", "rustix/runtime"]

# Use origin's implementation of thread startup and shutdown.
#
# To use threads, it's also necessary to enable the "thread" feature.
origin-thread = ["memoffset", "rustix/runtime", "origin-program"]
origin-thread = ["memoffset", "origin-program"]

# Use origin's implementation of signal handle registrtion.
#
# To use threads, it's also necessary to enable the "signal" feature.
origin-signal = ["rustix/runtime"]

# Use origin's `_start` definition.
origin-start = ["rustix/use-explicitly-provided-auxv", "rustix/runtime", "origin-program"]
origin-start = ["origin-program"]

# Don't use origin's `_start` definition, but export a `start` function which
# is meant to be run very early in program startup and passed a pointer to
# the initial stack. Don't enable this when enabling "origin-start".
external-start = ["rustix/use-explicitly-provided-auxv", "rustix/runtime", "origin-program"]
external-start = ["origin-program"]

# The loggers depend on a `.init_array` entry to initialize themselves, and
# `env_logger` needs it so that `c-scape` can initialize environment variables
Expand Down
2 changes: 1 addition & 1 deletion src/program.rs
Expand Up @@ -38,7 +38,7 @@ use linux_raw_sys::ctypes::c_int;
use rustix_futex_sync::Mutex;

#[cfg(all(
feature = "program-start",
feature = "origin-program",
not(any(feature = "origin-start", feature = "external-start"))
))]
compile_error!("\"origin-program\" depends on either \"origin-start\" or \"external-start\".");
Expand Down
1 change: 0 additions & 1 deletion src/thread/libc.rs
Expand Up @@ -196,7 +196,6 @@ pub fn current_id() -> ThreadId {
/// This must only be called immediately after a `fork` before any other
/// threads are created. `tid` must be the same value as what [`gettid`] would
/// return.
#[cfg(feature = "set_thread_id")]
#[doc(hidden)]
#[inline]
pub unsafe fn set_current_id_after_a_fork(tid: ThreadId) {
Expand Down
2 changes: 0 additions & 2 deletions src/thread/linux_raw.rs
Expand Up @@ -989,8 +989,6 @@ pub fn current_id() -> ThreadId {
/// This must only be called immediately after a `fork` before any other
/// threads are created. `tid` must be the same value as what [`gettid`] would
/// return.
#[cfg(feature = "set_thread_id")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "set_thread_id")))]
#[doc(hidden)]
#[inline]
pub unsafe fn set_current_id_after_a_fork(tid: ThreadId) {
Expand Down

0 comments on commit 9b9b5f9

Please sign in to comment.