SimonN / LixD

Lix: Lemmings-like game with puzzles, editor, multiplayer
https://www.lixgame.com
132 stars 16 forks source link

Build on macOS arm64 fail #430

Closed naymapl closed 2 years ago

naymapl commented 2 years ago

Hello. I build on Intel macOS just fine. I try to build it on my mac mini m1 and is fail. Install allegro from brew for amr. with no issue but build always fail. Any chance to add support for arm is well ?

 dub build -b release --compiler=ldc2                                                                                                                                                                        02.03.22    09:14:07 
Performing "release" build using ldc2 for aarch64, arm_hardfloat.
allegro 4.0.4+5.2.0: building configuration "no-libs"...
derelict-util 3.0.0-beta.2: building configuration "library"...
derelict-enet 4.2.0: building configuration "library"...
enumap 0.4.2: building configuration "library"...
bolts 1.3.1: building configuration "library"...
optional 1.3.0: building configuration "library"...
taggedalgebraic 0.11.22: building configuration "library"...
sdlang-d 0.10.6: building configuration "library"...
lix 0.9.42: building configuration "application"...
Compiling Lix 0.9.42 with LDC for macOS, 64-bit...
Linking...
ld: library not found for -lallegro_acodec
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: /usr/bin/cc failed with status: 1
ldc2 failed with exit code 1.
SimonN commented 2 years ago

Hi!

Hmm, you installed Allegro from brew for amr, but dub/ldc2/ld won't find the Allgero add-on libraries.

Please post the output of:

find /usr/lib* /usr/inc* -name \*allegro\*

Some ideas for how to proceed:

Thanks for giving Lix a shot on the different Macs. I don't have one myself to test. It's great to hear that it builds and runs fine on Intel macOS.

naymapl commented 2 years ago
  • "libs-osx-aarch64":

Hi. Thank you so much for reply. First in new apple silicon chips all package change to new directory: opt/homebrew/ I found allegro here:

find /opt/homebrew/ -name \*allegro\*                                                                                                                                                                     03.03.22    08:24:14 
/opt/homebrew//include/allegro5
/opt/homebrew//var/homebrew/linked/allegro
/opt/homebrew//Library/Taps/homebrew/homebrew-core/Formula/allegro.rb
/opt/homebrew//lib/liballegro_ttf.dylib
/opt/homebrew//lib/liballegro_image.5.2.7.dylib
/opt/homebrew//lib/liballegro_audio.5.2.dylib
/opt/homebrew//lib/liballegro_image.5.2.dylib
/opt/homebrew//lib/liballegro_image.dylib
/opt/homebrew//lib/pkgconfig/allegro_font-5.pc
/opt/homebrew//lib/pkgconfig/allegro_color-5.pc
/opt/homebrew//lib/pkgconfig/allegro_ttf-5.pc
/opt/homebrew//lib/pkgconfig/allegro_memfile-5.pc
/opt/homebrew//lib/pkgconfig/allegro_dialog-5.pc
/opt/homebrew//lib/pkgconfig/allegro_primitives-5.pc
/opt/homebrew//lib/pkgconfig/allegro-5.pc
/opt/homebrew//lib/pkgconfig/allegro_acodec-5.pc
/opt/homebrew//lib/pkgconfig/allegro_video-5.pc
/opt/homebrew//lib/pkgconfig/allegro_physfs-5.pc
/opt/homebrew//lib/pkgconfig/allegro_main-5.pc
/opt/homebrew//lib/pkgconfig/allegro_audio-5.pc
/opt/homebrew//lib/pkgconfig/allegro_image-5.pc
/opt/homebrew//lib/liballegro_primitives.5.2.7.dylib
/opt/homebrew//lib/liballegro_dialog.dylib
/opt/homebrew//lib/liballegro_dialog.5.2.dylib
/opt/homebrew//lib/liballegro_font.5.2.dylib
/opt/homebrew//lib/liballegro_dialog.5.2.7.dylib
/opt/homebrew//lib/liballegro_memfile.dylib
/opt/homebrew//lib/liballegro_ttf.5.2.7.dylib
/opt/homebrew//lib/liballegro_main.dylib
/opt/homebrew//lib/liballegro_physfs.dylib
/opt/homebrew//lib/liballegro_font.dylib
/opt/homebrew//lib/liballegro_font.5.2.7.dylib
/opt/homebrew//lib/liballegro_main.5.2.7.dylib
/opt/homebrew//lib/liballegro_primitives.dylib
/opt/homebrew//lib/liballegro_primitives.5.2.dylib
/opt/homebrew//lib/liballegro_main.5.2.dylib
/opt/homebrew//lib/liballegro.dylib
/opt/homebrew//lib/liballegro_color.dylib
/opt/homebrew//lib/liballegro_video.dylib
/opt/homebrew//lib/liballegro_audio.dylib
/opt/homebrew//lib/liballegro_audio.5.2.7.dylib
/opt/homebrew//lib/liballegro.5.2.dylib
/opt/homebrew//lib/liballegro_color.5.2.dylib
/opt/homebrew//lib/liballegro_ttf.5.2.dylib
/opt/homebrew//lib/liballegro_video.5.2.dylib
/opt/homebrew//lib/liballegro_video.5.2.7.dylib
/opt/homebrew//lib/liballegro_memfile.5.2.dylib
/opt/homebrew//lib/liballegro.5.2.7.dylib
/opt/homebrew//lib/liballegro_acodec.5.2.7.dylib
/opt/homebrew//lib/liballegro_acodec.dylib
/opt/homebrew//lib/liballegro_acodec.5.2.dylib
/opt/homebrew//lib/liballegro_physfs.5.2.dylib
/opt/homebrew//lib/liballegro_memfile.5.2.7.dylib
/opt/homebrew//lib/liballegro_color.5.2.7.dylib
/opt/homebrew//lib/liballegro_physfs.5.2.7.dylib
/opt/homebrew//opt/allegro
/opt/homebrew//Cellar/allegro
/opt/homebrew//Cellar/allegro/5.2.7.0/.brew/allegro.rb
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_acodec.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_memfile.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_native_dialog.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_osx.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro5.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_audio.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_color.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_direct3d.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/platform/allegro_sdl_config.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_font.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_opengl.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_ttf.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_image.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_physfs.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_primitives.h
/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_video.h
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_ttf.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_image.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_audio.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_image.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_image.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_font-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_color-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_ttf-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_memfile-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_dialog-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_primitives-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_acodec-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_video-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_physfs-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_main-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_audio-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/pkgconfig/allegro_image-5.pc
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_primitives.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_dialog.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_dialog.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_font.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_dialog.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_memfile.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_ttf.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_main.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_physfs.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_font.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_font.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_main.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_primitives.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_primitives.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_main.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_color.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_video.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_audio.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_audio.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_color.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_ttf.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_video.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_video.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_memfile.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_acodec.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_acodec.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_acodec.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_physfs.5.2.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_memfile.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_color.5.2.7.dylib
/opt/homebrew//Cellar/allegro/5.2.7.0/lib/liballegro_physfs.5.2.7.dylib

