Skip to content

Build error in rustpython-pylib: py_freeze! macro resolves wrong Lib path #7995

Closed

Description

@alok-108

Bug Description

The workspace fails to build on Windows (and possibly other platforms) due to a path error in crates/pylib/src/lib.rs. The py_freeze! macro is invoked with dir = "../Lib", but since the pylib crate is inside crates/pylib/, this resolves to crates/Lib instead of the repository root's Lib/ directory. This causes the build to fail for the entire workspace.

Steps to Reproduce

  1. Clone the repository on a Windows machine (or any machine where relative path resolution matters).
  2. Run cargo build --workspace (or cargo build -p rustpython-pylib).
  3. Observe the build error related to the py_freeze! macro not finding the Lib directory.

Expected Behavior

The py_freeze! macro should correctly find the Lib/ directory at the repository root, and the build should succeed.

Actual Behavior

Build fails with an error indicating that the directory ../Lib cannot be found or is empty.

Environment

  • OS: Windows (also likely affects other OSes depending on Cargo's working directory)
  • Rust version: (output of rustc --version)
  • RustPython commit: (latest main at the time of reporting)

Possible Solution

Change the path in crates/pylib/src/lib.rs from "../Lib" to "../../Lib" so that it correctly points to the root Lib/ directory. Alternatively, use CARGO_MANIFEST_DIR to construct an absolute path.

Additional Context

This issue was discovered while running a full workspace build on Windows. All other crates reference Lib/ correctly; only pylib seems to have this broken relative path.

Activity

  1. added
    C-bug
    on May 29, 2026
  2. ShaharNaveh commented on May 30, 2026

    @ShaharNaveh
    Contributor

    Thanks for the report. Have you ran git config core.symlinks truebefore running the build?

  3. alok-108 commented on May 30, 2026

    @alok-108
    ContributorAuthor

    @ShaharNaveh I tried the core.symlinks setting, but on Windows creating symlinks requires Developer Mode (it's disabled by default for security reasons), so the build still fails with just that.

    I found that simply changing the path in py_freeze! from "../Lib" to "../../Lib" in crates/pylib/src/lib.rs bypasses the symlink entirely and points directly to the root Lib folder. Works fine on Windows now — cargo build -p rustpython-pylib passes.

  4. ShaharNaveh commented on May 30, 2026

    @ShaharNaveh
    Contributor

    @ShaharNaveh I tried the core.symlinks setting, but on Windows creating symlinks requires Developer Mode (it's disabled by default for security reasons), so the build still fails with just that.

    I found that simply changing the path in py_freeze! from "../Lib" to "../../Lib" in crates/pylib/src/lib.rs bypasses the symlink entirely and points directly to the root Lib folder. Works fine on Windows now — cargo build -p rustpython-pylib passes.

    If we can make it relative to the CARGO_MANIFEST_DIR path, it would be great!

  5. alok-108 commented on May 30, 2026

    @alok-108
    ContributorAuthor

    @ShaharNaveh Good idea. I can use concat!(env!("CARGO_MANIFEST_DIR"), "/../../Lib") inside py_freeze!. That way the path always resolves from the crate directory, no matter where it's built or whether symlinks work.

    Does that approach look fine to you? If yes, I'll open a PR with it.

  6. ShaharNaveh commented on May 30, 2026

    @ShaharNaveh
    Contributor

    @ShaharNaveh Good idea. I can use concat!(env!("CARGO_MANIFEST_DIR"), "/../../Lib") inside py_freeze!. That way the path always resolves from the crate directory, no matter where it's built or whether symlinks work.

    Does that approach look fine to you? If yes, I'll open a PR with it.

    sound good to me:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions