Skip to content

Commit 716d0db

Browse files
committed
Fix pylib dependency for binary
1 parent e8b9b4b commit 716d0db

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

pylib/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// so build.rs sets this env var
77
pub const LIB_PATH: &str = match option_env!("win_lib_path") {
88
Some(s) => s,
9-
None => concat!(env!("CARGO_MANIFEST_DIR"), "/../Lib"),
9+
None => concat!(env!("CARGO_MANIFEST_DIR"), "/Lib"),
1010
};
1111

1212
#[cfg(feature = "freeze-stdlib")]
1313
pub fn frozen_stdlib() -> impl Iterator<Item = (String, rustpython_compiler_core::FrozenModule)> {
14-
rustpython_derive::py_freeze!(dir = "../Lib", crate_name = "rustpython_compiler_core")
14+
rustpython_derive::py_freeze!(dir = "./Lib", crate_name = "rustpython_compiler_core")
1515
}

src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ extern crate env_logger;
4343
#[macro_use]
4444
extern crate log;
4545

46+
use rustpython_pylib;
47+
4648
mod shell;
4749

4850
use clap::{App, AppSettings, Arg, ArgMatches};
@@ -249,6 +251,11 @@ fn add_stdlib(vm: &mut VirtualMachine) {
249251
#[cfg(feature = "stdlib")]
250252
vm.add_native_modules(rustpython_stdlib::get_module_inits());
251253

254+
let state = PyRc::get_mut(&mut vm.state).expect("vm.state must allow borrow mut");
255+
let settings = &mut state.settings;
256+
// add the current directory to sys.path
257+
settings.path_list.push("".to_owned());
258+
252259
// if we're on freeze-stdlib, the core stdlib modules will be included anyway
253260
#[cfg(feature = "freeze-stdlib")]
254261
vm.add_frozen(rustpython_pylib::frozen_stdlib());
@@ -257,25 +264,24 @@ fn add_stdlib(vm: &mut VirtualMachine) {
257264
{
258265
use rustpython_vm::common::rc::PyRc;
259266
let state = PyRc::get_mut(&mut vm.state).unwrap();
267+
let settings = &mut state.settings;
260268

261269
#[allow(clippy::needless_collect)] // false positive
262-
let path_list: Vec<_> = state.settings.path_list.drain(..).collect();
270+
let path_list: Vec<_> = settings.path_list.drain(..).collect();
263271

264272
// BUILDTIME_RUSTPYTHONPATH should be set when distributing
265273
if let Some(paths) = option_env!("BUILDTIME_RUSTPYTHONPATH") {
266-
state
267-
.settings
274+
settings
268275
.path_list
269276
.extend(split_paths(paths).map(|path| path.into_os_string().into_string().unwrap()))
270277
} else {
271278
#[cfg(feature = "rustpython-pylib")]
272-
state
273-
.settings
279+
settings
274280
.path_list
275281
.push(rustpython_pylib::LIB_PATH.to_owned())
276282
}
277283

278-
state.settings.path_list.extend(path_list.into_iter());
284+
settings.path_list.extend(path_list.into_iter());
279285
}
280286
}
281287

wasm/lib/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ edition = "2021"
1111
crate-type = ["cdylib", "rlib"]
1212

1313
[features]
14-
default = ["stdlib"]
15-
stdlib = ["freeze-stdlib", "rustpython-pylib", "rustpython-stdlib"]
16-
freeze-stdlib = ["rustpython-vm/freeze-stdlib", "rustpython-pylib?/freeze-stdlib"]
14+
default = ["freeze-stdlib"]
15+
freeze-stdlib = ["rustpython-vm/freeze-stdlib", "rustpython-pylib/freeze-stdlib", "rustpython-stdlib"]
1716
no-start-func = []
1817

1918
[dependencies]

0 commit comments

Comments
 (0)