linkers: basic support for the 'zig cc' linker

pull/13712/head
Andrei Alexeyev 1 year ago committed by Dylan Baker
parent 6797f9bc15
commit 798bf51903
  1. 1
      docs/markdown/Reference-tables.md
  2. 18
      docs/markdown/snippets/zig_ld.md
  3. 3
      mesonbuild/linkers/detect.py
  4. 7
      mesonbuild/linkers/linkers.py

@ -62,6 +62,7 @@ These are return values of the `get_linker_id` method in a compiler object.
| ld.mold | The fast MOLD linker |
| ld.solaris | Solaris and illumos |
| ld.wasm | emscripten's wasm-ld linker |
| ld.zigcc | The Zig linker (C/C++ frontend; GNU-like) |
| ld64 | Apple ld64 |
| ld64.lld | The LLVM linker, with the ld64 interface |
| link | MSVC linker |

@ -0,0 +1,18 @@
## Zig 0.11 can be used as a C/C++ compiler frontend
Zig offers
[a C/C++ frontend](https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html) as a drop-in replacement for Clang. It worked fine with Meson up to Zig 0.10. Since 0.11, Zig's
dynamic linker reports itself as `zig ld`, which wasn't known to Meson. Meson now correctly handles
Zig's linker.
You can use Zig's frontend via a [machine file](Machine-files.md):
```ini
[binaries]
c = ['zig', 'cc']
cpp = ['zig', 'c++']
ar = ['zig', 'ar']
ranlib = ['zig', 'ranlib']
lib = ['zig', 'lib']
dlltool = ['zig', 'dlltool']
```

@ -236,6 +236,9 @@ def guess_nix_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty
linker = linkers.AIXDynamicLinker(
compiler, for_machine, comp_class.LINKER_PREFIX, override,
version=search_version(e))
elif o.startswith('zig ld'):
linker = linkers.ZigCCDynamicLinker(
compiler, for_machine, comp_class.LINKER_PREFIX, override, version=v)
else:
__failed_to_detect_linker(compiler, check_args, o, e)
return linker

@ -938,6 +938,13 @@ class LLVMDynamicLinker(GnuLikeDynamicLinkerMixin, PosixDynamicLinkerMixin, Dyna
raise mesonlib.MesonBugException(f'win_subsystem: {value} not handled in lld linker. This should not be possible.')
class ZigCCDynamicLinker(LLVMDynamicLinker):
id = 'ld.zigcc'
def get_thinlto_cache_args(self, path: str) -> T.List[str]:
return []
class WASMDynamicLinker(GnuLikeDynamicLinkerMixin, PosixDynamicLinkerMixin, DynamicLinker):
"""Emscripten's wasm-ld."""

Loading…
Cancel
Save