dub icon indicating copy to clipboard operation
dub copied to clipboard

Dub build fails to build project on macOS with M1 chip

Open Vladiwostok opened this issue 1 year ago • 10 comments

System information

  • dub version: 1.38.0
  • OS Platform and distribution: macOS 14.5 (M1 chip)
  • compiler version LDC 1.39.0

Bug Description

Repo: https://github.com/Dlang-UPB/D-scanner

When trying to build the project's DMD dependency with dub build, the build fails with 'exit code 1' when running the following pregenerate command: https://github.com/dlang/dmd/blob/master/dub.sdl#L53-L61

When running the command manually, the linker reports that the 'phobos2-ldc' lib is not found. When specifying the library path via 'LIBRARY_PATH' or 'DFLAGS' env vars, the manual command works, but dub build still won't build the project.

How to reproduce?

  1. Get an M-chip macOS machine running (macOS 14.5) with the LDC compiler
  2. Clone the following repo: https://github.com/Dlang-UPB/D-scanner
  3. Run dub and watch the build fail:
dub build
  1. Run the pregen command manually (used dir paths specific to my macOS machine) and observe the linker error:
dub --arch=aarch64 --compiler=ldc2 --single /Users/runner/.dub/packages/dmd/~master/dmd/config.d -- /Users/runner/.dub/packages/dmd/~master/dmd/generated/dub /Users/runner/.dub/packages/dmd/~master/dmd/VERSION /etc
  1. Set either one env var:
export LIBRARY_PATH=/Users/runner/hostedtoolcache/dc/ldc2-1.39.0/arm64/ldc2-1.39.0-osx-universal/lib-arm64
export DFLAGS=-L-L/Users/runner/hostedtoolcache/dc/ldc2-1.39.0/arm64/ldc2-1.39.0-osx-universal/lib-arm64
  1. Run the pregen command manually (step 5) and watch the command execute successfully, run dub build (step 3) and watch the build fail.

Expected Behavior

The program should build successfully when using dub, and without having to set any additional library paths.

Logs

$ dub build
Error Expected one or zero arguments.
      Run "dub run -h" for more information about the "run" command.
Error Command failed with exit code 1: 
    "${DUB_EXE}" \
    --arch=${DUB_ARCH} \
    --compiler=${DC} \
    --single "${DUB_PACKAGE_DIR}config.d" \
    -- "${DUB_PACKAGE_DIR}generated/dub" \
    "${DUB_PACKAGE_DIR}VERSION" \
    /etc
$ dub build -vverbose
...
Running 
    "${DUB_EXE}" \
    --arch=${DUB_ARCH} \
    --compiler=${DC} \
    --single "${DUB_PACKAGE_DIR}config.d" \
    -- "${DUB_PACKAGE_DIR}generated/dub" \
    "${DUB_PACKAGE_DIR}VERSION" \
    /etc
   
Error Expected one or zero arguments.
      Run "dub run -h" for more information about the "run" command.
Error Command failed with exit code 1: 
    "${DUB_EXE}" \
    --arch=${DUB_ARCH} \
    --compiler=${DC} \
    --single "${DUB_PACKAGE_DIR}config.d" \
    -- "${DUB_PACKAGE_DIR}generated/dub" \
    "${DUB_PACKAGE_DIR}VERSION" \
    /etc
   
Full exception: object.Exception@source/dub/internal/utils.d(189): Command failed with exit code 1: 
    "${DUB_EXE}" \
    --arch=${DUB_ARCH} \
    --compiler=${DC} \
    --single "${DUB_PACKAGE_DIR}config.d" \
    -- "${DUB_PACKAGE_DIR}generated/dub" \
    "${DUB_PACKAGE_DIR}VERSION" \
    /etc
   
----------------
??:? object.Throwable.TraceInfo core.runtime.defaultTraceHandler(void*) [0x10233c2f3]
??:? _d_run_main [0x102344cf7]
??:? start [0x181c7e0df]
??:? 0x0 [0xe8177fffffffffff]
$ dub --arch=aarch64 --compiler=ldc2 --single /Users/runner/.dub/packages/dmd/~master/dmd/config.d -- /Users/runner/.dub/packages/dmd/~master/dmd/generated/dub /Users/runner/.dub/packages/dmd/~master/dmd/VERSION /etc
    Starting Performing "debug" build using ldc2 for aarch64, arm_hardfloat.
    Building config ~master: building configuration [application]
     Linking config
ld: library 'phobos2-ldc' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: /usr/bin/cc failed with status: 1
Error ldc2 failed with exit code 1.

Additional information

The same project built using makefile on the same OS and with the same compiler builds successfully, without having to set any additional library paths.

If needed, we can provide access to the target macOS machine via our Github actions flow.

Vladiwostok avatar Jul 23 '24 17:07 Vladiwostok