Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

translate-c unhappy when building outside source directory #47

Open

Description

@jburgy

Zig Version

0.14.0

Steps to Reproduce and Observed Behavior

$ git clone https://gist.github.com/jburgy/081992ed24df120cd2edde6e56346371
$ cd 081992ed24df120cd2edde6e56346371/
$ zig build
$ PYTHONPATH=zig-out/lib /opt/python/3.13.0/bin/python3 -c "import libext"
$ echo $?
0

Everything works as expected in the happy path above. However, if you do

$ mkdir ../scratch
$ cd ../scratch
$ zig build --build-file ../081992ed24df120cd2edde6e56346371/build.zig

you'll get error: failed to check cache: '../081992ed24df120cd2edde6e56346371/.zig-cache/o/4e4e86279020dbd67ed90b5b94e6e6ba/py.zig' file_hash FileNotFound. Not only does py.zig not exist, its parent (4e4e86279020dbd67ed90b5b94e6e6ba/) does not exist either

Expected Behavior

zig translate-c should write its output to a file regardless of in what folder zig build is run

Activity

  1. jburgy commented on Jul 11, 2025

    @jburgy
    Author

    See https://discord.com/channels/605571803288698900/1393290799684390962 for context as to why zig build runs outside the source root

  2. jburgy commented on Jul 12, 2025

    @jburgy
    Author

    Should this be blocking ziglang/zig#20630?

  3. Vexu commented on Jul 12, 2025

    @Vexu
    Member

    Should this be blocking #20630?

    No, your example works as expected when using https://github.com/ziglang/translate-c.

  4. jburgy commented on Jul 12, 2025

    @jburgy
    Author

    No, your example works as expected when using https://github.com/ziglang/translate-c.

    Not sure I follow that statement. Am I not using ziglang/translate-c when I do

    scratch$ zig build --build-file ../081992ed24df120cd2edde6e56346371/build.zig --verbose
    /opt/zig-linux-x86_64-0.14.0/zig translate-c -lc --listen=- -I /opt/python/3.13.0/include/python3.13 ../081992ed24df120cd2edde6e56346371/py.h 
    CLICOLOR_FORCE=1 pkg-config --list-all 
    /opt/zig-linux-x86_64-0.14.0/zig build-lib -lpython3.13 -ODebug -L /opt/python/3.13.0/lib --dep py -Mroot=../081992ed24df120cd2edde6e56346371/root.zig -ODebug -Mpy=../081992ed24df120cd2edde6e56346371/.zig-cache/o/4e4e86279020dbd67ed90b5b94e6e6ba/py.zig -lc --cache-dir ../081992ed24df120cd2edde6e56346371/.zig-cache --global-cache-dir /home/jburgy/.cache/zig --name ext -dynamic --zig-lib-dir /opt/zig-linux-x86_64-0.14.0/lib/ --listen=- 
    install
    └─ install ext
       └─ zig build-lib ext Debug native 1 errors
    error: failed to check cache: '../081992ed24df120cd2edde6e56346371/.zig-cache/o/4e4e86279020dbd67ed90b5b94e6e6ba/py.zig' file_hash FileNotFound

    (I should also mention that the problem goes away when I use @cImport instead of an explicit py.h and .addTranslateC in build.zig)

  5. Vexu commented on Jul 12, 2025

    @Vexu
    Member

    Not sure I follow that statement. Am I not using ziglang/translate-c when I do

    Not yet, that's why the issue is open.

  6. transferred this issue fromziglang/zigon Sep 26, 2025
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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions