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

Compile support for iOS & Android #9

Open
oix7 opened this issue Oct 23, 2023 · 7 comments
Open

Compile support for iOS & Android #9

oix7 opened this issue Oct 23, 2023 · 7 comments
Labels
help wanted Extra attention is needed

Comments

@oix7
Copy link

oix7 commented Oct 23, 2023

Hello, I noticed you have static libraries for mac/linux/windows, can you also include for ios and android targets please?

@BeanCheeseBurrito
Copy link
Owner

I will look into adding them!

@BeanCheeseBurrito BeanCheeseBurrito added the help wanted Extra attention is needed label Oct 27, 2023
@BeanCheeseBurrito
Copy link
Owner

BeanCheeseBurrito commented Oct 27, 2023

Flecs.NET uses zig to cross-compile native libraries for all target platforms. Trying to compile flecs with -Dtarget=aarch64-linux-android or -Dtarget=aarch64-ios doesn't seem to work out of the box due to missing headers. I'm assuming zig doesn't include them for those targets.

fatal error: 'assert.h' file not found

I'm not familiar enough with c/c++ and mobile development to get the build script to compile for those platforms but I'm open to contributions if anyone knows how to get it working. These are the relevant files for anyone interested in adding support for mobile targets.

https://github.com/BeanCheeseBurrito/Flecs.NET/blob/main/src/Flecs.NET.Native/build.zig
https://github.com/BeanCheeseBurrito/Flecs.NET/blob/main/src/Flecs.NET.Native/Flecs.NET.Native.csproj

@oix7
Copy link
Author

oix7 commented Oct 27, 2023

Thanks! Can we avoid exotic targets like linux android for now and just add the more vanilla stuff that zig does support? Or for modern ios at least?
ziglang/zig#5145

@oix7
Copy link
Author

oix7 commented Oct 27, 2023

@BeanCheeseBurrito
Copy link
Owner

Thanks! Can we avoid exotic targets like linux android for now and just add the more vanilla stuff that zig does support? Or for modern ios at least? ziglang/zig#5145

Zig doesn't provide(?) the headers needed to cross-compile for android and ios. The build script needs to be changed to allow the user to manually provide them but I'm not experienced enough with mobile development to set it up myself.

@oix7
Copy link
Author

oix7 commented Oct 29, 2023

In case it helps, I made this example github action that will output a static library via https://github.com/leetal/ios-cmake without needing any code signing.

name: Build Flecs for iOS

on:
  push:
    tags:
      - 'v*'
  workflow_dispatch:

jobs:
  build:
    runs-on: macos-latest
    strategy:
      matrix:
        config: [Debug, Release]
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        
      - name: Setup environment
        run: |
          echo "FLECS_REPO=https://github.com/SanderMertens/flecs.git" >> $GITHUB_ENV
          echo "FLECS_DIR=$GITHUB_WORKSPACE/flecs" >> $GITHUB_ENV
          echo "DEBUG_DIR=$GITHUB_WORKSPACE/build_ios/debug" >> $GITHUB_ENV
          echo "RELEASE_DIR=$GITHUB_WORKSPACE/build_ios/release" >> $GITHUB_ENV
          echo "TOOLCHAIN_FILE=$GITHUB_WORKSPACE/ios.toolchain.cmake" >> $GITHUB_ENV
          
      - name: Clone Flecs Repository
        run: git clone ${{ env.FLECS_REPO }} ${{ env.FLECS_DIR }}
          
      - name: Download dependencies
        run: |
          if [ ! -f "$TOOLCHAIN_FILE" ]; then
            curl -O https://raw.githubusercontent.com/leetal/ios-cmake/master/ios.toolchain.cmake
          fi
          
      - name: Build static library
        run: |
          mkdir -p $DEBUG_DIR
          mkdir -p $RELEASE_DIR
          cd $DEBUG_DIR
          cmake -DCMAKE_BUILD_TYPE=Debug $FLECS_DIR
          make
          mv libflecs_static.a libflecs.a
          cd $RELEASE_DIR
          cmake -DCMAKE_BUILD_TYPE=Release $FLECS_DIR
          make
          mv libflecs_static.a libflecs.a
          
      - name: Upload artifact (Debug)
        if: matrix.config == 'Debug'
        uses: actions/upload-artifact@v2
        with:
          name: libflecs-debug
          path: ${{ env.DEBUG_DIR }}/libflecs.a
          
      - name: Upload artifact (Release)
        if: matrix.config == 'Release'
        uses: actions/upload-artifact@v2
        with:
          name: libflecs-release
          path: ${{ env.RELEASE_DIR }}/libflecs.a

@BeanCheeseBurrito
Copy link
Owner

IOS static libraries were added in the latest package pushed to the GitLab feed. https://gitlab.com/BeanCheeseBurrito/Flecs.NET/-/packages/20154174

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants