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

How to install ldc for Mac Arm #51

Closed
aminya opened this issue Dec 30, 2021 · 5 comments
Closed

How to install ldc for Mac Arm #51

aminya opened this issue Dec 30, 2021 · 5 comments

Comments

@aminya
Copy link

aminya commented Dec 30, 2021

Does setup-dlang support ldc for Mac ARM?

@WebFreak001
Copy link
Member

there is a check that aborts the extension right now if you are not on x86_64:
https://github.com/dlang-community/setup-dlang/blob/v1/src/main.ts#L10

We don't have any devices outside the GitHub Actions runners, so we only have x86 runners and can't really test if the extension works on other architectures.

@aminya
Copy link
Author

aminya commented Dec 30, 2021

I am trying to cross-compile for Arm64 Mac. Ldc supports this if the correct environment variables are set.

Here is an example:
https://github.com/aminya/minijson/pull/23/files#diff-3ab46ee209a127470fce3c2cf106b1a1dbadbb929a4b5b13656a4bc4ce19c0b8R73

      - name: Setup Mac Arm64
        shell: bash
        if: contains(matrix.os, 'macos-11') 
        run: |
          ARCH="arm64"
          echo "ARCH=$ARCH" >> $GITHUB_ENV
          echo "triple=$ARCH-apple-macos" >> $GITHUB_ENV
          echo "DFLAGS='-mtriple=$triple -Xcc=target -Xcc=$ARCH-apple-macos'" >> $GITHUB_ENV
          echo "CPPFLAGS=$CPPFLAGS -arch $ARCH" >> $GITHUB_ENV
          echo "CFLAGS=$CFLAGS -arch $ARCH" >> $GITHUB_ENV
          echo "LDFLAGS=$LDFLAGS -arch $ARCH" >> $GITHUB_ENV

@WebFreak001
Copy link
Member

cross compiling to arm should be possible, though I haven't tried before.

It might be possible to run and include the output of the ldc-build-runtime tool in setup-dlang: https://wiki.dlang.org/Building_LDC_runtime_libraries

@aminya
Copy link
Author

aminya commented Dec 30, 2021

I am able to setup LDC for cross-compilation

      - name: Setup Mac Arm64
        shell: bash
        if: contains(matrix.os, 'macos-11')
        run: |
          ARCH="arm64"
          echo "ARCH=$ARCH" >> $GITHUB_ENV
          echo "triple=$ARCH-apple-macos" >> $GITHUB_ENV
          echo "DFLAGS='-mtriple=$triple -Xcc=target -Xcc=$ARCH-apple-macos'" >> $GITHUB_ENV
          echo "CPPFLAGS=$CPPFLAGS -arch $ARCH" >> $GITHUB_ENV
          echo "CFLAGS=$CFLAGS -arch $ARCH" >> $GITHUB_ENV
          echo "LDFLAGS=$LDFLAGS -arch $ARCH" >> $GITHUB_ENV

          # Manually install ldc 
          # Due to https://github.com/dlang-community/setup-dlang/issues/51
          curl -LJO https://github.com/ldc-developers/ldc/releases/download/v1.28.0/ldc2-1.28.0-osx-$ARCH.tar.xz
          tar -xf ldc2-1.28.0-osx-$ARCH.tar.xz
          rm ldc2-1.28.0-osx-$ARCH.tar.xz

          LDC_PATH="~/ldc"
          mkdir -p $LDC_PATH
          mv ldc2-1.28.0-osx-$ARCH $LDC_PATH

          # Activate ldc
          echo "LIBRARY_PATH=$LDC_PATH/lib${LIBRARY_PATH:+:}${LIBRARY_PATH:-}" >> $GITHUB_ENV
          echo "LD_LIBRARY_PATH=$LDC_PATH/lib${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH:-}" >> $GITHUB_ENV
          echo "PATH=$LDC_PATH/bin${PATH:+:}${PATH:-}" >> $GITHUB_ENV
          echo "DMD=ldmd2" >> $GITHUB_ENV
          echo "DC=ldc2" >> $GITHUB_ENV

However, it seems that dub support for arm64 is also missing. I might have to compile directly in this case.
aminya/minijson#23
https://github.com/aminya/minijson/runs/4667583537?check_suite_focus=true#step:10:25

@WebFreak001
Copy link
Member

cross compiling to arm should work like this now:

dub build --arch=arm64-apple-macos --build=release

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

2 participants