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

Building for mac m1(arm) #1708

Open
hellozyemlya opened this issue Jan 12, 2023 · 20 comments
Open

Building for mac m1(arm) #1708

hellozyemlya opened this issue Jan 12, 2023 · 20 comments

Comments

@hellozyemlya
Copy link

Hello. I am trying to build CppSharp for mac m1, I use following commands

 1026  ./build.sh build_llvm --platform osx-arm64
 1027  ./build.sh package_llvm --platform osx-arm64
 1028  ./build.sh generate -configuration Release -platform osx-arm64

the last command failed with:

eugenechekanskiy@MacBook-Pro-Eugene build % ./build.sh generate -configuration Release -platform osx-arm64
Archive llvm-791523-macosx-osx-arm64-Release.tar.xz already exists.
Using debug LLVM build: /Users/eugenechekanskiy/Develop/CppSharp/build/llvm/llvm-791523-macosx-osx-arm64-Debug
Using release LLVM build: /Users/eugenechekanskiy/Develop/CppSharp/build/llvm/llvm-791523-macosx-osx-arm64-Release
Error: invalid value 'osx-arm64' for option 'arch'

What is the proper platform keys for each of building steps?

@tritao
Copy link
Collaborator

tritao commented Jan 12, 2023

You need to add a new entry here: https://github.com/mono/CppSharp/blob/main/build/Helpers.lua#L12

@hxbb00
Copy link
Contributor

hxbb00 commented May 17, 2023

Have you implemented the arm architecture support?i need support arm64, but i do not know how to generate bindings(CppSharp/src/CppParser/Bindings/CSharp/aarch64-linux-gnu-cxx11abi),Can you give me some help

@konistehrad
Copy link
Contributor

Bumping this. It'd be a big help for Unity development, of all things, which often depends on bindings to native code.

@tritao
Copy link
Collaborator

tritao commented Feb 2, 2024

Have you implemented the arm architecture support?i need support arm64, but i do not know how to generate bindings(CppSharp/src/CppParser/Bindings/CSharp/aarch64-linux-gnu-cxx11abi),Can you give me some help

Late reply, but better late than never.

Support for generating bindings for ARM64 was just implemented in d1307a5. AppleARM64 was already implemented before.

For generating the parser bindings for ARM64 check the ParserGen project: https://github.com/mono/CppSharp/blob/main/src/CppParser/ParserGen/ParserGen.cs

You will also need to extract the headers package to the build folder IIRC: https://github.com/mono/CppSharp/releases/download/CppSharp/headers.zip

@tritao
Copy link
Collaborator

tritao commented Feb 2, 2024

Bumping this. It'd be a big help for Unity development, of all things, which often depends on bindings to native code.

I don't have an M1 machine so cannot really do this. But remember that you can cross-generate bindings with CppSharp, so you can run it either in a VM or container / remote machine to generate the bindings, which sould be able to run fine with M1.

@konistehrad
Copy link
Contributor

Bingo, thanks for that tip on the headers that's what I needed. (I was in the middle of exploring ParserGen as you were typing.) I can generate the bindings for you for M1 if it'll help.

@konistehrad
Copy link
Contributor

(Also for future travelers: the osx-arm64 above should be replaced with arm64)

@XzuluX
Copy link

XzuluX commented Feb 2, 2024

Just tried to build CppSharp on Ubuntu aarch64

Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy

./build.sh build_llvm --platform arm64
./build.sh package_llvm --platform arm64
./build.sh generate -configuration Release -platform arm64

got following error, any idea ?

Creating ../../obj/Encodings.Native/Release
Encodings.cpp
Creating ../../gen/Encodings
Linking Encodings.Native
make: Leaving directory '/home/zulu/repos/CppSharp/build/gmake'
  CppSharp -> /home/zulu/repos/CppSharp/bin/Release_arm64/CppSharp.dll
  CppSharp.AST -> /home/zulu/repos/CppSharp/bin/Release_arm64/CppSharp.AST.dll
  CppSharp.Runtime -> /home/zulu/repos/CppSharp/bin/Release_arm64/CppSharp.Runtime.dll
  CppSharp.Parser.CSharp -> /home/zulu/repos/CppSharp/bin/Release_arm64/CppSharp.Parser.CSharp.dll
  /home/zulu/repos/CppSharp/src/Parser/ASTConverter.cs(4,23): error CS0234: The type or namespace name 'AST' does not exist in the namespace 'CppSharp.Parser' (are you missing an assembly reference?) [/home/zulu/repos/CppSharp/src/Parser/CppSharp.Parser.csproj]
