Compile OpenWrt on Apple Silicon M1

I see that work was put in place in the master branch to compile on Apple Silicon, but there appears to be an issue today, at least.

make download attempts to run clean-build on qosify and fails. Anything I'm doing wrong?

Further note: The following error occurs when building gcc now:

gmake[2]: Entering directory '/Volumes/OpenWrt/openwrt/scripts/config'
gmake[2]: 'conf' is up to date.
gmake[2]: Leaving directory '/Volumes/OpenWrt/openwrt/scripts/config'
gmake[1]: Entering directory '/Volumes/OpenWrt/openwrt'
cd "/Volumes/OpenWrt/openwrt"; git log --format=%h -1 toolchain > /Volumes/OpenWrt/openwrt/tmp/.ver_check
cmp -s /Volumes/OpenWrt/openwrt/tmp/.ver_check /Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp/.ver_check || { \
	rm -rf /Volumes/OpenWrt/openwrt/build_dir/target-mips_24kc_musl /Volumes/OpenWrt/openwrt/staging_dir/target-mips_24kc_musl /Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl /Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl; \
	mkdir -p /Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp; \
	mv /Volumes/OpenWrt/openwrt/tmp/.ver_check /Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp/.ver_check; \
}
/Volumes/OpenWrt/openwrt/scripts/check-toolchain-clean.sh
gmake[2]: Entering directory '/Volumes/OpenWrt/openwrt'
cd "/Volumes/OpenWrt/openwrt"; git log --format=%h -1 toolchain > /Volumes/OpenWrt/openwrt/tmp/.ver_check
cmp -s /Volumes/OpenWrt/openwrt/tmp/.ver_check /Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp/.ver_check || { \
	rm -rf /Volumes/OpenWrt/openwrt/build_dir/target-mips_24kc_musl /Volumes/OpenWrt/openwrt/staging_dir/target-mips_24kc_musl /Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl /Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl; \
	mkdir -p /Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp; \
	mv /Volumes/OpenWrt/openwrt/tmp/.ver_check /Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp/.ver_check; \
}
+ mkdir -p /Volumes/OpenWrt/openwrt/staging_dir/target-mips_24kc_musl
+ cd /Volumes/OpenWrt/openwrt/staging_dir/target-mips_24kc_musl
+ mkdir -p bin lib stamp usr/include usr/lib
mkdir -p /Volumes/OpenWrt/openwrt/build_dir/target-mips_24kc_musl/stamp
touch /Volumes/OpenWrt/openwrt/staging_dir/target-mips_24kc_musl/.prepared
gmake[3]: Entering directory '/Volumes/OpenWrt/openwrt/toolchain/gdb'
gmake[3]: Nothing to be done for 'compile'.
gmake[3]: Leaving directory '/Volumes/OpenWrt/openwrt/toolchain/gdb'
time: toolchain/gdb/compile#0.00#0.00#0.01
gmake[3]: Entering directory '/Volumes/OpenWrt/openwrt/toolchain/binutils'
gmake[3]: Nothing to be done for 'compile'.
gmake[3]: Leaving directory '/Volumes/OpenWrt/openwrt/toolchain/binutils'
time: toolchain/binutils/compile#0.00#0.00#0.01
gmake[3]: Entering directory '/Volumes/OpenWrt/openwrt/toolchain/gcc/initial'
export SHELL="bash"; gmake CFLAGS="-O2 -I/Volumes/OpenWrt/openwrt/staging_dir/host/include " CFLAGS_FOR_TARGET="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" CXXFLAGS_FOR_TARGET="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" GOCFLAGS_FOR_TARGET="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro"  -C /Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial all-build-libiberty all-gcc all-target-libgcc
gmake[4]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/build-aarch64-apple-darwin21.4.0/libiberty'
gmake[6]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/build-aarch64-apple-darwin21.4.0/libiberty/testsuite'
gmake[6]: Nothing to be done for 'all'.
gmake[6]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/build-aarch64-apple-darwin21.4.0/libiberty/testsuite'
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/build-aarch64-apple-darwin21.4.0/libiberty'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libiberty'
gmake[6]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libiberty/testsuite'
gmake[6]: Nothing to be done for 'all'.
gmake[6]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libiberty/testsuite'
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libiberty'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/lto-plugin'
gmake  all-am
gmake[6]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/lto-plugin'
gmake[6]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/lto-plugin'
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/lto-plugin'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/intl'
gmake[5]: Nothing to be done for 'all'.
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/intl'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/build-aarch64-apple-darwin21.4.0/fixincludes'
gmake[5]: Nothing to be done for 'all'.
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/build-aarch64-apple-darwin21.4.0/fixincludes'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/build-aarch64-apple-darwin21.4.0/libcpp'
test -f config.h || (rm -f stamp-h1 && gmake stamp-h1)
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/build-aarch64-apple-darwin21.4.0/libcpp'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/zlib'
true "AR_FLAGS=rc" "CC_FOR_BUILD=gcc" "CFLAGS=-O2 -I/Volumes/OpenWrt/openwrt/staging_dir/host/include " "CXXFLAGS=-O2 -fbracket-depth=512 -pipe" "CFLAGS_FOR_BUILD=-O2 -fbracket-depth=512 -pipe" "CFLAGS_FOR_TARGET=-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" "INSTALL=/Volumes/OpenWrt/openwrt/staging_dir/host/bin/install -c" "INSTALL_DATA=/Volumes/OpenWrt/openwrt/staging_dir/host/bin/install -c -m 644" "INSTALL_PROGRAM=/Volumes/OpenWrt/openwrt/staging_dir/host/bin/install -c" "INSTALL_SCRIPT=/Volumes/OpenWrt/openwrt/staging_dir/host/bin/install -c" "LDFLAGS=" "LIBCFLAGS=-O2 -I/Volumes/OpenWrt/openwrt/staging_dir/host/include " "LIBCFLAGS_FOR_TARGET=-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" "MAKE=gmake" "MAKEINFO=/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0/missing makeinfo --split-size=5000000 " "PICFLAG=" "PICFLAG_FOR_TARGET=" "SHELL=/bin/sh" "EXPECT=expect" "RUNTEST=runtest" "RUNTESTFLAGS=" "exec_prefix=/Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl" "infodir=/Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/share/info" "libdir=/Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/lib" "prefix=/Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl" "tooldir=/Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/mips-openwrt-linux-musl" "AR=ar" "AS=as" "CC=gcc" "CXX=g++ -std=gnu++11" "LD=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" "LIBCFLAGS=-O2 -I/Volumes/OpenWrt/openwrt/staging_dir/host/include " "NM=nm" "PICFLAG=" "RANLIB=ranlib" "DESTDIR=" DO=all multi-do # gmake
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/zlib'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libbacktrace'
gmake  all-am
gmake[6]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libbacktrace'
true  DO=all multi-do # gmake
gmake[6]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libbacktrace'
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libbacktrace'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libcpp'
test -f config.h || (rm -f stamp-h1 && gmake stamp-h1)
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libcpp'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libcody'
gmake[5]: Nothing to be done for 'all'.
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libcody'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libdecnumber'
gmake[5]: Nothing to be done for 'all'.
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/libdecnumber'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/fixincludes'
gmake[5]: Nothing to be done for 'all'.
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/fixincludes'
gmake[5]: Entering directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/gcc'
g++ -std=gnu++11 -no-pie   -O2 -fbracket-depth=512 -pipe -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -fno-strict-aliasing -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-error=format-diag -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H  -o cc1 c/c-lang.o c-family/stub-objc.o attribs.o c/c-errors.o c/c-decl.o c/c-typeck.o c/c-convert.o c/c-aux-info.o c/c-objc-common.o c/c-parser.o c/c-fold.o c/gimple-parser.o c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o c-family/c-format.o c-family/c-gimplify.o c-family/c-indentation.o c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o c-family/c-semantics.o c-family/c-ada-spec.o c-family/c-ubsan.o c-family/known-headers.o c-family/c-attribs.o c-family/c-warn.o c-family/c-spellcheck.o glibc-c.o \
  cc1-checksum.o libbackend.a main.o libcommon-target.a libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a libcommon.a ../libcpp/libcpp.a  -liconv ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a   -L/Volumes/OpenWrt/openwrt/staging_dir/host/lib -L/Volumes/OpenWrt/openwrt/staging_dir/host/lib -L/Volumes/OpenWrt/openwrt/staging_dir/host/lib -lmpc -lmpfr -lgmp   -L./../zlib -lz 
clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument]
Undefined symbols for architecture arm64:
  "_ZSTD_compress", referenced from:
      lto_end_compression(lto_compression_stream*) in libbackend.a(lto-compress.o)
  "_ZSTD_compressBound", referenced from:
      lto_end_compression(lto_compression_stream*) in libbackend.a(lto-compress.o)
  "_ZSTD_decompress", referenced from:
      lto_end_uncompression(lto_compression_stream*, lto_compression) in libbackend.a(lto-compress.o)
  "_ZSTD_getErrorName", referenced from:
      lto_end_compression(lto_compression_stream*) in libbackend.a(lto-compress.o)
      lto_end_uncompression(lto_compression_stream*, lto_compression) in libbackend.a(lto-compress.o)
  "_ZSTD_getFrameContentSize", referenced from:
      lto_end_uncompression(lto_compression_stream*, lto_compression) in libbackend.a(lto-compress.o)
  "_ZSTD_isError", referenced from:
      lto_end_compression(lto_compression_stream*) in libbackend.a(lto-compress.o)
      lto_end_uncompression(lto_compression_stream*, lto_compression) in libbackend.a(lto-compress.o)
  "_ZSTD_maxCLevel", referenced from:
      lto_end_compression(lto_compression_stream*) in libbackend.a(lto-compress.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[5]: *** [/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0/gcc/c/Make-lang.in:87: cc1] Error 1
gmake[5]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/gcc'
gmake[4]: *** [Makefile:4445: all-gcc] Error 2
gmake[4]: Leaving directory '/Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial'
gmake[3]: *** [Makefile:37: /Volumes/OpenWrt/openwrt/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl/gcc-11.2.0-initial/.built] Error 2
gmake[3]: Leaving directory '/Volumes/OpenWrt/openwrt/toolchain/gcc/initial'
time: toolchain/gcc/initial/compile#0.70#0.32#1.10
    ERROR: toolchain/gcc/initial failed to build.
gmake[2]: *** [toolchain/Makefile:97: toolchain/gcc/initial/compile] Error 1
gmake[2]: Leaving directory '/Volumes/OpenWrt/openwrt'
gmake[1]: *** [toolchain/Makefile:93: /Volumes/OpenWrt/openwrt/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp/.toolchain_compile] Error 2
gmake[1]: Leaving directory '/Volumes/OpenWrt/openwrt'
gmake: *** [/Volumes/OpenWrt/openwrt/include/toplevel.mk:230: world] Error 2

I'll add some random notes:

gcc really likes a shared libzstd library. It does not like libzstd.a. Doesn't compile if the shared library is missing. Currently tools/zstd doesn't specify what library type to build. -Ddefault_library=both can be passed for static and shared.

avoiding shared libraries is nice as it avoids having to add rpath hacks in various packages. Especially with host packages where the static/shared distinction doesn't mean much.

Although I also remember macOS really liking shared libraries as well. Maybe I remember wrong.

The link command line above isn't even passing -lzstd, though.

right. a bug with gcc.

I think you can pass --without-zstd to gcc.