osx-cross / homebrew-avr

Homebrew AVR Toolchain
BSD 2-Clause "Simplified" License
398 stars 81 forks source link

Add avr-gcc 12.2 #286

Closed salkinium closed 1 year ago

salkinium commented 1 year ago

I've updated the versions and shasums, but I cannot build this correctly on my M2 mac yet. But the CI should test x86 already for me.

Current error is cryptic

salkinium commented 1 year ago

The error is clang: error: unknown argument: '-nodefaultrpaths', it's unclear to me where that comes from.

checking for avr-gcc... /private/tmp/avr-gccA12-20221228-86351-1grrp5m/gcc-12.2.0/build/./gcc/xgcc -B/private/tmp/avr-gccA12-20221228-86351-1grrp5m/gcc-12.2.0/build/./gcc/ -B/opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/bin/ -B/opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/lib/ -isystem /opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/include -isystem /opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/sys-include   
libtool: link: sed -e 's,^,_,' < ../../libcc1/libcc1.sym > .libs/libcc1-symbols.expsym
libtool: link: clang++ -std=gnu++11  -o .libs/libcc1.0.so -bundle  .libs/findcomp.o .libs/libcc1.o .libs/libcp1.o .libs/compiler.o .libs/names.o .libs/callbacks.o .libs/connection.o .libs/marshall.o    -Wl,-undefined -Wl,dynamic_lookup -nodefaultrpaths -Wl,-rpath -Wl,@loader_path ../libiberty/pic/libiberty.a   -Wl,-exported_symbols_list,.libs/libcc1-symbols.expsym
checking for suffix of object files... clang: error: unknown argument: '-nodefaultrpaths'
make[3]: *** [libcc1.la] Error 1
make[3]: *** Waiting for unfinished jobs....
mv -f .deps/context.Tpo .deps/context.Plo
o
checking whether we are using the GNU C compiler... yes
checking whether /private/tmp/avr-gccA12-20221228-86351-1grrp5m/gcc-12.2.0/build/./gcc/xgcc -B/private/tmp/avr-gccA12-20221228-86351-1grrp5m/gcc-12.2.0/build/./gcc/ -B/opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/bin/ -B/opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/lib/ -isystem /opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/include -isystem /opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/sys-include    accepts -g... yes
checking for /private/tmp/avr-gccA12-20221228-86351-1grrp5m/gcc-12.2.0/build/./gcc/xgcc -B/private/tmp/avr-gccA12-20221228-86351-1grrp5m/gcc-12.2.0/build/./gcc/ -B/opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/bin/ -B/opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/lib/ -isystem /opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/include -isystem /opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/sys-include    option to accept ISO C89... unsupported
checking how to run the C preprocessor... /private/tmp/avr-gccA12-20221228-86351-1grrp5m/gcc-12.2.0/build/./gcc/xgcc -B/private/tmp/avr-gccA12-20221228-86351-1grrp5m/gcc-12.2.0/build/./gcc/ -B/opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/bin/ -B/opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/lib/ -isystem /opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/include -isystem /opt/homebrew/Cellar/avr-gcc@12/12.2.0/avr/sys-include    -E
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... mv -f .deps/libcc1plugin.Tpo .deps/libcc1plugin.Plo
unknown
checking for _LARGE_FILES value needed for large files... unknown
checking size of double... 4
checking size of long double... 8
checking for inttypes.h... no
checking for stdint.h... no
checking for stdlib.h... no
checking for ftw.h... no
checking for unistd.h... no
checking for sys/stat.h... mv -f .deps/libcp1plugin.Tpo .deps/libcp1plugin.Plo
make[2]: *** [all] Error 2
make[1]: *** [all-libcc1] Error 2
make[1]: *** Waiting for unfinished jobs....

Configuration:

HOMEBREW_VERSION: 3.6.16
ORIGIN: https://github.com/Homebrew/brew
HEAD: 740f9ddcc620d4812770a0f12854ddd79c643874
Last commit: 8 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 641c85ef2ce9167ac84cea92f6e8f0092f683f9e
Core tap last commit: 59 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
HOMEBREW_NO_BOOTSNAP: set
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_blizzard_avalanche
Clang: 14.0.0 build 1400
Git: 2.37.1 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.84.0 => /usr/bin/curl
macOS: 13.0-arm64
CLT: 14.2.0.0.1.1668646533
Xcode: N/A
Rosetta 2: false

HOMEBREW_CC: clang
HOMEBREW_CXX: clang++
MAKEFLAGS: -j8
CMAKE_PREFIX_PATH: /opt/homebrew
CMAKE_INCLUDE_PATH: /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers
CMAKE_LIBRARY_PATH: /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries
PKG_CONFIG_PATH: /opt/homebrew/opt/gmp/lib/pkgconfig:/opt/homebrew/opt/isl/lib/pkgconfig:/opt/homebrew/opt/mpfr/lib/pkgconfig
PKG_CONFIG_LIBDIR: /usr/lib/pkgconfig:/opt/homebrew/Library/Homebrew/os/mac/pkgconfig/13
HOMEBREW_GIT: git
HOMEBREW_SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk
ACLOCAL_PATH: /opt/homebrew/share/aclocal
PATH: /opt/homebrew/Library/Homebrew/shims/mac/super:/opt/homebrew/opt/autoconf/bin:/opt/homebrew/opt/automake/bin:/opt/homebrew/opt/avr-binutils/bin:/usr/bin:/bin:/usr/sbin:/sbin

