Skip to content

add @tryImport #8033

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
wants to merge 1 commit into from
Closed

add @tryImport #8033

wants to merge 1 commit into from

Conversation

marler8997
Copy link
Contributor

@marler8997 marler8997 commented Feb 18, 2021

Alternative to #8072 (provide buildpkgs module to build.zig)

An implementation for the proposed @tryImport builtin: #8025

@Rocknest
Copy link
Contributor

Rocknest commented Feb 18, 2021

It think you are trying to solve a problem that is going to be solved by a package manager (someday). If this is supposed to be a temporary solution then why not just @hasPackage([]const u8) bool?

@marler8997
Copy link
Contributor Author

marler8997 commented Feb 18, 2021

It think you are trying to solve a problem that is going to be solved by a package manager (someday).

The "build.zig bootstrap problem" which I describe here (#8025 (comment)) is a fundamental problem with build.zig regardless of whether a package manager exists. A package manager may implement one of the solutions I described in the linked issue above, however, they all require other tools/configuration to resolve dependencies needed by build.zig. This causes build.zig to rely on other components to bootstrap it. This means that any component wanting to use build.zig also needs to know about any extra tools/files required to bootstrap it. This cannibalizes build.zig such that build configuration is now contained in multiple places, each with its own environment/configuration. @tryImport enables build.zig to bootstrap itself, with unrestricted access to the Zig language for any logic required to resolve dependencies and can also leverage results gained from runtime execution (it is not limited to comptime). This is not an alternative to a package manager, it's an orthogonal solution to a problem that would work in concert with a package manager.

If this is supposed to be a temporary solution then why not just @hasPackage([]const u8) bool?

This is permanent solution to a fundamental problem. Using @hasPackage limits the feature to only working with package imports, but the "build.d bootstrap problem" applies to both package and file imports. Another variation I considered was @hasImport. It is functionally equivalent to @tryImport, both can be used to implement the other, so the question becomes which is more common. @tryImport wins if it's more common to perform an import when checking for its existence. I think this is the case.

@Vexu Vexu added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Feb 21, 2021
An implementation for the proposed @tryImport builtin: ziglang#8025
@Vexu
Copy link
Member

Vexu commented Jun 10, 2021

I'll close this pr for now since we want to reserve the pull request queue for prs that are ready to be merged. I'll add a reminder to the issue about this implementation.

@Vexu Vexu closed this Jun 10, 2021
@Vexu Vexu mentioned this pull request Jun 10, 2021
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

Successfully merging this pull request may close these issues.

3 participants