Skip to content

std.Build.Module should include APIs from CompileStep #14719

@hryx

Description

@hryx

Currently it is not possible for an upstream package foo to add C header include paths to a Module it has defined — it's only possible to do this on CompileSteps. The effect of this is that if the package defines a module using @cImport(), a depending project bar that uses this module will fail to build because the headers aren't in its search path.

For now, the workaround in the dependee's build.zig is to call exe.addIncludePath(X) where X is the path to the globally cached package, e.g. ~/.cache/zig/p/hash-of-package/include.

It should be possible for bar to depend on foo without adding this include path. If bar does not call @cImport() directly itself, it should also not have to call exe.addIncludePath at all.

The suggested approach in today's meeting was to expand the API of Module to have (some of? *) the same APIs as CompileStep. This would allow the upstream foo to call mod.installHeadersDirectory() in build.zig, and then bar can use the foo module and find its headers.

*Note: I'm not sure which APIs should be copied from CompileStep. All of them? Just ones related to installing headers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.zig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions