Skip to content

zig build mixes non-system headers with system libraries #10957

@carlocab

Description

@carlocab

Zig Version

0.9.0

Steps to Reproduce

First, try to build fastfec 0.0.4 with only zig build -Dvendored-pcre=false:

curl -L https://github.com/washingtonpost/FastFEC/archive/refs/tags/0.0.4.tar.gz | tar -x
cd FastFEC-0.0.4
zig build -Dvendored-pcre=false

if you don't have pcre installed, this will fail with the following error:

error(compilation): clang failed with stderr: In file included from /private/var/folders/kb/pf4wbfc512z47l56g5072l900000gn/T/tmp.I7m44QsSX4/FastFEC-0.0.4/src/writer.c:1:
/private/var/folders/kb/pf4wbfc512z47l56g5072l900000gn/T/tmp.I7m44QsSX4/FastFEC-0.0.4/src/memory.h:5:10: fatal error: 'pcre.h' file not found

Now, do the same after installing pcre and pkg-config (e.g. brew install pcre pkg-config). Compilation succeeds, but fastfec links with /usr/lib/libpcre.dylib:

❯ otool -L zig-out/*/*fastfec*
zig-out/bin/fastfec:
        /usr/lib/libcurl.4.dylib (compatibility version 7.0.0, current version 9.0.0)
        /usr/lib/libpcre.0.dylib (compatibility version 1.0.0, current version 1.10.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
zig-out/lib/libfastfec.dylib:
        @rpath/libfastfec.dylib (compatibility version 1.0.0, current version 1.0.0)
        /usr/lib/libpcre.0.dylib (compatibility version 1.0.0, current version 1.10.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)

The macOS SDK does not provide headers for PCRE, which means that zig used the headers from Homebrew except linked with the system libpcre.

Expected Behavior

I expected my build to link with Homebrew pcre. This was the behaviour under Zig 0.8.1:

❯ brew install fastfec
[snip]
❯ brew linkage fastfec
System libraries:
  /usr/lib/libSystem.B.dylib
  /usr/lib/libcurl.4.dylib
Homebrew libraries:
  /usr/local/opt/pcre/lib/libpcre.1.dylib (pcre)
❯ otool -L $(brew --prefix fastfec)/*/*fastfec*
/usr/local/opt/fastfec/bin/fastfec:
        /usr/lib/libcurl.4.dylib (compatibility version 7.0.0, current version 9.0.0)
        /usr/local/opt/pcre/lib/libpcre.1.dylib (compatibility version 4.0.0, current version 4.13.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)
/usr/local/opt/fastfec/lib/libfastfec.dylib:
        /usr/local/opt/fastfec/lib/libfastfec.dylib (compatibility version 0.0.0, current version 0.0.0)
        /usr/local/opt/pcre/lib/libpcre.1.dylib (compatibility version 4.0.0, current version 4.13.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)

Actual Behavior

Linkage with macOS libpcre.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavioros-macosmacOS

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions