Skip to content
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

Add support for passing null, string literals, enum lists and more to b.dependency() #23340

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

castholm
Copy link
Contributor

I was getting pretty fed up with not being able to pass null values as options to dependencies, which prevents this relatively common use case from working:

const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// Optional option; if null, use some sane default
const strip = b.option(bool, "strip", "Strip debug symbols");

const dep = b.dependency("foo", .{
    .target = target,
    .optimize = optimize,
    .strip = strip, // compile error!
});

The only current workaround to this problem is to use a separate b.dependency() invocation for the null case, which is annoying (and the number of separate invocations rapidly increases the more optional options there are!).

This PR first adds a fairly comprehensive standalone test case that tests the behavior of b.dependency(). It then implements support for passing

  • null (as literals or as explicit optionals)
    • passing null is the same as not specifying the option
  • string literals
  • values coercible to []const T (including strings and string/lazy path lists)
  • enum lists
  • std.zig.BuildId

to b.dependency() and updates the test accordingly. See test/standalone/dependency_options/build.zig for a demonstration of the new types of option values these changes allow for.

Closes #21609
Closes #21928
(I only encountered these after I started working on this branch. Sorry!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant