www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - DUB on Apple Silicon

reply Jan Allersma <jan allersma.be> writes:
L.S.,

Currently I'm trying to compile a DUB project on my Apple with M1 
processor.
When I was trying to build to project, something strange happened:

```
$ dub run --vverbose --force 
--compiler=/usr/local/homebrew/Cellar/ldc/1.35.0/bin/ldc2 
--arch=arm64
Using dub registry url 'https://code.dlang.org/'
'git --git-dir=/<path-to-my-dub-project>/.git describe --long 
--tags' failed with exit code 128: fatal: No names found, cannot 
describe anything.
Determined package version using GIT: printplaat ~persistency
Error Unsupported architecture: arm64
Full exception: 
dub.compilers.compiler.UnsupportedArchitectureException source/dub/
ompilers/ldc.d(93): Unsupported architecture: arm64
----------------
??:? object.Throwable.TraceInfo 
core.runtime.defaultTraceHandler(void*) [0x10472f3d2]
```

I cannot figure out why I get this error and why it is not 
possible for me to compile my project. My 
[dub.json](https://github.com/kapstok/printplaat/blob/apple-silicon/dub.json)
may look a bit odd, but I don't see why that should be the reason for the
problem. Does anyone know what the problem could be?

Many thanks in advance!
Oct 30 2023
next sibling parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
See: https://github.com/dlang/dub/blob/master/source/dub/compilers/ldc.d#L93

Use aarch64 instead.
Oct 30 2023
parent reply Jan Allersma <jan allersma.be> writes:
On Monday, 30 October 2023 at 21:06:34 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 See: 
 https://github.com/dlang/dub/blob/master/source/dub/compilers/ldc.d#L93

 Use aarch64 instead.
Thanks! It seems to partially solve the problem. When building, the linker still expects x86_64 architecture instead of arm64: ``` /usr/local/homebrew/Cellar/ldc/1.35.0/bin/ldc2 -L-lstdc++ -Xcc --mv=arsd.dom=/Users/werk/.dub/packages/arsd-official/11.2.2 arsd-official/dom.d --mv=arsd.characterencodings=/Users/werk/.dub/packages/arsd-official/11.2.2/arsd-official/ haracterencodings.d --mv=arsd.core=/Users/werk/.dub/packages/arsd-official/11.2.2/ rsd-official/core.d -march=aarch64 -c -of/Users/werk/.dub/cache/printplaat/~apple-silicon/build/application-debug-881Rj0Sg_L43vAT yoyqKA/printplaat.o -d-debug -g -w --oq -od=/Users/werk/.dub/cache/printplaat/~apple-silicon/build/application-debug-881Rj0 g_L43vATMyoyqKA/obj -d-version=Have_printplaat -d-version=Have_arsd_official_dom -d-version=Have_arsd_official_characterencodings -d-version=Have_arsd_official_core -Isrc/ sdl_wrapper/build/arsd-official/arsd/dom.d src/app.d src/components.d src/input/delegates.d src/input/field.d src/palette.d src/persistency.d -vcolumns Linking printplaat /usr/local/homebrew/Cellar/ldc/1.35.0/bin/ldc2 -of/Users/werk/.dub/cache/printplaat/~apple-silicon/build/application-debug-881Rj0Sg_L43v TMyoyqKA/printplaat /Users/werk/.dub/cache/printplaat/~apple-silicon/build/application-debug-881Rj0Sg_L43vAT yoyqKA/printplaat.o ../../.dub/cache/arsd-official/11.2.2/+dom/build/library-debug-QoYAFb4-AqELlyjHCh3Bog/li arsd-official_dom.a ../../.dub/cache/arsd-official/11.2.2/+characterencodings/build/library-debug-O9UK1pRdgOznLacdyYRRLA/libarsd-official_ haracterencodings.a ../../.dub/cache/arsd-official/11.2.2/+core/build/library-debug-kVIIkSg8q9PWianoM_cwlw/lib rsd-official_core.a -L-Lsdl_wrapper/build -L-lsdlwrapper -L-lSDL2 -L-lSDL2_ttf -L-lstdc++ -march=aarch64 -g ld: warning: ignoring file 'sdl_wrapper/build/libSDL2_ttf.a[2](libSDL2_ttf_la-SDL_ttf.o)': found architecture 'arm64', required architecture 'x86_64' ld: warning: ignoring file '../../.dub/cache/arsd-official/11.2.2/+core/build/library-debug-kVIIkSg8q9PWianoM_cwlw/libarsd-official_core a[2](arsd.core.o)': found architecture 'arm64', required architecture 'x86_64' ld: warning: ignoring file '/Users/werk/.dub/cache/printplaat/~apple-silicon/build/application-debug-881Rj0Sg_L43vATMy yqKA/printplaat.o': found architecture 'arm64', required architecture 'x86_64' ld: warning: ignoring file '../../.dub/cache/arsd-official/11.2.2/+characterencodings/build/library-debug-O9UK1pRdgOznLacdyYRRLA/libarsd-official_characterencodings.a[2](arsd.cha acterencodings.o)': found architecture 'arm64', required architecture 'x86_64' ld: warning: ignoring file '../../.dub/cache/arsd-official/11.2.2/+dom/build/library-debug-QoYAFb4-AqELlyjHCh3Bog/libarsd-official_do .a[2](arsd.dom.o)': found architecture 'arm64', required architecture 'x86_64' ld: warning: ignoring file '/usr/local/homebrew/Cellar/ldc/1.35.0/lib/libphobos2-ldc.a[183](zlib.o)': found architecture 'arm64', required architecture 'x86_64' (...) And so on... ``` Could it have something to do with `-L-lstdc++`? Or am I supposed to use a different linker?
Oct 30 2023
next sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
I have no suggestion except telling dub to ``--force`` a new build. Just 
in case there is something left over.
Oct 30 2023
prev sibling parent reply Johan <j j.nl> writes:
On Monday, 30 October 2023 at 21:29:50 UTC, Jan Allersma wrote:
 On Monday, 30 October 2023 at 21:06:34 UTC, Richard (Rikki) 
 Andrew Cattermole wrote:
 See: 
 https://github.com/dlang/dub/blob/master/source/dub/compilers/ldc.d#L93

 Use aarch64 instead.
Thanks! It seems to partially solve the problem. When building, the linker still expects x86_64 architecture instead of arm64:
Hello Jan, I don't know much about compiling with `dub`. But I think that the program invoking the linker defines the mode of the linker; looks like the linker is called from an x86_64 binary, instead of an arm64. Can you tell us (use `file ...` to check): 1. Is `ldc2` an arm64 binary or an x86_64 binary? 2. is `dub` arm64? I think in an ideal world you don't even have to tell `dub` what arch to build for, it automatically selects the right architecture. If you use the LDC released binaries for macOS from LDC's github, you will get arm64 versions of `ldc2`, `dub`, ... https://github.com/ldc-developers/ldc/releases/download/v1.35.0/ldc2-1.35.0-osx-arm64.tar.xz cheers, Johan
Oct 30 2023
next sibling parent reply Jan Allersma <jan allersma.be> writes:
On Monday, 30 October 2023 at 22:06:11 UTC, Johan wrote:

 Can you tell us (use `file ...` to check):
 1. Is `ldc2` an arm64 binary or an x86_64 binary?
 2. is `dub` arm64?
I have tried using `--force` and the flag Guillaume Piolat suggested. Unfortunately, both solutions did not solve the problem. Johan's suggestion gave some insights: ``` $ file `which dub` /usr/local/bin/dub: Mach-O 64-bit executable x86_64 $ file /usr/local/homebrew/Cellar/ldc/1.35.0/bin/ldc2 /usr/local/homebrew/Cellar/ldc/1.35.0/bin/ldc2: Mach-O 64-bit executable arm64 $ file `which ld` /usr/bin/ld: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e] /usr/bin/ld (for architecture x86_64): Mach-O 64-bit executable x86_64 /usr/bin/ld (for architecture arm64e): Mach-O 64-bit executable arm64e ``` I will try to get a arm64 version of DUB. Once I have done that, I will give an update.
Oct 31 2023
parent Jan Allersma <jan allersma.be> writes:
On Tuesday, 31 October 2023 at 09:03:12 UTC, Jan Allersma wrote:
 I will try to get a arm64 version of DUB. Once I have done 
 that, I will give an update.
Maybe I am too much of a rookie, but compiling DUB from source with ldc2 gave me a lot of frustrations. I ended up making a Bash script that does the same I expect DUB to do. With this configuration, compiling to aarch64 is possible. I assume that Johan's suggestion was right, looking back at the script I made now. Thanks for everyone's input!
Nov 01 2023
prev sibling parent Jan Allersma <jan allersma.be> writes:
On Monday, 30 October 2023 at 22:06:11 UTC, Johan wrote:
 If you use the LDC released binaries for macOS from LDC's 
 github, you will get arm64 versions of `ldc2`, `dub`, ...
 https://github.com/ldc-developers/ldc/releases/download/v1.35.0/ldc2-1.35.0-osx-arm64.tar.xz
I am such a silly goose. I overlooked the option to just download the binaries. Downloading it resolved the problem. So I can still use DUB if I want to. Thanks! 😁
Nov 01 2023
prev sibling parent Guillaume Piolat <first.name gmail.com> writes:
On Monday, 30 October 2023 at 20:51:39 UTC, Jan Allersma wrote:
 Many thanks in advance!
dub -a arm64-apple-macos
Oct 30 2023