Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## Next release
## 0.2.1 - 2025-12-16

### Bugfixes

- Fixed the `stringleton::enable!()` macro when referring to foreign crates.
- Fixed usage of `sym!()` in external tests.

### Dependencies

Expand Down
21 changes: 18 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ members = [
"tests/dylib/dynamic-library",
"tests/dylib/c-dynamic-library",
"tests/check-codegen",
"tests/foreign-crate-registry",
"tests/foreign-crate",
]
default-members = ["stringleton", "stringleton-registry"]
default-members = ["stringleton", "stringleton-registry", "tests/check-codegen", "tests/foreign-crate-registry", "tests/foreign-crate"]
resolver = "3"

[workspace.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions stringleton-dylib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stringleton-dylib"
version = "0.2.0"
version = "0.2.1"
edition = "2024"
authors = ["Simon Ask Ulsnes <simon@ulsnes.dk>"]
license = "MIT OR Apache-2.0"
Expand All @@ -16,7 +16,7 @@ crate-type = ["dylib"]
[dependencies]
ctor.workspace = true
linkme.workspace = true
stringleton-registry = { version = "0.2.0", path = "../stringleton-registry", default-features = false }
stringleton-registry = { version = "0.2.1", path = "../stringleton-registry", default-features = false }

[features]
default = ["std"]
Expand Down
2 changes: 1 addition & 1 deletion stringleton-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stringleton-registry"
version = "0.2.0"
version = "0.2.1"
edition = "2024"
authors = ["Simon Ask Ulsnes <simon@ulsnes.dk>"]
license = "MIT OR Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions stringleton/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stringleton"
version = "0.2.0"
version = "0.2.1"
edition = "2024"
authors = ["Simon Ask Ulsnes <simon@ulsnes.dk>"]
license = "MIT OR Apache-2.0"
Expand All @@ -16,7 +16,7 @@ crate-type = ["rlib"]
[dependencies]
ctor.workspace = true
linkme.workspace = true
stringleton-registry = { version = "0.2.0", path = "../stringleton-registry", default-features = false }
stringleton-registry = { version = "0.2.1", path = "../stringleton-registry", default-features = false }

[dev-dependencies]
hashbrown.workspace = true
Expand Down
5 changes: 5 additions & 0 deletions stringleton/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ assert_eq!(message, message2);
assert_eq!(message.as_str().as_ptr(), message2.as_str().as_ptr());
```

**NOTE:** In external tests (i.e. those in a separate `tests/` subdirectory), each
test file should call `stringleton::enable!(main_library_crate)` instead of
`stringleton::enable!()`. See the documentation of the `enable!()` macro for more
details.

## Crate features

- **std** *(enabled by default)*: Use synchronization primitives from the
Expand Down
19 changes: 15 additions & 4 deletions stringleton/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ macro_rules! static_sym {
/// Put a call to this macro somewhere in the root of each crate that uses the
/// `sym!(...)` macro.
///
/// The second variant reuses the symbol table of another crate, and this is
/// particularly needed due to the way external tests (in the `tests/`
/// subdirectory of the project) are compiled. Test files `tests/foo.rs`, are
/// compiled as "pseudo-crates", so they are semantically a separate crate from
/// the main library crate. But they are compiled into the same binary, so just
/// using `stringleton::enable!()` without arguments will cause linker errors
/// (`duplicate #[distributed_slice] with name "TABLE"`).
///
/// In external tests using [`sym!()`], the test file should instead use
/// `stringleton::enable!(main_library_crate)`.
///
/// ## Details
///
/// This creates a "distributed slice" containing all symbols in this crate, as
Expand Down Expand Up @@ -184,11 +195,11 @@ macro_rules! enable {
() => {
#[doc(hidden)]
#[cfg(not(any(miri, target_arch = "wasm32")))]
pub(crate) mod _stringleton_enabled {
pub mod _stringleton_enabled {
#[$crate::internal::linkme::distributed_slice]
#[linkme(crate = $crate::internal::linkme)]
#[doc(hidden)]
pub(crate) static TABLE: [$crate::internal::Site] = [..];
pub static TABLE: [$crate::internal::Site] = [..];

$crate::internal::ctor::declarative::ctor! {
#[ctor]
Expand All @@ -207,10 +218,10 @@ macro_rules! enable {
#[cfg(not(any(miri, target_arch = "wasm32")))]
pub use _stringleton_enabled::_stringleton_register_symbols;
};
($krate:path) => {
($($krate:tt)+) => {
#[doc(hidden)]
#[cfg(not(any(miri, target_arch = "wasm32")))]
pub(crate) use $krate::_stringleton_enabled;
pub use $($krate)*::_stringleton_enabled;
};
}

Expand Down
15 changes: 15 additions & 0 deletions tests/foreign-crate-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "foreign-crate-registry"
publish = false
edition = "2024"

[lib]
path = "lib.rs"
test = true
doctest = false

[lints]
workspace = true

[dependencies]
stringleton = { path = "../../stringleton", features = ["debug-assertions"] }
7 changes: 7 additions & 0 deletions tests/foreign-crate-registry/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use stringleton::sym;

stringleton::enable!();

pub fn foo() -> stringleton::Symbol {
sym!(foo)
}
16 changes: 16 additions & 0 deletions tests/foreign-crate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "foreign-crate"
publish = false
edition = "2024"

[lib]
path = "lib.rs"
test = true
doctest = false

[lints]
workspace = true

[dependencies]
stringleton = { path = "../../stringleton", features = ["debug-assertions"] }
foreign-crate-registry.path = "../foreign-crate-registry"
5 changes: 5 additions & 0 deletions tests/foreign-crate/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stringleton::enable!(::foreign_crate_registry);

pub fn bar() -> stringleton::Symbol {
stringleton::sym!(bar)
}
12 changes: 12 additions & 0 deletions tests/foreign-crate/tests/external_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use foreign_crate::bar;
use foreign_crate_registry::foo;
use stringleton::sym;

// Forwarding to `foreign_crate_registry` through `foreign_crate`.
stringleton::enable!(foreign_crate);

#[test]
fn external_symbols_test() {
assert_eq!(foo(), sym!(foo));
assert_eq!(bar(), sym!(bar));
}