#Different optimize mode for dependency does not work

1 messages · Page 1 of 1 (latest)

hollow cave
#

I have zigimg as a dependency in my build.zig file:


pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const zigimg = b.dependency("zigimg", .{
        .optimize = std.builtin.OptimizeMode.ReleaseFast,
    }).module("zigimg");

    // ...

    exe_mod.addImport("zigimg", zigimg);

    // ...
}

but without optimization encoding a png image takes forever, like 30+ seconds, so I want to always build zigimg in ReleaseFast mode.
I thought this is how to do it but its not working, it still takes that long. But supplying --release=fast to build everything in ReleaseFast mode works.

proper zephyr
#

Only the root modules optimisation mode applies.
this is because zig builds in a single compilation unit, you can split it into multiple but then you would have to make a c abi wrapper.

hollow cave
#

If that is the case why is the optimize mode always passed into the dependency?

proper zephyr
#

because it can do more than just export modules

hollow cave
#

what? i mean why can i specify the optimization level in the second argument for Build.dependency if it doesnt matter and only the optimization of the root module is applied?

#

is it just ignored?

#

surely not

proper zephyr
#

because the dependency used b.standardOptimizeOption which adds the optimize build flag.
it is not ignored, it is given to the zigimg module, it just gets overriden by your modules optimise mode.

they likely only used it because 1) its just standard boilerplate they are used to 2) they also probably want to configure the optimise mode when running their tests

hollow cave
#

is there no sort of optimization at module level which i can do or turn on to make it go faster? its unbelievably slow, but in release mode its basically instant

maiden badge
#

maybe try .use_llvm = true on the addExecutable if you are on linux

hollow cave
#

Oh nice, that actually makes it quite a bit faster, not as fast as release but i can work with that