Menu

#3 Support the ziglang python package

1.0
open
nobody
None
2025-11-13
2025-11-09
No

Hi anthon,

could this (optionally) support the Ziglang Python Package,
instead of setting PY_ZIG on the environment?

Related

Tickets: #3

Discussion

  • Anthon van der Neut

    Hi Tobias,

    I somehow missed that the Zig compiler package (ziglang) had been uploaded to PyPI when I made the 0.2.0 release. I have considered this before, but never got to a decision, primarily because I don't want to force people to install ziglang to every virtual environment, if they already have the file somewhere global.

    Reconsidering this, making the package optional is probably the way to go (i.e. pip install setuptools-zig[ziglang])

    • I have to check, but should try to be able get the correct ziglang version (i.e. not the latest), this would allow other packages to have setuptools-zig[ziglang] as a requirement and get a matching compiler (e.g. ziglang==0.10.1.post1 for setuptools-zig==0.2.1)
    • I have to look at the mechanism, again, but not require the PY_ZIG environment variable, and when starting zig fails, erroring while displaing the message to run pip install setuptools-zig[ziglang]
    • I also want to make it so that if PY_ZIG points to a directory instead of an executable, it is assumed that the different versions are installed (on my dev machine /opt/zig/{0.10.1,0.11.0,...,0.15.2}) that the latest patch version of the required major.minor version matching the setuptools-zig is used.

    I should also make sure things are working with the latest version (and maybe intermediate versions between 0.10 and 0.15, depending on the amount of work) as well.

    So thanks for reminding, and and feel free to comment on the above approach. Are you using setuptools-zig in some package?

     
    • Tobias Simetsreiter

      Hi,

      I have done some testing, and would prefer not to couple ziglang and
      setuptools-zig versions tightly.
      Rather leave it to the consuming package and have it as a separate
      build-dependency next to it.
      So my idea was to add a boolean option on the build_zig config to use
      whatever version is installed alongside setuptools-zig and keep the PY_ZIG
      usage the default.
      Something like this:
      dasimmet / setuptools-zig - Code / [5d9822] /setuptools_zig.py
      https://sourceforge.net/u/dasimmet/setuptools-zig/ci/default/tree/setuptools_zig.py#l31

      zig 0.15.2 is not out on pypi yet, i raised a ticket there, to have it
      added.

      Also at some point @cInclude will be removed from the zig language, at that
      point it would make sense to support build.zig or have zig translate-c
      run separately

      I'm looking into creating a lib to parse zig's .zon into python
      dictionaries, but i'm new to native python extension amd its not published
      yet.

      Am Di., 11. Nov. 2025 um 09:47 Uhr schrieb Anthon van der Neut anthon@users.sourceforge.net:

      Hi Tobias,

      I somehow missed that the Zig compiler package (ziglang) had been
      uploaded to PyPI when I made the 0.2.0 release. I have considered this
      before, but never got to a decision, primarily because I don't want to
      force people to install ziglang to every virtual environment, if they
      already have the file somewhere global.

      Reconsidering this, making the package optional is probably the way to go
      (i.e. pip install setuptools-zig[ziglang])

      • I have to check, but should try to be able get the correct ziglang
        version (i.e. not the latest), this would allow other packages to have
        setuptools-zig[ziglang] as a requirement and get a matching compiler
        (e.g. ziglang==0.10.1.post1 for setuptools-zig==0.2.1)
      • I have to look at the mechanism, again, but not require the PY_ZIG
        environment variable, and when starting zig fails, erroring while
        displaing the message to run pip install setuptools-zig[ziglang]
      • I also want to make it so that if PY_ZIG points to a directory
        instead of an executable, it is assumed that the different versions are
        installed (on my dev machine /opt/zig/{0.10.1,0.11.0,...,0.15.2}) that
        the latest patch version of the required major.minor version matching the
        setuptools-zig is used.

      I should also make sure things are working with the latest version (and
      maybe intermediate versions between 0.10 and 0.15, depending on the amount
      of work) as well.

      So thanks for reminding, and and feel free to comment on the above
      approach. Are you using setuptools-zig in some package?


      [tickets:#3] https://sourceforge.net/p/setuptools-zig/tickets/3/
      Support the ziglang python package

      Status: open
      Milestone: 1.0
      Created: Sun Nov 09, 2025 03:15 PM UTC by Tobias Simetsreiter
      Last Updated: Sun Nov 09, 2025 03:15 PM UTC
      Owner: nobody

      Hi anthon,

      could this (optionally) support the Ziglang Python Package
      https://pypi.org/project/ziglang/,
      instead of setting PY_ZIG on the environment?


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/setuptools-zig/tickets/3/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Tickets: #3

  • Anthon van der Neut

    I have been working on this, making sure Python 3.9-3.14 work with the examples and wilth Zig 0.11-0.15, which it now does.
    Since all the combinations work, and I don't have to have a specific version of zig with a specific setuptools-zig (or vv.), I decided against the optional extension for now. A user has to specify the build dependency anyway and it doesn't really differ to have:

         setup_requires=['setuptools-zig', 'ziglang'],
    

    instead of

         setup_requires=['setuptools-zig[ziglang]'],
    

    and with the former you can easily do 'ziglang<0.15', if you program requires that.

    The way I implemented the (minor) changes to setuptools-zig by trying to import ziglang and if that works add the path of the loaded module to sys.path (and to os.environ['PATH']as well, just in case).
    Now I still have to check the sum.c and c_int.c+sum.zig in the README need updating. Once the readme is done I'll post a new version.

    As for parsing .zon files, I am not even sure if the zig code for that is a library. If it does and has a not to complex list internal datastructures, it may be possible to "wrap" each of this with a PyObject.

     

Log in to post a comment.