File tree Expand file tree Collapse file tree 2 files changed +33
-25
lines changed Expand file tree Collapse file tree 2 files changed +33
-25
lines changed Original file line number Diff line number Diff line change 1111 serde:: Deserialize ,
1212 std:: {
1313 collections:: HashMap ,
14- env, fs,
15- io:: Cursor ,
14+ fs,
1615 iter,
1716 ops:: Deref ,
1817 path:: { Path , PathBuf } ,
@@ -34,6 +33,7 @@ mod abi;
3433mod bindgen;
3534mod bindings;
3635pub mod command;
36+ mod link;
3737mod prelink;
3838#[ cfg( feature = "pyo3" ) ]
3939mod python;
@@ -326,29 +326,7 @@ pub async fn componentize(
326326 dl_openable : false ,
327327 } ) ;
328328
329- // Link all the libraries (including any native extensions) into a single component.
330- let mut linker = wit_component:: Linker :: default ( )
331- . validate ( true )
332- . use_built_in_libdl ( true ) ;
333-
334- for Library {
335- name,
336- module,
337- dl_openable,
338- } in & libraries
339- {
340- linker = linker. library ( name, module, * dl_openable) ?;
341- }
342-
343- linker = linker. adapter (
344- "wasi_snapshot_preview1" ,
345- & zstd:: decode_all ( Cursor :: new ( include_bytes ! ( concat!(
346- env!( "OUT_DIR" ) ,
347- "/wasi_snapshot_preview1.reactor.wasm.zst"
348- ) ) ) ) ?,
349- ) ?;
350-
351- let component = linker. encode ( ) ?;
329+ let component = link:: link_libraries ( & libraries) ?;
352330
353331 let stubbed_component = if stub_wasi {
354332 stubwasi:: link_stub_modules ( libraries) ?
Original file line number Diff line number Diff line change 1+ use std:: io:: Cursor ;
2+
3+ use anyhow:: Result ;
4+
5+ use crate :: Library ;
6+
7+ pub fn link_libraries ( libraries : & [ Library ] ) -> Result < Vec < u8 > > {
8+ let mut linker = wit_component:: Linker :: default ( )
9+ . validate ( true )
10+ . use_built_in_libdl ( true ) ;
11+
12+ for Library {
13+ name,
14+ module,
15+ dl_openable,
16+ } in libraries
17+ {
18+ linker = linker. library ( name, module, * dl_openable) ?;
19+ }
20+
21+ linker = linker. adapter (
22+ "wasi_snapshot_preview1" ,
23+ & zstd:: decode_all ( Cursor :: new ( include_bytes ! ( concat!(
24+ env!( "OUT_DIR" ) ,
25+ "/wasi_snapshot_preview1.reactor.wasm.zst"
26+ ) ) ) ) ?,
27+ ) ?;
28+
29+ return linker. encode ( ) . map_err ( |e| anyhow:: anyhow!( e) ) ;
30+ }
You can’t perform that action at this time.
0 commit comments