cc @ladislas

salkinium commented 1 year ago

I also cannot build avr-gcc@11 on macOS 13 with CLT 14.2. The internet suggests a downgrade to CLT 13.4, but the OS version won't allow it. Doesn't sound like something I can fix

chris-durand commented 1 year ago

The error is clang: error: unknown argument: '-nodefaultrpaths', it's unclear to me where that comes from.

@salkinium It comes from the patch https://raw.githubusercontent.com/Homebrew/formula-patches/1d184289/gcc/gcc-12.2.0-arm.diff. The patch adds a non-standard nodefaultrpaths option to gcc and somehow this is passed to the clang command line during the avr-gcc build.

salkinium commented 1 year ago

I was able to build this using the x86 homebrew on macOS 13, and the resulting compiler works just fine using Rosetta emulation. While not ideal, I would simply ignore the build issues on macOS 13 for now, since it must be fixed by Apple, and instead add a warning that it may not compile natively with instructions on how to compile it with x86 homebrew.

salkinium commented 1 year ago

I've added a warning message on macOS 13 on ARM64 with workaround instructions. Not great, but definitely workable.

Warning: Due to a bug in the macOS 13 command line tools 14.1, native
compilation may fail with an error related to missing support for
`-nodefaultrpath` in clang. There is no known fix for this.
However, you can build the formula using x86 Homebrew:
 $ arch -x86_64 /usr/local/bin/brew install avr-gcc@12
If you don't have x86 Homebrew, you must install it first:
 $ arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
salkinium commented 1 year ago

Thanks to an idea by @chris-durand, I just removed the patch and it compiles just fine on macOS 13. There isn't anything wrong with the compiler either, at least nothing I could detect in my examples. The patch is still being applied for macOS ≤12 though.

salkinium commented 1 year ago

Note sure why the ihex differs for the compiler running on ARM64, but at least it differs the same on the macOS 11 CI with the patch and my local macOS 13 instance without the patch.

salkinium commented 1 year ago

Please approve the CI for me @ladislas 🥺

ladislas commented 1 year ago

@salkinium i'm not sure the test is really useful as is. could you remove/replace it with something simpler like version output?

salkinium commented 1 year ago

I removed the second hex file test. I wanted to try to add a version test, but I cannot get shell_output to return a non-empty string, instead of printing to the shell. I still don't understand how Ruby works… 🙈

version_output = "gcc version 12.2.0 (Homebrew AVR GCC 12.2.0)"
assert_match version_output, shell_output("#{prefix}/bin/avr-gcc -v")
ladislas commented 1 year ago

@salkinium this should do the trick

    version_output = "gcc version 12.2.0 (Homebrew AVR GCC 12.2.0)\n"
    assert_equal `#{bin}/avr-gcc -v, version_output

note the \n at the end of version_output -- it has to be double checked as it might not be needed.

salkinium commented 1 year ago

Unfortunately the backticks return empty string as well. That's why I used shell_output, but that doesn't work either.

Error: avr-gcc@12: failed
An exception occurred within a child process:
  Minitest::Assertion:
--- expected
+++ actual
@@ -1 +1 @@
-"gcc version 12.2.0 (Homebrew AVR GCC 12.2.0)"
+""
ladislas commented 1 year ago

that's strange. are you sure avr-gcc is actually built? or that the path is the right one?

can you try with --verbose

also, shell_output is an object. Can you try shell_output(...).output?

https://rubydoc.brew.sh/Homebrew/Assertions.html#shell_output-instance_method

salkinium commented 1 year ago

Oh boy, avr-gcc -v outputs on stderr! No clue if that is supposed to be like that, but just adding 2>&1 did the trick 🙈.

There is still one error in the macOS 11 CI about a master branch? What is that about?

ladislas commented 1 year ago

@salkinium you juste need this head "https://gcc.gnu.org/git/gcc.git", branch: "master"

ladislas commented 1 year ago

also, binutils has been updated to 2.40

https://github.com/Homebrew/homebrew-core/blob/master/Formula/binutils.rb

salkinium commented 1 year ago

Do I need to put the README modifications into their own commit? This CI is… strict.

ladislas commented 1 year ago

Do I need to put the README modifications into their own commit? This CI is… strict.

Yeah, I think that would be better. I've never had this experience before, so I'm learning a lot as well in the process 😂

if you don't mind removing the README changes, I'll run the CI again asap

salkinium commented 1 year ago

I removed the Readme changes @ladislas.