nodemcu / nodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32
https://nodemcu.readthedocs.io
MIT License
7.65k stars 3.12k forks source link

ziglang build broken on macOS #3575

Open tomsci opened 1 year ago

tomsci commented 1 year ago

Trying to build dev-esp32 branch @ 32d03a21da4fdfddf153d118e2e32a064d6d0003 on macOS 13.3.1 on Apple Silicon appears to be hitting a bug in ziglang while compiling luac.cross (output trimmed to only include relevant stuff):

$ make
/nodemcu-firmware/sdk/esp32-esp-idf/tools/idf.py  "all"
Executing action: all (aliases: build)
Running make in directory /nodemcu-firmware/build
Executing "make -j 12 all"...
-- Building ESP-IDF components for target esp32
-- Project sdkconfig file /nodemcu-firmware/sdkconfig
Loading defaults file /nodemcu-firmware/sdkconfig.defaults...
-- App "nodemcu" version: 1.4.0-master_20151229-880-g4e9b
[  1%] Performing build step for 'luac_cross_build'
[hostcc] luac.o
<snip>
[hostcc] lundump.o
MachO Flush... [hostcc] lutf8lib.o
[hostcc] lvm.o
MachO Flush... [hostcc] lzio.o
[hostcc] linit.o
[hostcc] lpanic.o
MachO Flush... MachO Flush... [hostcc] uzlib_deflate.o
[hostcc] crc32.o
[ link] luac.cross
MachO Flush... error(link): undefined reference to symbol 'dyld_stub_binder'
error: UndefinedSymbolReference
make[4]: *** [/nodemcu-firmware/build/luac_cross/luac.cross] Error 1
make[3]: *** [luac_cross/src/luac_cross_build-stamp/luac_cross_build-build] Error 2
make[2]: *** [esp-idf/lua/CMakeFiles/luac_cross_build.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....

This appears to be the same issue as https://github.com/ziglang/zig/issues/11896 which has been open for a while and maaaaybe will be fixed in the next version 0.11 (it's on their milestones but not yet fixed, so who knows if it gets pushed out or not).

Looking at how zig is used here, it seems to be a wrapper around clang? At least for me, this patch to just not use it at all fixed the issue:

diff --git a/components/lua/lua-5.3/host/idf.mk b/components/lua/lua-5.3/host/idf.mk
index 8dfba397..b1ccfe94 100644
--- a/components/lua/lua-5.3/host/idf.mk
+++ b/components/lua/lua-5.3/host/idf.mk
@@ -1,6 +1,6 @@
 all: build

-HOSTCC?=$(PYTHON) -m ziglang cc
+HOSTCC?=cc

 ifeq ($V,)
   Q:=@

I found this comment referencing zig https://github.com/nodemcu/nodemcu-firmware/issues/1661#issuecomment-878903150 so I guess it's here for the cases where you don't have a host C compiler? Maybe we can make it configurable for the cases where hostcc is available and works, but zig doesn't? Just a thought, for now I've just added the above patch to my branch, but I figured I should raise this if only for other people hitting the same issue to search for!