/home/zulu/repos/CppSharp/src/Parser/ASTConverter.Expr.cs(8,23): error CS0234: The type or namespace name 'AST' does not exist in the namespace 'CppSharp.Parser' (are you missing an assembly reference?) [/home/zulu/repos/CppSharp/src/Parser/CppSharp.Parser.csproj]
/home/zulu/repos/CppSharp/src/Parser/ASTConverter.Stmt.cs(8,23): error CS0234: The type or namespace name 'AST' does not exist in the namespace 'CppSharp.Parser' (are you missing an assembly reference?) [/home/zulu/repos/CppSharp/src/Parser/CppSharp.Parser.csproj]
/home/zulu/repos/CppSharp/src/Parser/Parser.cs(6,36): error CS0234: The type or namespace name 'AST' does not exist in the namespace 'CppSharp.Parser' (are you missing an assembly reference?) [/home/zulu/repos/CppSharp/src/Parser/CppSharp.Parser.csproj]
/home/zulu/repos/CppSharp/src/Parser/Parser.cs(7,39): error CS0234: The type or namespace name 'AST' does not exist in the namespace 'CppSharp.Parser' (are you missing an assembly reference?) [/home/zulu/repos/CppSharp/src/Parser/CppSharp.Parser.csproj]
/home/zulu/repos/CppSharp/src/Parser/ASTConverter.cs(16,39): error CS0246: The type or namespace name 'TagType' could not be found (are you missing a using directive or an assembly reference?) [/home/zulu/repos/CppSharp/src/Parser/CppSharp.Parser.csproj]
/home/zulu/repos/CppSharp/src/Parser/ASTConverter.cs(17,41): error CS0246: The type or namespace name 'ArrayType' could not be found (are you missing a using directive or an assembly reference?) [/home/zulu/repos/CppSharp/src/Parser/CppSharp.Parser.csproj]
/home/zulu/repos/CppSharp/src/Parser/ASTConverter.cs(18,44): error CS0246: The type or namespace name 'FunctionType' could not be found (are you missing a using directive or an assembly reference?) [/home/zulu/repos/CppSharp/src/Parser/CppSharp.Parser.csproj]
/home/zulu/repos/CppSharp/src/Parser/ASTConverter.cs(19,43): error CS0246: The type or namespace name 'PointerType' could not be found (are you missing a using directive or an assembly reference?) [/home/zulu/repos/CppSharp/src/Parser/CppSharp.Parser.csproj]
/home/zulu/repos/CppSharp/src/Parser/ASTConverter.cs(20,49): error CS0246: The type or namespace name 'MemberPointerType' could not be found (are you missing a using directive or an assembly reference?) [/home/zulu/repos/CppSharp/src/Parser/CppSharp.Parser.csproj]
/home/zulu/repos/CppSharp/src/Parser/ASTConverter.cs(21,43): error CS0246: The type or namespace name 'TypedefType' could not be found (are you missing a using directive or an assembly reference?) [/home/zulu/repos/CppSharp/src/Parser/CppSharp.Parser.csproj]
......

@konistehrad
Copy link
Contributor

konistehrad commented Feb 2, 2024

Those are part of the aforementioned bindings packages found in for example CppSharp/src/CppParser/Bindings/CSharp/aarch64-linux-gnu-cxx11abi. They'll have to be regenerated as mentioned in #1708 (comment). I'm working on this on the Mac side now, I assume the solution will be portable to linux as well. I'll fire up a VM and see if I can't generate them there as well.

As an aside, on Mac the premake5 binary that's downloaded is for x86_64. You'll have to brew install a native version and replace the downloaded one. Also, build/llvm/LLVM.lua needs to be updated to include AArch64 in LLVM_TARGETS_TO_BUILD

