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

ability to depend on zig modules #14278

Closed
Tracked by #14265
andrewrk opened this issue Jan 12, 2023 · 2 comments · Fixed by #14538
Closed
Tracked by #14265

ability to depend on zig modules #14278

andrewrk opened this issue Jan 12, 2023 · 2 comments · Fixed by #14538
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig build system std.Build, the build runner, `zig build` subcommand, package management
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Jan 12, 2023

Extracted from #14265.

Terminology clarification: #14307

Something like this:

build.zig.zon

.{
    .name = "clap",
    .url = "...",
    .hash = "...",
}

build.zig

// "clap" here references the dependency.name field of the build.zig.zon file.
const clap_pkg = b.dependency("clap", .{});

const exe = b.addExecutable("app", "src/main.zig");

// "clap" here is the string used when calling b.addModule (see code snippet below)
const clap_module = clap_pkg.module("clap");

// "clap" here is the name used for `@import` within src/main.zig
exe.addModule("clap", clap_module);

The build.zig file for clap:

const module = b.addModule("clap", ".", "clap.zig");

const example = b.addExecutable("simple", "example/simple.zig");
example.addModule("clap", module);
example.setBuildMode(mode);
example.setTarget(target);
example.install();

See #14282 for depending on pure zig modules without executing build.zig logic.

See #14286 for running build.zig logic in a sandbox.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig build system std.Build, the build runner, `zig build` subcommand, package management labels Jan 12, 2023
@andrewrk andrewrk added this to the 0.11.0 milestone Jan 12, 2023
@andrewrk andrewrk changed the title ability to depend on zig packages ability to depend on zig modules Jan 13, 2023
@antlilja
Copy link
Contributor

How are you supposed to handle pure zig packages which in turn depend on for example system libraries? Are you supposed to create a CompilationArtifact as well as a Module and the package consumer needs to link against both, or is the Module supposed to have knowledge about its non pure zig dependencies?

const lib = b.addStaticLibrary("a", "a.zig");
lib.linkSystemLibrary("some-system-library");
lib.linkLibC();

const module = b.addModule("a", "a.zig");
const module = b.addModule("a", "a.zig");
module.linkSystemLibrary("some-system-library");
module.linkLibC();

andrewrk added a commit that referenced this issue Feb 4, 2023
New API introduced: std.Build.addModule

This function exposes a zig module with the given name, which can be
used by packages that depend on this one via std.Build.Dependency.module.

std.Build.Pkg and related functionality is deleted. Every use case has a
straightforward upgrade path using the new Module struct.

std.Build.OptionsStep.getPackage is replaced by
std.Build.OptionsStep.createModule.

std.Build.CompileStep.addPackagePath is replaced by
std.Build.CompileStep.addAnonymousModule.

This partially addresses #14307 by renaming some of the instances of
"package" to "module".

Closes #14278
andrewrk added a commit that referenced this issue Feb 4, 2023
New API introduced: std.Build.addModule

This function exposes a zig module with the given name, which can be
used by packages that depend on this one via std.Build.Dependency.module.

std.Build.Pkg and related functionality is deleted. Every use case has a
straightforward upgrade path using the new Module struct.

std.Build.OptionsStep.getPackage is replaced by
std.Build.OptionsStep.createModule.

std.Build.CompileStep.addPackagePath is replaced by
std.Build.CompileStep.addAnonymousModule.

This partially addresses #14307 by renaming some of the instances of
"package" to "module".

Closes #14278
@tisonkun
Copy link
Contributor

tisonkun commented May 5, 2023

Nice to see the evolution in package management!

FWIW - I'm caching these changes in my toy project https://github.com/korandoru/zig-uuid to demonstrate the usage for new build APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. zig build system std.Build, the build runner, `zig build` subcommand, package management
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants