@@ -51,17 +51,80 @@ pub fn embedded_helper_utils() -> Result<TempDir, io::Error> {
5151
5252pub fn bundle_libraries (
5353 library_path : Vec < ( & str , Vec < std:: path:: PathBuf > ) > ,
54- ) -> Result < Vec < Library > , io :: Error > {
54+ ) -> Result < Vec < Library > , anyhow :: Error > {
5555 let mut libraries = vec ! [
56- library_from_so( "libcomponentize_py_runtime.so" ) ?,
57- library_from_so( "libpython3.12.so" ) ?,
58- library_from_so( "libc.so" ) ?,
59- library_from_so( "libwasi-emulated-mman.so" ) ?,
60- library_from_so( "libwasi-emulated-process-clocks.so" ) ?,
61- library_from_so( "libwasi-emulated-getpid.so" ) ?,
62- library_from_so( "libwasi-emulated-signal.so" ) ?,
63- library_from_so( "libc++.so" ) ?,
64- library_from_so( "libc++abi.so" ) ?,
56+ Library {
57+ name: "libcomponentize_py_runtime.so" . into( ) ,
58+ module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
59+ env!( "OUT_DIR" ) ,
60+ "/libcomponentize_py_runtime.so.zst"
61+ ) ) ) ) ?,
62+ dl_openable: false ,
63+ } ,
64+ Library {
65+ name: "libpython3.12.so" . into( ) ,
66+ module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
67+ env!( "OUT_DIR" ) ,
68+ "/libpython3.12.so.zst"
69+ ) ) ) ) ?,
70+ dl_openable: false ,
71+ } ,
72+ Library {
73+ name: "libc.so" . into( ) ,
74+ module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
75+ env!( "OUT_DIR" ) ,
76+ "/libc.so.zst"
77+ ) ) ) ) ?,
78+ dl_openable: false ,
79+ } ,
80+ Library {
81+ name: "libwasi-emulated-mman.so" . into( ) ,
82+ module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
83+ env!( "OUT_DIR" ) ,
84+ "/libwasi-emulated-mman.so.zst"
85+ ) ) ) ) ?,
86+ dl_openable: false ,
87+ } ,
88+ Library {
89+ name: "libwasi-emulated-process-clocks.so" . into( ) ,
90+ module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
91+ env!( "OUT_DIR" ) ,
92+ "/libwasi-emulated-process-clocks.so.zst"
93+ ) ) ) ) ?,
94+ dl_openable: false ,
95+ } ,
96+ Library {
97+ name: "libwasi-emulated-getpid.so" . into( ) ,
98+ module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
99+ env!( "OUT_DIR" ) ,
100+ "/libwasi-emulated-getpid.so.zst"
101+ ) ) ) ) ?,
102+ dl_openable: false ,
103+ } ,
104+ Library {
105+ name: "libwasi-emulated-signal.so" . into( ) ,
106+ module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
107+ env!( "OUT_DIR" ) ,
108+ "/libwasi-emulated-signal.so.zst"
109+ ) ) ) ) ?,
110+ dl_openable: false ,
111+ } ,
112+ Library {
113+ name: "libc++.so" . into( ) ,
114+ module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
115+ env!( "OUT_DIR" ) ,
116+ "/libc++.so.zst"
117+ ) ) ) ) ?,
118+ dl_openable: false ,
119+ } ,
120+ Library {
121+ name: "libc++abi.so" . into( ) ,
122+ module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
123+ env!( "OUT_DIR" ) ,
124+ "/libc++abi.so.zst"
125+ ) ) ) ) ?,
126+ dl_openable: false ,
127+ } ,
65128 ] ;
66129
67130 for ( index, ( path, libs) ) in library_path. iter ( ) . enumerate ( ) {
@@ -76,7 +139,7 @@ pub fn bundle_libraries(
76139
77140 libraries. push ( Library {
78141 name : format ! ( "/{index}/{path}" ) ,
79- module : fs:: read ( library) . unwrap ( ) ,
142+ module : fs:: read ( library) . with_context ( || library . display ( ) . to_string ( ) ) ? ,
80143 dl_openable : true ,
81144 } ) ;
82145 }
@@ -85,18 +148,6 @@ pub fn bundle_libraries(
85148 Ok ( libraries)
86149}
87150
88- fn library_from_so ( library_name : & str ) -> Result < Library , io:: Error > {
89- let path = env ! ( "OUT_DIR" ) . to_owned ( ) ;
90- let filepath = path + "/" + library_name + ".zst" ;
91- let bytes = fs:: read ( filepath) ?;
92-
93- Ok ( Library {
94- name : library_name. into ( ) ,
95- module : zstd:: decode_all ( Cursor :: new ( bytes) ) ?,
96- dl_openable : false ,
97- } )
98- }
99-
100151pub fn search_for_libraries_and_configs < ' a > (
101152 python_path : & ' a Vec < & ' a str > ,
102153 module_worlds : & ' a [ ( & ' a str , & ' a str ) ] ,
@@ -171,15 +222,19 @@ fn search_directory(
171222 modules_seen : & mut HashSet < String > ,
172223) -> Result < ( ) , anyhow:: Error > {
173224 if path. is_dir ( ) {
174- for entry in fs:: read_dir ( path) ? {
225+ for entry in fs:: read_dir ( path) . with_context ( || path . display ( ) . to_string ( ) ) ? {
175226 search_directory ( root, & entry?. path ( ) , libraries, configs, modules_seen) ?;
176227 }
177228 } else if let Some ( name) = path. file_name ( ) . and_then ( |name| name. to_str ( ) ) {
178229 if name. ends_with ( NATIVE_EXTENSION_SUFFIX ) {
179230 libraries. push ( path. to_owned ( ) ) ;
180231 } else if name == "componentize-py.toml" {
181- let root = root. canonicalize ( ) ?;
182- let path = path. canonicalize ( ) ?;
232+ let root = root
233+ . canonicalize ( )
234+ . with_context ( || root. display ( ) . to_string ( ) ) ?;
235+ let path = path
236+ . canonicalize ( )
237+ . with_context ( || path. display ( ) . to_string ( ) ) ?;
183238
184239 let module = module_name ( & root, & path)
185240 . ok_or_else ( || anyhow ! ( "unable to determine module name for {}" , path. display( ) ) ) ?;
@@ -224,7 +279,9 @@ fn search_directory(
224279 module,
225280 root : root. to_owned ( ) ,
226281 path : path. parent ( ) . unwrap ( ) . to_owned ( ) ,
227- config : toml:: from_str :: < RawComponentizePyConfig > ( & fs:: read_to_string ( path) ?) ?,
282+ config : toml:: from_str :: < RawComponentizePyConfig > (
283+ & fs:: read_to_string ( & path) . with_context ( || path. display ( ) . to_string ( ) ) ?,
284+ ) ?,
228285 } ) ;
229286 }
230287 }
0 commit comments