Compile support for iOS & Android
oix7 opened this issue · 7 comments
Hello, I noticed you have static libraries for mac/linux/windows, can you also include for ios and android targets please?
I will look into adding them!
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
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
- and maybe skip the ios simulator target too for simplicity, although it seems someone has done it before: https://github.com/kubkon/zig-ios-example
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.
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
IOS static libraries were added in the latest package pushed to the GitLab feed. https://gitlab.com/BeanCheeseBurrito/Flecs.NET/-/packages/20154174