Skip to content

Commit 0274083

Browse files
authored
Update workspace to the 2024 edition (#2495)
* Update workspace to the 2024 edition With the MSRV now high enough this is possible. A bit belated but hey better late than never. * Update playground off of cargo-component * Update libdl build * Fix wasi-sdk used for libdl.so
1 parent d99e559 commit 0274083

File tree

8 files changed

+153
-161
lines changed

8 files changed

+153
-161
lines changed

.github/workflows/playground.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ jobs:
2727
with:
2828
node-version: 20
2929
- uses: ./.github/actions/install-rust
30-
- uses: cargo-bins/cargo-binstall@v1.6.9
31-
- run: cargo binstall cargo-component@0.20.0 -y
3230
- run: rustup component add rustfmt # needed for cargo-component, apparently?
33-
- run: rustup target add wasm32-wasip1
31+
- run: rustup target add wasm32-wasip2
3432
- run: npm ci
3533
working-directory: playground
3634
- run: npm run build

Cargo.lock

Lines changed: 2 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ unnecessary_cast = 'warn'
8585
# allow_attributes_without_reason = 'warn'
8686

8787
[workspace.package]
88-
edition = '2021'
88+
edition = '2024'
8989
license = "Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT"
9090
version = "0.247.0"
9191
# Current thinking for wasm-tools is that the minimum supported Rust version

crates/wit-component/dl/src/lib.rs

Lines changed: 83 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,36 @@ static mut ERROR: *const c_char = ptr::null();
5151
static mut LIBRARIES: *const Libraries = ptr::null();
5252

5353
unsafe fn invalid_handle(library: *const c_void) -> bool {
54-
if LIBRARIES.is_null() {
55-
panic!(
56-
"`__wasm_set_libraries` should have been called during \
54+
unsafe {
55+
if LIBRARIES.is_null() {
56+
panic!(
57+
"`__wasm_set_libraries` should have been called during \
5758
instantiation with a non-NULL value"
58-
);
59-
}
60-
61-
let library = library as *const Library;
62-
if (0..(*LIBRARIES).count)
63-
.any(|index| (*LIBRARIES).libraries.add(usize::try_from(index).unwrap()) == library)
64-
{
65-
false
66-
} else {
67-
ERROR = c"invalid library handle".as_ptr();
68-
true
59+
);
60+
}
61+
62+
let library = library as *const Library;
63+
if (0..(*LIBRARIES).count)
64+
.any(|index| (*LIBRARIES).libraries.add(usize::try_from(index).unwrap()) == library)
65+
{
66+
false
67+
} else {
68+
ERROR = c"invalid library handle".as_ptr();
69+
true
70+
}
6971
}
7072
}
7173

7274
/// # Safety
7375
///
7476
/// `library` must be a valid, not-yet-closed library pointer returned by
7577
/// `dlopen`.
76-
#[no_mangle]
78+
#[unsafe(no_mangle)]
7779
pub unsafe extern "C" fn dlclose(library: *mut c_void) -> c_int {
78-
if invalid_handle(library) { -1 } else { 0 }
80+
unsafe { if invalid_handle(library) { -1 } else { 0 } }
7981
}
8082

81-
#[no_mangle]
83+
#[unsafe(no_mangle)]
8284
pub extern "C" fn dlerror() -> *const c_char {
8385
unsafe {
8486
let value = ERROR;
@@ -90,85 +92,89 @@ pub extern "C" fn dlerror() -> *const c_char {
9092
/// # Safety
9193
///
9294
/// `name` must be a valid pointer to a null-terminated string.
93-
#[no_mangle]
95+
#[unsafe(no_mangle)]
9496
pub unsafe extern "C" fn dlopen(name: *const c_char, flags: c_int) -> *const c_void {
95-
if LIBRARIES.is_null() {
96-
panic!(
97-
"`__wasm_set_libraries` should have been called during \
97+
unsafe {
98+
if LIBRARIES.is_null() {
99+
panic!(
100+
"`__wasm_set_libraries` should have been called during \
98101
instantiation with a non-NULL value"
102+
);
103+
}
104+
105+
if (flags & !(RTLD_LAZY | RTLD_NOW | RTLD_GLOBAL)) != 0 {
106+
// TODO
107+
ERROR = c"dlopen flags not yet supported".as_ptr();
108+
return ptr::null();
109+
}
110+
111+
let name = CStr::from_ptr(name);
112+
let name = name.to_bytes();
113+
let libraries = slice::from_raw_parts(
114+
(*LIBRARIES).libraries,
115+
usize::try_from((*LIBRARIES).count).unwrap(),
99116
);
100-
}
101-
102-
if (flags & !(RTLD_LAZY | RTLD_NOW | RTLD_GLOBAL)) != 0 {
103-
// TODO
104-
ERROR = c"dlopen flags not yet supported".as_ptr();
105-
return ptr::null();
106-
}
107-
108-
let name = CStr::from_ptr(name);
109-
let name = name.to_bytes();
110-
let libraries = slice::from_raw_parts(
111-
(*LIBRARIES).libraries,
112-
usize::try_from((*LIBRARIES).count).unwrap(),
113-
);
114-
if let Ok(index) = libraries.binary_search_by(|library| {
115-
slice::from_raw_parts(
116-
library.name.data,
117-
usize::try_from(library.name.length).unwrap(),
118-
)
119-
.cmp(name)
120-
}) {
121-
&libraries[index] as *const _ as _
122-
} else {
123-
ERROR = c"library not found".as_ptr();
124-
ptr::null()
117+
if let Ok(index) = libraries.binary_search_by(|library| {
118+
slice::from_raw_parts(
119+
library.name.data,
120+
usize::try_from(library.name.length).unwrap(),
121+
)
122+
.cmp(name)
123+
}) {
124+
&libraries[index] as *const _ as _
125+
} else {
126+
ERROR = c"library not found".as_ptr();
127+
ptr::null()
128+
}
125129
}
126130
}
127131

128132
/// # Safety
129133
///
130134
/// `library` must be a valid, not-yet-closed library pointer returned by
131135
/// `dlopen`, and `name` must be a valid pointer to a null-terminated string.
132-
#[no_mangle]
136+
#[unsafe(no_mangle)]
133137
pub unsafe extern "C" fn dlsym(library: *const c_void, name: *const c_char) -> *const c_void {
134-
if library as isize == RTLD_NEXT || library as isize == RTLD_DEFAULT {
135-
// TODO
136-
ERROR = c"dlsym RTLD_NEXT and RTLD_DEFAULT not yet supported".as_ptr();
137-
return ptr::null();
138-
}
139-
140-
if invalid_handle(library) {
141-
return ptr::null();
142-
}
143-
144-
let library = library as *const Library;
145-
let name = CStr::from_ptr(name);
146-
let name = name.to_bytes();
147-
let symbols = slice::from_raw_parts(
148-
(*library).symbols.symbols,
149-
usize::try_from((*library).symbols.count).unwrap(),
150-
);
151-
if let Ok(index) = symbols.binary_search_by(|symbol| {
152-
slice::from_raw_parts(
153-
symbol.name.data,
154-
usize::try_from(symbol.name.length).unwrap(),
155-
)
156-
.cmp(name)
157-
}) {
158-
symbols[index].address
159-
} else {
160-
ERROR = c"symbol not found".as_ptr();
161-
ptr::null()
138+
unsafe {
139+
if library as isize == RTLD_NEXT || library as isize == RTLD_DEFAULT {
140+
// TODO
141+
ERROR = c"dlsym RTLD_NEXT and RTLD_DEFAULT not yet supported".as_ptr();
142+
return ptr::null();
143+
}
144+
if invalid_handle(library) {
145+
return ptr::null();
146+
}
147+
let library = library as *const Library;
148+
let name = CStr::from_ptr(name);
149+
let name = name.to_bytes();
150+
let symbols = slice::from_raw_parts(
151+
(*library).symbols.symbols,
152+
usize::try_from((*library).symbols.count).unwrap(),
153+
);
154+
if let Ok(index) = symbols.binary_search_by(|symbol| {
155+
slice::from_raw_parts(
156+
symbol.name.data,
157+
usize::try_from(symbol.name.length).unwrap(),
158+
)
159+
.cmp(name)
160+
}) {
161+
symbols[index].address
162+
} else {
163+
ERROR = c"symbol not found".as_ptr();
164+
ptr::null()
165+
}
162166
}
163167
}
164168

165169
/// # Safety
166170
///
167171
/// `libraries` must be a valid pointer to a `Libraries` object, and this
168172
/// pointer must remain valid for the lifetime of the process.
169-
#[no_mangle]
173+
#[unsafe(no_mangle)]
170174
pub unsafe extern "C" fn __wasm_set_libraries(libraries: *const Libraries) {
171-
LIBRARIES = libraries;
175+
unsafe {
176+
LIBRARIES = libraries;
177+
}
172178
}
173179

174180
#[cfg(target_arch = "wasm32")]

0 commit comments

Comments
 (0)