zig icon indicating copy to clipboard operation
zig copied to clipboard

Proposal: support using the compiler as a zig.zon package

Open theoparis opened this issue 1 year ago • 6 comments

Use Cases

  1. Use the native zig backends (once they are ready, of course) as an alternative to using libLLVM*.a
  2. Use the compiler as a library

Use case 2 is what I'm in need of since I want to make an alternative to Nix flakes but with a flake.zig. A build.zig does not fit my use case since I want to have a nix-like CLI with a zix develop similar to nix devShells. This would mean using the compiler to parse the flake.zig, checking types and running the outputs function to extract devShells.default.

theoparis avatar Feb 06 '24 04:02 theoparis

The parser and lexer are already on the std. Maybe what we should do is move the other stages to the std as well.

Arnau478 avatar Feb 06 '24 16:02 Arnau478

+1

Related to this, a similar idea I had was being able to use the zig compiler as a library, such that one could use zig as a scripting language.

You would be able to embed the compiler as a library, then have it compile different zig files at runtime into dylibs. This would allow you to use zig for the same purposes as one currently uses scripting languages like lua.

The advantage to this would be that there would not be any complex interfacing functions or anything required. Zig can easily interface with other zig code since it's the same language.

The use case for this would be things that need to be easily user extensible, such as games and text editors.

VisenDev avatar Feb 06 '24 17:02 VisenDev

yeah the solution to this is to get the compiler in the std.zig namespace not expose it with zon imo. but its a ways out and easier to do once development isnt as rapid (thus making movements cause a wave of merge conflicts)

nektro avatar Feb 06 '24 20:02 nektro

@theoparis has this been implemented?

VisenDev avatar May 12 '24 12:05 VisenDev

No. I have given up on using zig after what happened on the Zig discord. Additionally, there is nowhere else for me to go because it is the only active Zig community.

I have moved to rust and c++ and I do not intend on coming back until the Zig community deals with these horrible moderators/contributors.

theoparis avatar May 13 '24 06:05 theoparis

Regardless of your feelings about the Zig community, it would still be worthwhile to keep the issue open because it allows the Zig developers (distinct from the community) to track it. You can re-open and then click "Unsubscribe" on the sidebar to not receive notifications about it.

sin-ack avatar May 13 '24 11:05 sin-ack