marler8997 / zigup

Download and manage zig compilers.
MIT No Attribution
772 stars 61 forks source link

Consistent, predictable, simplified build steps #87

Open resolritter opened 1 year ago

resolritter commented 1 year ago

I think it would be valuable for there to be a way of building zigup without having to guess which compiler version is compatible with it. Even better would be to have be a single build command which sets up all the required build tools and produces the binary regardless of which operating system is used. I understand that this "single build command" is supposed to be zig build, but I need to have a working zig installation for that, which is what this tool is supposed to help me with (i.e. a "chicken and egg situation").

resolritter commented 1 year ago

I've seen other tools deal with that problem by providing a install script which works across different distributions and operating systems. That is the case for e.g. rustup and pyenv.

Alternatively, in the past I've used containers to set up reproducible build procedures. Something like the following:

# build zigup inside of a Docker image
docker build --tag zigup-builder .

# create a temporary container 
docker container create --name tmp zigup-builder

# pull the built zigup from the container
docker container cp tmp:/zigup .

I don't think that using containers is necessary, but it might be easier that way. Notably, this is the approach that cross takes and it works pretty well for them.

marler8997 commented 1 year ago

I think it would be valuable for there to be a way of building zigup without having to guess which compiler version is compatiable with it.

Me too, here's the latest proposal for a standardized way of doing this: https://github.com/ziglang/zig/issues/14475

Outside of having a standard, any mechanism we choose will be non-standard and require developers to read the documentation and/or scrub the codebase to figure out what version they'll need. Before standard is set, the simplest/most obvious way to do this in my mind is to document the version in the README which I'd be willing to maintain.

but I need to have a working zig installation for that

This isn't really a solvable problem, you always have to start with something. The best you can do is make that "thing" you need to start with the simplest/easiest thing to setup as possible (or even better, likely to already be setup). We currently have 2 main methods to get started with zigup, either you can download a prebuilt zig archive, or you could download a prebuilt zigup binary. Both these are relatively simple to do, but, I'd be open to making improvements on these workflows such as providing convenient scripts to set them up for you.

By switching to docker we've introduced a relatively large dependency in comparison to what we have now that requires more setup/system integration. Docker is large and requires interaction with your system including networking, namespacing, daemons, elevated privileges etc. One option is to support Docker in addition to our current methods, but, if we accepted that reasoning alone to add new bootstrap methods then we'd have an endless sea of bootstrap frameworks to support (CMake/Meson/Bazel/Npm/Nuget/Docker/RunC/etc). So we have to evaluate each one on a case-by-case basis. A strong argument in favor of each one would be how popular/ubiquitous it is. I think this would be a strong argument for a BASH script used in combination with a set of HTTP client tools like curl/wget/etc.

resolritter commented 1 year ago

One option is to support Docker in addition to our current methods

This is indeed my intent. Sorry if it wasn't clear enough.

By switching to docker we've introduced a relatively large dependency in comparison to what we have now that requires more setup/system integration. Docker is large and requires interaction with your system including networking, namespacing, daemons, elevated privileges etc.

While that is true, it's also possible to build Dockerfiles with podman build .. I reckon Podman is generally safer and less complicated to set up than Docker.

I think this would be a strong argument for a BASH script used in combination with a set of HTTP client tools like curl/wget/etc.

That's the approach taken by e.g. pyenv and rustup (mentioned in https://github.com/marler8997/zigup/issues/87#issuecomment-1528892277). It requires that those tools you mentioned are available in the host in advance, otherwise you have to tell the user to install them by himself or somehow provision them during the script. They probably are already installed for Linux and macOS users, but not for Windows users unless they're using WSL.

Perhaps there could be a Python script which:

1 - Downloads the Zig toolchain (Python provides an HTTP client and tar support in its standard library) 2 - Downloads git if it is not available in the host 3 - Builds zigup

That could be good enough for most users. On the other hand, using a Dockerfile saves us the trouble of maintaining said script. docker build --build-arg ZIGUP_TARGET=$TARGET works regardless of operating system thanks to Zig's cross-compilation capabilities. To your point, Docker seems ubiquitous/popular enough and Docker haters can always use Podman otherwise.