Skip to content

builtin function to expose additional build options #1646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewrk opened this issue Oct 8, 2018 · 7 comments
Closed

builtin function to expose additional build options #1646

andrewrk opened this issue Oct 8, 2018 · 7 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Oct 8, 2018

New builtin function:
@buildOption(comptime name: []const u8, comptime T: type, comptime default_value: T) T

This returns a comptime value, and exposes the option to the Zig command line interface:

zig build-exe --option name value

If the option is buried in a package:

zig build-exe --pkg-begin --option name value --pkg-end

To be decided: how to refer to the std package, since it is automatically added (not explicitly with --pkg-begin ...)

Here's a real life use case, from std/os/index.zig:

// TODO make this a build variable that you can set
const unexpected_error_tracing = false;

zig build-options would be another command similar to build-exe but instead of producing a build artifact, it would simply list all the build options available and their default values.

The zig build system would expose these options in the zig build --help menu. There would be API to set a build option for a given artifact, and thus suppressing it from being exposed as a zig build option.

Another use case for this feature is #1639. Code that calls a function pointer could have the number of stack bytes required be a build option, with a low value as the default. Code that needed a larger stack size could then set a build option to increase the size as necessary.

@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Oct 8, 2018
@andrewrk andrewrk added this to the 0.4.0 milestone Oct 8, 2018
@Manuzor
Copy link
Contributor

Manuzor commented Oct 10, 2018

What about build.zig? Seems like it would feel more natural to set package options there.

I have to admit I'm with Jonathan Blow on this topic. I'd rather have fewer command-line options in favor of more code that controls the build. Build definitions can become complicated rather quickly and I'd rather express them in structured code than in a single flat command line.

@andrewrk
Copy link
Member Author

What about build.zig?

This:

The zig build system would expose these options in the zig build --help menu. There would be API to set a build option for a given artifact, and thus suppressing it from being exposed as a zig build option.

So if you know what you want to do in your build script, you do it, and the option is not user-visible.

@Manuzor
Copy link
Contributor

Manuzor commented Oct 10, 2018

Oh, I misread the proposal the first time and thought the paragraph was describing how custom build options would just be documented via zig build --help. Thanks for clarifying.

@Sahnvour
Copy link
Contributor

This would be very useful, for example to control the level of debug to use in the standard library. We could choose between none, light or heavy debugs (think for example iterator invalidation, allocator canaries and such) independently from the optimization flag (with sound default values).

@andrewrk andrewrk added the accepted This proposal is planned. label Nov 21, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Feb 15, 2019
@andrewrk andrewrk removed the accepted This proposal is planned. label Feb 15, 2019
@andrewrk
Copy link
Member Author

Something like this is still planned but the idea needs to be reworked to take into account #943

@andrewrk andrewrk added the zig build system std.Build, the build runner, `zig build` subcommand, package management label Jul 4, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Aug 28, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Dec 31, 2019
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 27, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@courajs
Copy link
Contributor

courajs commented Oct 23, 2021

Is this resolved by the addition of Builder.addOptions and OptionsStep?

@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Jun 19, 2023
@andrewrk andrewrk removed the zig build system std.Build, the build runner, `zig build` subcommand, package management label Jul 26, 2024
@andrewrk
Copy link
Member Author

The idea behind this was making it possible for the language itself to expose configuration options, and have those options bubble up to the CLI and build system. In the interest of simplicity, I think this is better managed via @import and configuration generated at build time.

@andrewrk andrewrk closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

4 participants