11#![ deny( warnings) ]
22
33use std:: {
4- fs,
4+ fs:: { self } ,
55 io:: { self , Cursor } ,
66} ;
77
@@ -14,7 +14,7 @@ use crate::Library;
1414
1515pub fn embedded_python_standard_library ( ) -> Result < TempDir , io:: Error > {
1616 // Untar the embedded copy of the Python standard library into a temporary directory
17- let stdlib = tempfile:: tempdir ( ) . expect ( "could not create temp dirfor python stnadard lib" ) ;
17+ let stdlib = tempfile:: tempdir ( ) ? ;
1818
1919 Archive :: new ( Decoder :: new ( Cursor :: new ( include_bytes ! ( concat!(
2020 env!( "OUT_DIR" ) ,
@@ -28,7 +28,7 @@ pub fn embedded_python_standard_library() -> Result<TempDir, io::Error> {
2828
2929pub fn embedded_helper_utils ( ) -> Result < TempDir , io:: Error > {
3030 // Untar the embedded copy of helper utilities into a temporary directory
31- let bundled = tempfile:: tempdir ( ) . expect ( "could not create tempdir for embedded helper utils" ) ;
31+ let bundled = tempfile:: tempdir ( ) ? ;
3232
3333 Archive :: new ( Decoder :: new ( Cursor :: new ( include_bytes ! ( concat!(
3434 env!( "OUT_DIR" ) ,
@@ -44,78 +44,15 @@ pub fn bundle_libraries(
4444 library_path : Vec < ( & str , Vec < std:: path:: PathBuf > ) > ,
4545) -> Result < Vec < Library > , io:: Error > {
4646 let mut libraries = vec ! [
47- Library {
48- name: "libcomponentize_py_runtime.so" . into( ) ,
49- module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
50- env!( "OUT_DIR" ) ,
51- "/libcomponentize_py_runtime.so.zst"
52- ) ) ) ) ?,
53- dl_openable: false ,
54- } ,
55- Library {
56- name: "libpython3.12.so" . into( ) ,
57- module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
58- env!( "OUT_DIR" ) ,
59- "/libpython3.12.so.zst"
60- ) ) ) ) ?,
61- dl_openable: false ,
62- } ,
63- Library {
64- name: "libc.so" . into( ) ,
65- module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
66- env!( "OUT_DIR" ) ,
67- "/libc.so.zst"
68- ) ) ) ) ?,
69- dl_openable: false ,
70- } ,
71- Library {
72- name: "libwasi-emulated-mman.so" . into( ) ,
73- module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
74- env!( "OUT_DIR" ) ,
75- "/libwasi-emulated-mman.so.zst"
76- ) ) ) ) ?,
77- dl_openable: false ,
78- } ,
79- Library {
80- name: "libwasi-emulated-process-clocks.so" . into( ) ,
81- module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
82- env!( "OUT_DIR" ) ,
83- "/libwasi-emulated-process-clocks.so.zst"
84- ) ) ) ) ?,
85- dl_openable: false ,
86- } ,
87- Library {
88- name: "libwasi-emulated-getpid.so" . into( ) ,
89- module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
90- env!( "OUT_DIR" ) ,
91- "/libwasi-emulated-getpid.so.zst"
92- ) ) ) ) ?,
93- dl_openable: false ,
94- } ,
95- Library {
96- name: "libwasi-emulated-signal.so" . into( ) ,
97- module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
98- env!( "OUT_DIR" ) ,
99- "/libwasi-emulated-signal.so.zst"
100- ) ) ) ) ?,
101- dl_openable: false ,
102- } ,
103- Library {
104- name: "libc++.so" . into( ) ,
105- module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
106- env!( "OUT_DIR" ) ,
107- "/libc++.so.zst"
108- ) ) ) ) ?,
109- dl_openable: false ,
110- } ,
111- Library {
112- name: "libc++abi.so" . into( ) ,
113- module: zstd:: decode_all( Cursor :: new( include_bytes!( concat!(
114- env!( "OUT_DIR" ) ,
115- "/libc++abi.so.zst"
116- ) ) ) ) ?,
117- dl_openable: false ,
118- } ,
47+ library_from_so( "libcomponentize_py_runtime.so" ) ?,
48+ library_from_so( "libpython3.12.so" ) ?,
49+ library_from_so( "libc.so" ) ?,
50+ library_from_so( "libwasi-emulated-mman.so" ) ?,
51+ library_from_so( "libwasi-emulated-process-clocks.so" ) ?,
52+ library_from_so( "libwasi-emulated-getpid.so" ) ?,
53+ library_from_so( "libwasi-emulated-signal.so" ) ?,
54+ library_from_so( "libc++.so" ) ?,
55+ library_from_so( "libc++abi.so" ) ?,
11956 ] ;
12057
12158 for ( index, ( path, libs) ) in library_path. iter ( ) . enumerate ( ) {
@@ -138,3 +75,16 @@ pub fn bundle_libraries(
13875
13976 Ok ( libraries)
14077}
78+
79+ fn library_from_so ( library_name : & str ) -> Result < Library , io:: Error > {
80+ let path = env ! ( "OUT_DIR" ) . to_owned ( ) ;
81+ let filepath = path + "/" + library_name + ".zst" ;
82+ let bytes = fs:: read ( filepath) ?;
83+
84+
85+ return Ok ( Library {
86+ name : library_name. into ( ) ,
87+ module : zstd:: decode_all ( Cursor :: new ( bytes) ) ?,
88+ dl_openable : false ,
89+ } ) ;
90+ }
0 commit comments