I change dub.json for:

...
   "dependencies": {
        "allegro": ">=4.0.4",
        "enumap": ">=0.4.2",
        "derelict-enet": ">=2.0.0",
        "optional": "~>1.3.0",
        "sdlang-d": ">=0.10.6",
    },

     "libs-osx-aarch64": [
        "/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_acodec",
        "/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_audio",
        "/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_font",
        "/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_image",
        "/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_primitives",
        "/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_ttf",
    ],
    "libs-linux": ["allegro-5"],
    "libs-dragonflybsd": ["allegro-5"],
    "libs-freebsd": ["allegro-5"],
    "libs-netbsd": ["allegro-5"],
    "libs-openbsd": ["allegro-5"],
    "libs-solaris": ["allegro-5"],
    "libs-osx": ["allegro"],
    "libs-windows": ["allegro"],
...

but got error all the times:

dub build                                                                                                                                                                                                 03.03.22    08:26:36 
Performing "debug" build using ldc2 for aarch64, arm_hardfloat.
allegro 4.0.4+5.2.0: target for configuration "no-libs" is up to date.
derelict-util 3.0.0-beta.2: target for configuration "library" is up to date.
derelict-enet 4.2.0: target for configuration "library" is up to date.
enumap 0.4.2: target for configuration "library" is up to date.
bolts 1.3.1: target for configuration "library" is up to date.
optional 1.3.0: target for configuration "library" is up to date.
taggedalgebraic 0.11.22: target for configuration "library" is up to date.
sdlang-d 0.10.6: target for configuration "library" is up to date.
lix 0.9.42: building configuration "application"...
Compiling Lix 0.9.42 with LDC for macOS, 64-bit...
Linking...
ld: library not found for -l/opt/homebrew//Cellar/allegro/5.2.7.0/include/allegro5/allegro_acodec
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: /usr/bin/cc failed with status: 1
ldc2 failed with exit code 1.

For sure is not correct patch of allegro.

SimonN commented 2 years ago

Thanks! /opt/homebrew/lib/liballegro_acodec.dylib exists, we had its basename allegro_acodec already correct, and yet the linker fails to find it.

It's reasonable that Homebrew installs outside of /usr. Since Homebrew is popular, I'd have expected the linker to search in /opt/homebrew/lib/ by default, too.

Idea A. On POSIX systems, dub will ask pkg-config for the library paths and names.

  1. Revert dub.json to how it came with Lix.
  2. Install pkg-config: brew install pkg-config
  3. Rebuild Lix without changing any files.

If this solves the problem, I'll add pkg-config to the build instructions for macOS. I've already added pkgconf or pkg-config to the instructions for some Linux distros; it makes a lot of sense to add it to macOS, too.

Idea B. If idea A didn't work, let's try again to force the exact paths by hand. In dub.json, replace your edited section with this:

