nuttx/tools/Zig.defs
Ansh Rai 522ae4cb3f tools/Zig.defs: Fix Zig builds on sim:x86_64
Building Zig applications on sim:x86_64 with Zig 0.13.0 fails because
the generated target "x86_64-freestanding-sysv" is not recognized by
Zig. Introduce a Zig-specific ABI mapping that translates "sysv" to
"gnu" without affecting other toolchains.

After correcting the target ABI, linking still fails due to unresolved
references to __zig_probe_stack. Add -fcompiler-rt so Zig includes the
required compiler runtime during linking.

Verified on sim:nsh with CONFIG_EXAMPLES_HELLO_ZIG=y:

  nsh> hello_zig
  [sim]: Hello, Zig!

Fixes #19475

Signed-off-by: Ansh Rai <anshrai331@gmail.com>
2026-07-20 09:36:56 +08:00

54 lines
1.6 KiB
Text

############################################################################
# tools/Zig.defs
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ZIG := zig
ifeq ($(CONFIG_ARCH_ARM),y)
ifeq ($(CONFIG_ARM_THUMB),y)
ZIGFLAGS := -target thumb-freestanding-$(LLVM_ABITYPE)
else
ZIGFLAGS := -target arm-freestanding-$(LLVM_ABITYPE)
endif
else ifeq ($(CONFIG_ARCH_RISCV),y)
ZIGFLAGS := -target $(LLVM_ARCHTYPE)-freestanding-none
ZIGFLAGS += -mcmodel=medium
else
ifeq ($(LLVM_ABITYPE),sysv)
ZIG_ABITYPE := gnu
else
ZIG_ABITYPE := $(LLVM_ABITYPE)
endif
ZIGFLAGS := -target $(LLVM_ARCHTYPE)-freestanding-$(ZIG_ABITYPE)
endif
# Convert cortex-xxx/sifive-exx to cortex_xxx/sifive_exx
ifneq ($(LLVM_CPUTYPE),)
ZIGFLAGS += -mcpu $(subst -,_,$(LLVM_CPUTYPE))
endif
ZIGFLAGS += -fcompiler-rt