Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.Build: add search prefix "exact" variant #22552

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

BratishkaErik
Copy link
Contributor

@BratishkaErik BratishkaErik commented Jan 20, 2025

This allows more granurality when adding search pathes for cross-compiling. By default old (all variant) system added bin, include and lib subdirectories from search-prefix argument path when cross-compiling, but on some distros it's not correct and can lead to some errors.

For example, on my Gentoo system I have libcurl installed as both 32-bit and 64-bit versions, which are located in /usr/lib and /usr/lib64 directories respectively. If I use plain --search-prefix, it fails because it tries to add 32-bit libraries:

$ zig build -Dtarget=x86_64-linux-gnu.2.35 --search-prefix /usr/
install
└─ install true_or_false
   └─ zig build-exe true_or_false Debug x86_64-linux.6.11.7-gnu.2.40 3 errors
error: ld.lld: /usr/lib/libcurl.so is incompatible with elf_x86_64
error: ld.lld: /usr/lib/libssl.so is incompatible with elf_x86_64
error: ld.lld: /usr/lib/libcrypto.so is incompatible with elf_x86_64

Another example is libgccjit library, which shared objects are located (at least on my system) in /usr/lib/gcc/x86_64-pc-linux-gnu/14/, and include files in include subdir there. One solution I used recently was to create temporary directory and symlink files so that they have names expected by Zig, but it's not the best solution.

With this PR you can now supply file which will instruct build system to add pathes written there as-is, without trying to guess subdirs there. Something like:

.{
    .libraries = "/usr/lib64",
}

or

.{
    .binaries = "/usr/x86_64-pc-linux-gnu/gcc-bin/14/",
    .libraries = "/usr/lib/gcc/x86_64-pc-linux-gnu/14",
    .includes = "/usr/lib/gcc/x86_64-pc-linux-gnu/14/include/",
}

can be saved in some file like paths.zon and then passed using --search-prefix-exact paths.zon. This also helps to use this config on a system (distro) level, without messing with build.zig.

@BratishkaErik
Copy link
Contributor Author

aarch64-linux-debug failure seems to be a regular error.BrokenPipe, not sure what causes x86_64-windows-release failure, it might be related but then why only 1 test and why debug worked fine

…nd option

This allows more granurality when adding search pathes for cross-compiling.
By default old (all variant) system added `bin`, `include` and `lib`
subdirectories from `search-prefix` argument path when cross-compiling,
but on some distros it's not correct and can lead to some errors.

For example, on my Gentoo system I have libcurl installed as both
32-bit and 64-bit versions, which are located in `/usr/lib` and `/usr/lib64`
 directories respectively. If I use plain `--search-prefix`, it fails
because it tries to add 32-bit libraries:
```console
$ zig build -Dtarget=x86_64-linux-gnu.2.35 --search-prefix /usr/
install
└─ install true_or_false
   └─ zig build-exe true_or_false Debug x86_64-linux.6.11.7-gnu.2.40 3 errors
error: ld.lld: /usr/lib/libcurl.so is incompatible with elf_x86_64
error: ld.lld: /usr/lib/libssl.so is incompatible with elf_x86_64
error: ld.lld: /usr/lib/libcrypto.so is incompatible with elf_x86_64
```

Another example is `libgccjit` library, which shared objects are located
(at least on my system) in `/usr/lib/gcc/x86_64-pc-linux-gnu/14/`, and
include files in include subdir there. One solution I used recently
was to create temporary directory and symlink files so that they have
names expected by Zig, but it's not the best solution.

With this PR you can now supply file which will instruct build system
to add pathes written there as-is, without trying to guess subdirs there.
Something like:
```zig
.{
    .libraries = "/usr/lib64",
}
```
or
```zig
.{
    .binaries = "/usr/x86_64-pc-linux-gnu/gcc-bin/14/",
    .libraries = "/usr/lib/gcc/x86_64-pc-linux-gnu/14",
    .includes = "/usr/lib/gcc/x86_64-pc-linux-gnu/14/include/",
}
```

can be saved in some file like paths.zon and then passed using
`--search-prefix-exact paths.zon`. This also helps to use this config
on a system (distro) level, without messing with build.zig.

Signed-off-by: Eric Joldasov <[email protected]>
@alexrp alexrp force-pushed the search-prefix-exact branch from d759b1e to 836795d Compare January 30, 2025 12:30
@alexrp alexrp added this to the 0.14.0 milestone Jan 30, 2025
Sign up for free to 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.

2 participants