"libs-osx-aarch64": [
    "/opt/homebrew/lib/allegro_acodec",
    "/opt/homebrew/lib/allegro_audio",
    "/opt/homebrew/lib/allegro_font",
    "/opt/homebrew/lib/allegro_image",
    "/opt/homebrew/lib/allegro_primitives",
    "/opt/homebrew/lib/allegro_ttf",
],

Then rebuild Lix.

It looks funky to add directory paths in "libs:" followed by the library's basename without lib nor extension in the basename. But it should work according to https://github.com/dlang/dub/issues/1449#issuecomment-645836598.

If this is the only solution, it makes it harder to support for me. I'd rather not ship Lix with such custom paths per platform. It would be much better if pkg-config solved the problem.

naymapl commented 2 years ago

Thank you for help.

idea A: what do you mean - "Rebuild Lix without changing any files." ?? No idea how to rebuild it but I installed pkg-config and try to build fresh git clone and still error

Compiling Lix 0.9.42 with LDC for macOS, 64-bit...
Linking...
ld: library not found for -lallegro_acodec
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: /usr/bin/cc failed with status: 1
ldc2 failed with exit code 1.

Idea B not working:

ld: library not found for -l/opt/homebrew/lib/allegro_acodec
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: /usr/bin/cc failed with status: 1
ldc2 failed with exit code 1.

or

ld: library not found for -lallegro_acodec
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: /usr/bin/cc failed with status: 1
ldc2 failed with exit code 1.
SimonN commented 2 years ago

Yep, with "rebuild Lix", I meant: Try again to compile Lix by running dub.

Hmm, on idea B, the Error "ld: library not found for -l/opt/homebrew/lib/allegro_acodec" sounds like passing full dirs in -l linker flags won't work after all.

Idea C: We can add the library directory manually for lookup. Revert dub.json to how it looks on a clean checkout. Then, somewhere in the middle of dub.json, e.g., directly before the line "libs": [, add the following line:

"lflags-osx-aarch64": ["-L/opt/homebrew/lib/"],

Then run dub again to compile Lix.

naymapl commented 2 years ago

@SimonN thank you - this idea working well. Game build but have some issues with graphic sprite. I thing some png files alfa layer are pink and game looks like this:

Zrzut ekranu 2022-03-4 o 09 22 48 Its not in every single level but cursor is pink is well.

SimonN commented 2 years ago

Cool to see it run on ARM! I'll file a separate bug for the pink colors.

About what to put in my dub.json: I believe I've relied on pkg-config in the wrong way all these years. Allegro's pkg-config usage suggest that I should put

"libs": ["allegro-5", "allegro_color-5", ...

i.e., append -5, instead of trying to guess the exact library names as 0.9.42 does:

"libs": ["allegro", "allegro_color", ...

dub will first try to pass the names from "libs": to pkg-config. Only if pkg-config doesn't know them or isn't installed, dub will use the "libs": as -l flags directly for the linker.

For my next release, I'm planning: I'll add pkg-config to the macOS build instructions, and write into dub.json the library names with -5 appended.

naymapl commented 2 years ago

@SimonN thank you for answer. I try config like this in dub.json:

    "libs": [
        "allegro_acodec",
        "allegro_audio",
        "allegro_font",
        "allegro_image",
        "allegro_primitives",
        "allegro_ttf",
    ],

    "lflags-osx-aarch64": ["-L/opt/homebrew/lib/"],
    "libs-linux": ["allegro-5"],
    "libs-osx": ["allegro-5"],
    "libs-windows": ["allegro-5"],

Build log:

dub build -b release --compiler=ldc2 --force   

Performing "release" build using ldc2 for aarch64, arm_hardfloat.
allegro 4.0.4+5.2.0: building configuration "no-libs"...
derelict-util 3.0.0-beta.2: building configuration "library"...
derelict-enet 4.2.0: building configuration "library"...
enumap 0.4.2: building configuration "library"...
bolts 1.3.1: building configuration "library"...
optional 1.3.0: building configuration "library"...
taggedalgebraic 0.11.22: building configuration "library"...
sdlang-d 0.10.6: building configuration "library"...
lix 0.9.42: building configuration "application"...
Compiling Lix 0.9.42 with LDC for macOS, 64-bit...
Linking...

Still this same issue with pink transparent alpha layer.

SimonN commented 2 years ago

Editing dub.json won't help with the colors. I'll think of something to try!

naymapl commented 2 years ago

ok. I check source and all png files have this pink layer. Maybye is better to create source png files with real transparent layers ?

edit: answer is no :D

mouse l

I prepare file with transparent layer and now have no cursor :D Zrzut ekranu 2022-03-5 o 17 10 43

SimonN commented 2 years ago

Hi @naymapl, since Lix 0.9.43, I've permanently changed dub.json to rely on pkg-config on macOS.

Please discard your custom dub.json, then pull my master branch. Does $ dub now build out of the box on ARM64 macOS?

SimonN commented 2 years ago

I still believe: In Lix 0.9.43 and Lix 0.9.44, the dub.json works out of the box even on ARM macOS and need not be changed. That would solve this issue. I'll close this.

Reopen or file a new bug if you run into problems again. :-)