#Package manager: How to communicate CrossTarget (and SysRoot) to dependencies?

1 messages · Page 1 of 1 (latest)

quasi cosmos
#

In the new package manager, how can I communicate the cross-target (e.g. zig build -Dtarget=wasm32-freestanding to a dependency?

When I call zig build with a cross-compilation target like this, calling b.standardTargetOptions(.{}) in the build() function of the dependency returns a target where cpu_arch and os_tag are both null, instead of .wasm32 and .freestanding.

(which then causes the dependency to build a native library, instead of a wasm32 library)

#

...ah ok, to partly answer myself... it looks like I can setup the dependency like this and add those options to this mysterious 'anytype' parameter:

    const dep_sokol = b.dependency("sokol", .{
        .target = target,
        .optimize = optimize,
    });

...still having trouble getting the sysroot over, since this args: anytype argument doesn't seem to support (optional) strings

I wonder why those standard build options are not tranferred automatically?

quasi cosmos
#

hmm ok, new question:

How to communicate the sysroot.

Doing this:

return b.dependency("sokol", .{
    .target = target,
    .optimize = optimize,
    .sysroot = abs_sysroot,
});

...just seems to try passing it as a -Dsysroot option, but for a command line it would need to be --sysroot

#

...alternatively, if I want to call a function in the dependency's build.zig which sets up the C library build, I'd need a way to get the path to the downloaded dependency directory... hmm...

#

...which I can obtain with Dependency.builder.build_root.path... I think I'm getting somewhere...

quasi cosmos
#

...ok everything fixed, supporting C libraries with the package manager still feels quite awkward IMHO, but maybe I missed some things