Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't build for SMING_ARCH=Host in Apple M1 Pro #2773

Open
mtzfactory opened this issue May 24, 2024 · 8 comments
Open

Can't build for SMING_ARCH=Host in Apple M1 Pro #2773

mtzfactory opened this issue May 24, 2024 · 8 comments

Comments

@mtzfactory
Copy link

I'm trying to build the basic blink example to debug it in my host machine (Apple M1 Pro) but it fails with the following error:

❯ make SMING_ARCH=Host

Basic_Blink: Invoking 'all' for Host (debug) architecture
/Applications/Xcode.app/Contents/Developer/usr/bin/make components application

Building /Users/xxxxxx/development/personal/espressif/sming/Sming/out/Host/debug/lib/clib-Storage-1766cf74635c72591842b6a122154060.a
clang: error: unknown argument: '-fstrict-volatile-bitfields'
clang: error: -Wl,-EL: 'linker' input unused [-Werror,-Wunused-command-line-argument]
make[2]: *** [src/Debug.cpp.d] Error 1
make[1]: *** [Storage-build] Error 2
make: *** [all] Error 2
@mtzfactory mtzfactory changed the title Can't build for SMING_ARCH=Host in an Apple M1 Pro Can't build for SMING_ARCH=Host in Apple M1 Pro May 24, 2024
@mikee47
Copy link
Contributor

mikee47 commented May 24, 2024

