C/C++ projects packaged for Zig

(github.com)

23 points | by jcbhmr 2 hours ago

4 comments

  • fuhsnn 18 minutes ago
    These look more like configure snapshots for Zig's bundled Clang than full ports of build system.

    The HAVE_/WITH_ defines are supposed to be dynamically probed to adapt to different toolchain environments, setting them manually like that[1][2][3] could only work well for specific targets and for specific versions.

    [1] https://github.com/allyourcodebase/libxml2/blob/38fb69d375bc...

    [2] https://github.com/allyourcodebase/rnnoise/blob/47db9c212d7e...

    [3] https://github.com/allyourcodebase/wayland/blob/f992cd71e199...

  • rtpg 1 hour ago
    I'm a bit worried this is intro'ing the classic problem we have in Bazel land, where everyone is having to show up with their own sort of packaging scripts etc instead of using upstream tooling one way or another.

    I had the impression `zig` already has stuff like `zig cc`. Would... would `zig make` be an impossible proposition? Maybe that makes no sense.

    • peesem 2 minutes ago
      you _can_ just tell zig build to call make. the only benefits of an inbuilt make would be not having to install it and that it could maybe intercept calls to external compilers and replace them with `zig cc` or something similar but i get the impression that supporting nontrivial make scripts would be very hard
    • Defletter 9 minutes ago
      This is something that bothers me about languages that proclaim C/C++ compat because it's almost exclusively just talking about the ABI. I will say that Zig's build system is definitely one of the better ones, just look at the sqlite3 repo: it just points to the amalgamation zip and compiles it statically, meaning you can compile it with whichever flags you want. Even though I personally don't use sqlite, I cannot help but appreciate the simplicity. Whereas other systems languages with C/C++ compat (eg: D) cannot do this.

      With that said, Zig falls well short when dependencies have more involved build systems that are too obnoxious to recreate, eg: libevent. I have a bit of a sentimental attachment to libevent and would love to use it within my Zig projects, but the only viable options are: 1) dynamically link; 2) have two [or more] separate build steps; or 3) wait until allyourcodebase does the obnoxious work for me. None of which are appealing so I end up using different libraries just for the build-system integration. And by their nature of being Zig libraries, they're usually less known, less battle-tested, and riskier to use because it's more likely to be some random guy's side project.

      Putting aside the StackOverflow tier "why would you ever do/want that?" troll argument, the issue is that I'm being obstructed from using the libraries I want to use over build system incompatibilities. It feels somewhat similar to the complaint about having two [or more] languages within the same codebase.

    • kingstnap 57 minutes ago
      zig make is zig build.

      I haven't kept my zig skills sharp enough but zig build and the build.zig file basically lets you create a dag of steps and create various targets. It's basically make but the programming language is zig itself and the associated code happens to be in the standard library.

      https://ziglang.org/documentation/0.16.0/std/#std.Build

      https://ziglang.org/learn/build-system/

    • forrestthewoods 33 minutes ago
      > classic problem we have in Bazel land

      Can you tell me more about this? I’ve never used Bazel. I have used Buck extensively. But have never used either in an open source context.

    • LoganDark 1 hour ago
      When I build software to use on my personal machine, I usually swap the build system out for tup. Maintainers never see this, but tup is just better for me. (Exception: Rust projects that use cargo, and JS projects that use bundling)
  • gracefulliberty 1 hour ago
    Both an excellent showcase of the Zig build system and a convenient way to use C libraries within Zig.
  • jeremyjh 1 hour ago
    I just looked at one example...Wayland's meson.build is 142 LOC, but build.zig is 581.

    https://github.com/allyourcodebase/wayland/blob/master/build... https://github.com/wayland-mirror/wayland/blob/main/meson.bu...

    • wavesquid 31 minutes ago
      The meson build is across multiple files, you should add together:

        meson.build
        meson_options.txt
        doc/meson.build
        egl/meson.build
        src/meson.build
        tests/meson.build
        cursor/meson.build
        doc/doxygen/meson.build
        doc/publican/meson.build
        doc/doxygen/xml/meson.build
        doc/publican/sources/meson.build
        doc/doxygen/xml/Client/meson.build
        doc/doxygen/xml/Server/meson.build
      • jeremyjh 3 minutes ago
        Well then, nevermind.
    • gregdaniels421 1 hour ago
      The Zig is far more explicit about what it is doing with lots of very long dotted commands for specifiy version headers and such, so maybe not super fair unless you like magic.
      • jeremyjh 46 minutes ago
        Whats an example of magic in the meson.build that you don't understand? I think this is the first meson.build I've ever looked at and it seems very straightforward.