Also, the following must be added to LLVM.lua's links definition:

      "LLVMAArch64AsmParser",
      "LLVMAArch64CodeGen",
      "LLVMAArch64Desc",
      "LLVMAArch64Disassembler",
      "LLVMAArch64Info",
      "LLVMAArch64Utils",

@tritao
Copy link
Collaborator

tritao commented Feb 2, 2024

Btw, we have LLVM builds on CI here: https://github.com/mono/CppSharp/actions/workflows/llvm.yml

Would be nice to add a new configuration here too: https://github.com/mono/CppSharp/blob/main/.github/workflows/llvm.yml#L12

Then we can re-issue new LLVM builds which will give us new packages with the LLVMAArch64 libraries.

@konistehrad
Copy link
Contributor

Gotcha let me fork and make a couple changes while I'm in here.

@konistehrad
Copy link
Contributor

konistehrad commented Feb 2, 2024

I was able to build LLVM with AArch64 support, and patched a couple other files to allow generating the bindings. Unfortunately it failed, it seems the headers may be out of date.

C:\Users\conrad\Documents\CppSharp\build\headers\osx\include\sys/cdefs.h(763,2): error: Unsupported architecture

Is the headline error for Mac, I think the rest stem from that.

C:\Users\conrad\Documents\CppSharp\build\headers\x86_64-linux-gnu/usr/include\gnu/stubs.h(7,11): fatal: 'gnu/stubs-32.h' file not found

Is the error thrown when generating ARM64 linux bindings. We're close, but not quite it looks like.

@tritao
Copy link
Collaborator

tritao commented Feb 2, 2024

Hmm, I thought that could happen but was hoping to not be the case. That headers zipped package is probably almost a decade old at this point. You should be able to update the headers in the zip with a more recent copy from your local system.

Edit: Actually, from the error message, looks like it's fetching the x86_64 headers, which seems wrong. Check here: https://github.com/mono/CppSharp/blob/main/src/CppParser/ParserGen/ParserGen.cs#L96

@konistehrad
Copy link
Contributor

Got it. I’ll pull headers in a bit and re run.

@XzuluX
Copy link

XzuluX commented Mar 11, 2024

Just retried to build for arm64:

./build.sh build_llvm --platform arm64
./build.sh package_llvm --platform arm64
./build.sh generate -configuration Release -platform arm64

run the build:
./build.sh -configuration Release -platform arm64

got following error:

make: Entering directory '/home/station/repos/CppSharp/build/gmake'
==== Building CppSharp.CppParser (release_arm64) ====
==== Building Std-symbols (release_arm64) ====
make[1]: *** No rule to make target '../../../src/CppParser/Bindings/CSharp/arm64-linux-gnu-cxx11abi/Std-symbols.cpp', needed by '../../obj/Std-symbols/Release/Std-symbols.o'. Stop.
make: *** [Makefile:60: Std-symbols] Error 2

I think the ABI for arm64-linux-gnu-cxx11abi is missing in src/CppParser/Bindings/CSharp. How do I obtain or create the ABI ?

@tritao
Copy link
Collaborator

tritao commented Mar 11, 2024

@XzuluX It was being worked on here: #1825
But is on pause right now, would be great if someone else can pick up the effort up.

@XzuluX
Copy link

XzuluX commented Mar 11, 2024

@tritao I don't have a clear understanding of what still needs to be done. Do you have any hints?

@tritao
Copy link
Collaborator

tritao commented Mar 11, 2024

Not sure, but its my understanding there were still failures to fix. @konistehrad, you said in the PR that you might provide some assistance to whoever picks this up, could you provide a summary of what needs to be done?

@konistehrad
Copy link
Contributor

konistehrad commented Mar 11, 2024

It's a little tough for me to say. I was able to build the LLVM instances, I created a new headers package, and built CppSharp against them. Attempting to use the created build artifacts seemingly always results in segfaults, and unfortunately I was never able to run down the source of that error. It doesn't appear to be a problem with the calling convention, but I never got far enough to conclusively determine that. Sorry I couldn't be more help.

@tritao
Copy link
Collaborator

tritao commented Mar 11, 2024

No worries, thanks for all the time you've put into it so far, hopefully someone else can take the mantle and continue from where you've left off.

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

5 participants