You have CLANG_TIDY defined (added in #2648). If this is problematic perhaps we should rename that variable, e.g. SMING_CLANG_TIDY ?

@mikee47
Copy link
Contributor

mikee47 commented May 24, 2024

Actually, might not be this... Try posting a dump of make V=1 so we can see compiler options, etc.

@mtzfactory
Copy link
Author

@mikee47 thanks for your response...

This is the log from command make V=1

❯ make SMING_ARCH=Host

sming-test: Invoking 'all' for Host (debug) architecture
Using configuration 'standard'
/Applications/Xcode.app/Contents/Developer/usr/bin/make components application

Building /Users/rmartinez/development/personal/espressif/sming/Sming/out/Host/debug/lib/clib-Storage-1766cf74635c72591842b6a122154060.a
clang: error: unknown argument: '-fstrict-volatile-bitfields'
clang: error: -Wl,-EL: 'linker' input unused [-Werror,-Wunused-command-line-argument]
make[2]: *** [src/Debug.cpp.d] Error 1
make[1]: *** [Storage-build] Error 2
make: *** [all] Error 2

❯ make V=1
PYTHON_VERSION = Python 3.12.3

sming-test: Invoking 'all' for Host (debug) architecture
-- Parsing App
-- Parsing Sming
-- Parsing Storage
-- Parsing sming-arch
-- Parsing driver
-- Parsing arch_driver
-- Parsing SerialLib
-- Parsing esp_hal
-- Parsing gdbstub
-- Parsing heap
-- Parsing malloc_count
-- Parsing hostlib
-- Parsing libc
-- Parsing spi_flash
-- Parsing vflash
-- Parsing rboot
-- Parsing FlashString
-- Parsing Spiffs
-- Parsing IFS
-- Parsing SPI
-- Parsing terminal
SUBMODULES_FETCHED:
/Applications/Xcode.app/Contents/Developer/usr/bin/make components application
PYTHON_VERSION = Python 3.12.3
-- Parsing App
-- Parsing Sming
-- Parsing Storage
-- Parsing sming-arch
-- Parsing driver
-- Parsing arch_driver
-- Parsing SerialLib
-- Parsing esp_hal
-- Parsing gdbstub
-- Parsing heap
-- Parsing malloc_count
-- Parsing hostlib
-- Parsing libc
-- Parsing spi_flash
-- Parsing vflash
-- Parsing rboot
-- Parsing FlashString
-- Parsing Spiffs
-- Parsing IFS
-- Parsing SPI
-- Parsing terminal

Building /Users/rmartinez/development/personal/espressif/sming/Sming/out/Host/debug/lib/clib-Storage-1766cf74635c72591842b6a122154060.a
/Applications/Xcode.app/Contents/Developer/usr/bin/make -r -R --no-print-directory -C /Users/rmartinez/development/personal/espressif/sming/Sming/out/Host/debug/build/Storage/Storage-1766cf74635c72591842b6a122154060 -f /Users/rmartinez/development/personal/espressif/sming/Sming/component-wrapper.mk COMPONENT_NAME=Storage COMPONENT_PATH=/Users/rmartinez/development/personal/espressif/sming/Sming/Components/Storage COMPONENT_BUILD_BASE=/Users/rmartinez/development/personal/espressif/sming/Sming/out/Host/debug/build/Storage COMPONENT_LIBDIR=/Users/rmartinez/development/personal/espressif/sming/Sming/out/Host/debug/lib COMPONENT_LIBNAME=Storage COMPONENT_LIBHASH=1766cf74635c72591842b6a122154060  build
PYTHON_VERSION = Python 3.12.3
WriteConfig /Users/rmartinez/development/personal/espressif/sming/Sming/out/Host/debug/build/Storage/Storage-1766cf74635c72591842b6a122154060/build.cfg
g++ -I/Users/rmartinez/development/personal/espressif/sming/Sming/Components -I/Users/rmartinez/development/personal/espressif/sming/Sming/System/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Wiring -I/Users/rmartinez/development/personal/espressif/sming/Sming/Core -I/Users/rmartinez/development/personal/espressif/sming/Sming -I/Users/rmartinez/development/personal/espressif/sming/Sming/Components/Storage/src/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host/Core -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host/Components -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host/Components/driver/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Components/arch_driver/src/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host/Components/SerialLib -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host/Components/esp_hal/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Esp8266/Components/esp8266/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host/Components/gdbstub/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host/Components/heap/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Components/malloc_count/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host/Components/hostlib/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host/Components/libc/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host/Components/spi_flash/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Esp8266/Components/spi_flash/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Arch/Host/Components/vflash/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Components/rboot/rboot -I/Users/rmartinez/development/personal/espressif/sming/Sming/Components/rboot/rboot/appcode -I/Users/rmartinez/development/personal/espressif/sming/Sming/Components/rboot/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Components/FlashString/src/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Libraries/Spiffs/src/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Components/IFS/src/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Components/IFS/src/Arch/Host/include -I/Users/rmartinez/development/personal/espressif/sming/Sming/Libraries/SPI/src -I/Users/rmartinez/development/personal/espressif/sming/Sming/Libraries/SPI/src/Arch/Host -I/Users/rmartinez/development/personal/espressif/sming/Sming/Components/terminal/include -Wl,-EL -finline-functions -fdata-sections -ffunction-sections -fstrict-volatile-bitfields -Wall -Wpointer-arith -Wno-comment -DARDUINO=106 -Werror -Wno-parentheses -Wno-unused-variable -Wno-unused-but-set-variable -Os -g -DARCH_HOST -m32 -Wno-deprecated-declarations -D_FILE_OFFSET_BITS=64 -DSMING_ARCH=Host -DSMING_SOC=host -DPROJECT_DIR=\"/Users/rmartinez/development/personal/temp/sming-test\" -DSMING_HOME=\"/Users/rmartinez/development/personal/espressif/sming/Sming\" -DSOC_HOST=1 -DDISABLE_NETWORK=1 -DDISABLE_WIFI=1 -DDEBUG_PRINT_FILENAME_AND_LINE=0 -DCUST_FILE_BASE=Components/Storage/src/Debug.cpp -DDEBUG_VERBOSE_LEVEL=2 -DSTRING_OBJECT_SIZE=12 -DUSE_US_TIMER -DENABLE_MALLOC_COUNT -DCOMPONENT_PATH=\"/Users/rmartinez/development/personal/espressif/sming/Sming/Components/Storage\" -Werror -DPARTITION_TABLE_OFFSET=0x00002000 -felide-constructors -fno-rtti -fno-exceptions -std=c++17  -MM -MT src/Debug.o /Users/rmartinez/development/personal/espressif/sming/Sming/Components/Storage/src/Debug.cpp -MF src/Debug.cpp.d
clang: error: unknown argument: '-fstrict-volatile-bitfields'
clang: error: -Wl,-EL: 'linker' input unused [-Werror,-Wunused-command-line-argument]
make[2]: *** [src/Debug.cpp.d] Error 1
make[1]: *** [Storage-build] Error 2
make: *** [all] Error 2

@mikee47
Copy link
Contributor

mikee47 commented Jun 7, 2024

So on your system running g++ invokes clang. I'm not an Apple user but from a quick web search I suspect clang/llvm is the default installed toolset.

Sming requires GCC. Have a look at https://sming.readthedocs.io/en/latest/getting-started/macos/index.html for installation instructions. You can also try searching for 'installing gcc on macos`.

It would be handy to have a MacOS system for testing, but they don't make it easy!

@mtzfactory
Copy link
Author

You are right, I tried to install the GNU version but still doesn't work...

As you can see I have installed the GNU versions for make and gcc...

❯ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0
❯ gcc --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
❯ $(brew --prefix gcc)/bin/gcc-14 --version
gcc-14 (Homebrew GCC 14.1.0) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

❯ $(brew --prefix gcc)/bin/g++-14 --version
g++-14 (Homebrew GCC 14.1.0) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

And I set the env variables to define the right CC and GCC:

# make
  local MAKE="$BREW_OPT_DIR/make"
  [ -d "$MAKE" ] && export PATH="$MAKE/libexec/gnubin:$PATH"

  # gcc
  local GCC="$BREW_OPT_DIR/gcc"
  if [ -d "$GCC" ]; then
    export PATH="$GCC/bin:$PATH"
    export CC="$(brew --prefix gcc)/bin/gcc-14"
    export CXX="$(brew --prefix gcc)/bin/g++-14"
  fi

I don't know what else I can do :-(

@mikee47
Copy link
Contributor

mikee47 commented Jun 11, 2024

I'm trying to get a VM installation of MacOS so I can help further. It's painful...

In the meantime, you can edit Sming/Host/build.mk to set the paths explicitly. You'll see that Sming expects gcc and g++, etc. on the path (not CC or CXX).

slaff pushed a commit that referenced this issue Jun 12, 2024
This PR adds the `CLANG_BUILD` for host builds. The toolchain detection logic is in the main build.mk file as there might be future support for clang toolchains for actual devices. It's also a revision to the existing logic which checks GCC compiler version.

Try it out using `make SMING_SOC=host CLANG_BUILD=1`.
To build with a specific (installed) version of clang, for example clang-15, use `CLANG_BUILD=15` .
Further customisation can be made by editing `Sming/Arch/Host/build.mk`.

Clang-tidy support (#2648) is also improved as there are some compiler flag differences between GCC and clang which are now shared between CLANG_TIDY and CLANG_BUILD operation.

An extra CI build has been added using clang.

Further to #2773, the default toolchain for macos is a version of clang (Apple Clang). This PR doesn't quite support that because there are other issues to address, but it's a step in the right direction.
@mikee47
Copy link
Contributor

mikee47 commented Jun 12, 2024

Update, I've been trying to get host builds for MacOS but even with GCC installed we still have to use the xcode linker. Bear with me, I'm sure we can get this working!

@mikee47
Copy link
Contributor

mikee47 commented Jun 12, 2024

Spoke too soon.

The host emulator builds in 32-bit mode to reflect the devices being targeted. GCC and clang both allow building 32-bit binaries for 64-bit platforms. However, it looks like Apple won't support 32-bit applications at all. See https://support.apple.com/en-us/103076.

Build fails at the link step because the linker refuses to recognise code compiled with the -m32 option.

Revising the framework to support 64-bit builds is problematic because all pointers would become 64-bit. That could be worth investigating if only to allow more general use of the libraries.

@mikee47 mikee47 mentioned this issue Jun 16, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants