Skip to content

Add option to skip linking against system libraries - #10

Merged
bytesofpie merged 9 commits into
allyourcodebase:mainfrom
RokasPuzonas:use-system-integration-option-api
Jan 15, 2026
Merged

Add option to skip linking against system libraries#10
bytesofpie merged 9 commits into
allyourcodebase:mainfrom
RokasPuzonas:use-system-integration-option-api

Conversation

@RokasPuzonas

Copy link
Copy Markdown
Contributor

Resolves#7

Here is an example for how the build.zig needs to look if you are using -fno-sys=mbedtls:

constmbedtls_dependency=b.dependency("mbedtls", .{
.target=target,
.optimize=optimize,
});
constlibssh2_dependency=b.dependency("libssh2", .{
.target=target,
.optimize=optimize,
.strip=optimize!=.Debug,
.@"crypto-backend"=.mbedtls,
});
constlibssh2_artifact=libssh2_dependency.artifact("ssh2");
// This line is very important, it's important to link mbedtls with libssh2. Not with root_module.// This is a very easy mistake to make.libssh2_artifact.linkLibrary(mbedtls_dependency.artifact("mbedtls"));
root_module.linkLibrary(libssh2_artifact);
constexe=b.addExecutable(.{
.name="resource_tracker",
.root_module=root_module
});

Comment threadREADME.md Outdated
Comment threadbuild.zig Outdated
Comment threadbuild.zig Outdated
Comment threadbuild.zig Outdated
Comment threadbuild.zig Outdated
@RokasPuzonas

Copy link
Copy Markdown
ContributorAuthor

Sorry for coming back to this after so long. After playing around with these, I changed my mind. I don't think using the system integration API in a library is a good idea.

Reasons:

  1. A user of this library can't specify if they prefer using a system library or not in build.zig (i.e. in the arguments for b.dependency). It's a CLI only option.
  2. Because it's a CLI only option, this made using the library a bit clunky, I couldn't just run zig build and it would build my application according to my preferences, I was forced to use zig build -fno-sys=mbedtls.
  3. If a library uses the system integration API, it pollutes the build options for everybody downstream that uses the library. The user won't be able to have their own "mbedtls" system integration option.

Solution: Provide an option for skipping the .linkSystemLibrary calls like .link-system-crypto-backend which would be a true/false value. Then the user of the library can decide if they want to use b.systemIntegrationOption.

This solution was inspired by the sokol-zig and how it handles integrating with imgui using the .with_sokol_imgui where you need to "Bring your own cimgui".

@RokasPuzonasRokasPuzonas changed the title Use system integration options APIAdd option to skip linking against system librariesJan 10, 2026

@bytesofpiebytesofpie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Agreed this seems like a better approach!

@bytesofpie
bytesofpie merged commit 65a7697 into allyourcodebase:mainJan 15, 2026
4 checks passed
Sign up for freeto 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.

Allow not linking against crypto system libraries

2 participants

@RokasPuzonas@bytesofpie