Repository: RustPython/RustPython (language: rust)

Issue:
`hello_embed.rs` not working with `freeze-stdlib` feature
## Summary

The example `hello_embed.rs` does not work (but does with stdlib)

The `hello_embed.rs` :
```rust
fn main() -> rustpython::vm::PyResult<()> {
    rustpython::vm::Interpreter::without_stdlib(Default::default()).enter(|vm| {
        let scope = vm.new_scope_with_builtins();
        let source = r#"print("Hello World!")"#;
        let code_obj = vm
            .compile(source, rustpython::vm::compiler::Mode::Exec, "<embedded>".to_owned())
            .map_err(|err| vm.new_syntax_error(&err, Some(source)))?;

        vm.run_code_obj(code_obj, scope)?;

        Ok(())
    })
}
```
The `Cargo.toml` file :
```toml
[dependencies]
rustpython = { git = "https://github.com/RustPython/RustPython.git", features = ["freeze-stdlib"] }
```

## Error

The error I get with backtrace :
```
lost sys.stderr
RuntimeError: lost sys.stderr
Original exception was:
lost sys.stderr
ImportError: No such frozen object named codecs
[...]
```



Discussion / hints:

Fix patch:
diff --git a/pylib/build.rs b/pylib/build.rs
index 52a2e3a632..1aca8b3318 100644
--- a/pylib/build.rs
+++ b/pylib/build.rs
@@ -1,11 +1,14 @@
 fn main() {
-    process_python_libs("../Lib/python_builtins/*");
+    process_python_libs("../vm/Lib/python_builtins/*");
 
     #[cfg(not(feature = "stdlib"))]
-    process_python_libs("../Lib/core_modules/*");
-
-    #[cfg(feature = "stdlib")]
-    process_python_libs("../../Lib/**/*");
+    process_python_libs("../vm/Lib/core_modules/*");
+    #[cfg(feature = "freeze-stdlib")]
+    if cfg!(windows) {
+        process_python_libs("../Lib/**/*");
+    } else {
+        process_python_libs("./Lib/**/*");
+    }
 
     if cfg!(windows) {
         if let Ok(real_path) = std::fs::read_to_string("Lib") {
diff --git a/vm/src/vm/mod.rs b/vm/src/vm/mod.rs
index b01e28821e..fa2dfb9073 100644
--- a/vm/src/vm/mod.rs
+++ b/vm/src/vm/mod.rs
@@ -244,11 +244,13 @@ impl VirtualMachine {
 
     fn import_utf8_encodings(&mut self) -> PyResult<()> {
         import::import_frozen(self, "codecs")?;
-        let encoding_module_name = if cfg!(feature = "freeze-stdlib") {
-            "encodings.utf_8"
-        } else {
-            "encodings_utf_8"
-        };
+        // FIXME: See corresponding part of `core_frozen_inits`
+        // let encoding_module_name = if cfg!(feature = "freeze-stdlib") {
+        //     "encodings.utf_8"
+        // } else {
+        //     "encodings_utf_8"
+        // };
+        let encoding_module_name = "encodings_utf_8";
         let encoding_module = import::import_frozen(self, encoding_module_name)?;
         let getregentry = encoding_module.get_attr("getregentry", self)?;
         let codec_info = getregentry.call((), self)?;
@@ -875,7 +877,9 @@ fn core_frozen_inits() -> impl Iterator<Item = (&'static str, FrozenModule)> {
 
     // core stdlib Python modules that the vm calls into, but are still used in Python
     // application code, e.g. copyreg
-    #[cfg(not(feature = "freeze-stdlib"))]
+    // FIXME: Initializing core_modules here results duplicated frozen module generation for core_modules.
+    // We need a way to initialize this modules for both `Interpreter::without_stdlib()` and `InterpreterConfig::new().init_stdlib().interpreter()`
+    // #[cfg(not(feature = "freeze-stdlib"))]
     ext_modules!(
         iter,
         dir = "./Lib/core_modules",


Test patch: