zig icon indicating copy to clipboard operation
zig copied to clipboard

Using external library: changes are not reflected when rebuilding the Zig code

Open togglebyte opened this issue 4 years ago • 2 comments

I believe that this is a bug:

When using an external library with Zig, and the library is rebuilt or deleted, the changes are not reflected in the Zig binary when it's rebuilt.

The only way I found to see the changes was to modify the Zig code making use of the external library.

extern fn greet() void;

pub fn main() anyerror!void {
    greet(); // If greet is changed in the external library this is not
             // reflected until this code is rebuilt.
}

Workaround: just modify src/main.zig and rebuild and it works

togglebyte avatar Nov 26 '20 09:11 togglebyte

This is caused by the fact that you are using zig build with linkSystemLibrary in combination with addLibPath (Saw this on stream). To solve this you can instead use the addObjectFile API. Currently there is on caching when linking system libraries.

@andrewrk Do we want to implement caching for system libraries? Because currently when any of the system libraries changes this is not 'seen' by the caching system.

For the future: how do we make sure that people know that they can also use addObjectFile to add static libraries to a zig executable? And what should be the preferred way, because currently we have multiple ways to do the same thing (which is not what zig zen stands for)

FireFox317 avatar Nov 28 '20 14:11 FireFox317

To solve this you can instead use the addObjectFile API.

Would .addObjectFile work if he was linking against a shared object though? For many situations you don't care (or know) whether you'll be linking against a static or a dynamic library.

Do we want to implement caching for system libraries?

IMO we need to. For static libraries that probably menas the same mtime and hashing that we do for include files. For dynamic libraries me might be able to just inspect all the metadata (e.g. compare exported symbols and symbol versions)

daurnimator avatar Nov 30 '20 11:11 daurnimator