Skip to content

Does not cross compile for nerves on Mac arm64 #16

Description

@SteffenDE

Hey there,

I'm using expty in nerves_ssh_system_shell and it works great in case it can use a prebuilt archive, but when it needs to compile, it fails for me in the following ways:

On macOS ARM64 trying to compile for Linux x86_64 MUSL:

==> expty
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 has been removed from CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.

  Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.


-- Configuring incomplete, errors occurred!
make: *** [/Users/steffen/nerves_examples/hello_live_view/_build/x86_64_dev/lib/expty/libuv/lib/libuv_a.a] Error 1
could not compile dependency :expty, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile expty --force", update it with "mix deps.update expty" or clean it with "mix deps.clean expty"
==> hello_live_view
** (Mix) Could not compile with "make" (exit status: 2).
You need to have gcc and make installed. Try running the
commands "gcc --version" and / or "make --version". If these programs
are not installed, you will be prompted to install them.

When I set export CMAKE_POLICY_VERSION_MINIMUM=3.5, I get a lot of Building C object ... but in the end it fails with

-- Installing: /Users/steffen/nerves_examples/hello_live_view/_build/x86_64_dev/lib/expty/libuv/lib/libuv_a.a
-- Installing: /Users/steffen/nerves_examples/hello_live_view/_build/x86_64_dev/lib/expty/libuv/lib/cmake/libuv/libuvConfig.cmake
-- Installing: /Users/steffen/nerves_examples/hello_live_view/_build/x86_64_dev/lib/expty/libuv/lib/cmake/libuv/libuvConfig-noconfig.cmake
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - no
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /Users/steffen/.nerves/artifacts/nerves_toolchain_x86_64_nerves_linux_musl-darwin_arm-13.2.0/bin/x86_64-nerves-linux-musl-gcc
-- Check for working C compiler: /Users/steffen/.nerves/artifacts/nerves_toolchain_x86_64_nerves_linux_musl-darwin_arm-13.2.0/bin/x86_64-nerves-linux-musl-gcc - broken
CMake Error at /opt/homebrew/share/cmake/Modules/CMakeTestCCompiler.cmake:67 (message):
  The C compiler

    "/Users/steffen/.nerves/artifacts/nerves_toolchain_x86_64_nerves_linux_musl-darwin_arm-13.2.0/bin/x86_64-nerves-linux-musl-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: '/Users/steffen/nerves_examples/hello_live_view/_build/x86_64_dev/lib/expty/cmake_expty/CMakeFiles/CMakeScratch/TryCompile-Uaoirs'

    Run Build Command(s): /opt/homebrew/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_dc3fb/fast
    /Library/Developer/CommandLineTools/usr/bin/make  -f CMakeFiles/cmTC_dc3fb.dir/build.make CMakeFiles/cmTC_dc3fb.dir/build
    Building C object CMakeFiles/cmTC_dc3fb.dir/testCCompiler.c.o
    /Users/steffen/.nerves/artifacts/nerves_toolchain_x86_64_nerves_linux_musl-darwin_arm-13.2.0/bin/x86_64-nerves-linux-musl-gcc   -m64 -fstack-protector-strong -march=x86-64 -fPIE -pie -Wl,-z,now -Wl,-z,relro -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -O2 --sysroot /Users/steffen/.nerves/artifacts/nerves_system_x86_64-portable-1.31.3/staging  -arch arm64 -o CMakeFiles/cmTC_dc3fb.dir/testCCompiler.c.o -c /Users/steffen/nerves_examples/hello_live_view/_build/x86_64_dev/lib/expty/cmake_expty/CMakeFiles/CMakeScratch/TryCompile-Uaoirs/testCCompiler.c
    x86_64-nerves-linux-musl-gcc: error: unrecognized command-line option '-arch'
    make[2]: *** [CMakeFiles/cmTC_dc3fb.dir/testCCompiler.c.o] Error 1
    make[1]: *** [cmTC_dc3fb/fast] Error 2





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
make: *** [/Users/steffen/nerves_examples/hello_live_view/_build/x86_64_dev/lib/expty/priv/expty.so] Error 1
could not compile dependency :expty, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile expty --force", update it with "mix deps.update expty" or clean it with "mix deps.clean expty"
==> hello_live_view
** (Mix) Could not compile with "make" (exit status: 2).
You need to have gcc and make installed. Try running the
commands "gcc --version" and / or "make --version". If these programs
are not installed, you will be prompted to install them.

When I build on Linux x86_64 GNU for Linux x86_64 MUSL it works: https://gist.github.com/SteffenDE/93891da6c755af35501ff00dd91e6f68, but I've also seen it fail when I built the system from source, though with a different error. Not sure how to best reproduce that and also not sure if related.

To reproduce on macOS ARM64:

  1. git clone https://github.com/nerves-project/nerves_examples.git
  2. cd nerves_examples/hello_live_view/ (or any other project)
  3. Edit mix.exs and add {:expty, "~> 0.2.1"} as dependency.
  4. MIX_TARGET=x86_64 mix deps.get
  5. MIX_TARGET=x86_64 mix firmware

I'm not sure how easy it is to fix this, but it would be great if it properly compiled in that case. Maybe another solution would be to also precompile for musl, if that's easier to do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions