Skip to content

Commit

Permalink
Merge pull request #138 from Faless/linux/arms
Browse files Browse the repository at this point in the history
[Linux] Add arm32/arm64 linux builds support
  • Loading branch information
Faless authored Feb 15, 2024
2 parents 7141bc4 + 34ef104 commit 762365d
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 24 deletions.
54 changes: 39 additions & 15 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,32 @@ jobs:
# Linux
- platform: linux
arch: 'x86_32'
buildroot: 'i686'
buildroot: 'i686-godot-linux-gnu_sdk-buildroot'
gdnative_flags: 'bits=32'
sconsflags: ''
os: 'ubuntu-20.04'
cache-name: linux-x86_32
- platform: linux
arch: 'x86_64'
buildroot: 'x86_64'
buildroot: 'x86_64-godot-linux-gnu_sdk-buildroot'
gdnative_flags: 'bits=64'
sconsflags: ''
os: 'ubuntu-20.04'
cache-name: linux-x86_64
- platform: linux
arch: 'arm32'
buildroot: 'arm-godot-linux-gnueabihf_sdk-buildroot'
gdnative_flags: 'bits=32'
sconsflags: ''
os: 'ubuntu-20.04'
cache-name: linux-arm32
- platform: linux
arch: 'arm64'
buildroot: 'aarch64-godot-linux-gnu_sdk-buildroot'
gdnative_flags: 'bits=64'
sconsflags: ''
os: 'ubuntu-20.04'
cache-name: linux-arm64

# macOS
- platform: macos
Expand Down Expand Up @@ -144,26 +158,20 @@ jobs:
dpkg -l | grep ii | grep mingw
update-alternatives --get-selections | grep mingw
- name: Install Linux build dependencies
if: ${{ matrix.platform == 'linux' }}
run: |
sudo apt-get update
sudo apt-get install build-essential gcc-multilib g++-multilib wget
- name: Setup Linux buildroot toolchain cache
if: ${{ matrix.platform == 'linux' }}
uses: actions/cache@v4
with:
path: |
${{ matrix.buildroot }}-godot-linux-gnu_sdk-buildroot.tar.bz2
${{ matrix.buildroot }}.tar.bz2
key: linux-${{ matrix.buildroot }}-buildroot

- name: Install Linux build dependencies
if: ${{ matrix.platform == 'linux' }}
run: |
sudo apt-get update
sudo apt-get install build-essential gcc-multilib g++-multilib wget
if [ ! -f ${{ matrix.buildroot }}-godot-linux-gnu_sdk-buildroot.tar.bz2 ]; then
wget https://downloads.tuxfamily.org/godotengine/toolchains/linux/${{ matrix.buildroot }}-godot-linux-gnu_sdk-buildroot.tar.bz2
fi
tar -xjf ${{ matrix.buildroot }}-godot-linux-gnu_sdk-buildroot.tar.bz2
echo "$GITHUB_WORKSPACE/${{ matrix.buildroot }}-godot-linux-gnu_sdk-buildroot/bin" >> $GITHUB_PATH
patch -p1 < misc/patches/scons_path.diff
- name: Set up Python 3.x
uses: actions/setup-python@v5
with:
Expand All @@ -174,6 +182,22 @@ jobs:
run: |
python -c "import sys; print(sys.version)"
python -m pip install scons
- name: Setup Linux toolchains
if: ${{ matrix.platform == 'linux' }}
run: |
if [ ! -f ${{ matrix.buildroot }}.tar.bz2 ]; then
wget https://downloads.tuxfamily.org/godotengine/toolchains/linux/${{ matrix.buildroot }}.tar.bz2
fi
tar -xjf ${{ matrix.buildroot }}.tar.bz2
${{ matrix.buildroot }}/relocate-sdk.sh
echo "$GITHUB_WORKSPACE/${{ matrix.buildroot }}/bin" >> $GITHUB_PATH
echo "PKG_CONFIG=$GITHUB_WORKSPACE/${{ matrix.buildroot }}/share/pkgconfig/" >> $GITHUB_ENV
patch -p1 < misc/patches/scons_path.diff
patch -p1 < misc/patches/gdnantive_arm_warnings.diff
- name: Print tools versions
run: |
python --version
scons --version
cmake --version
Expand Down
18 changes: 13 additions & 5 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ def add_sources(sources, dirpath, extension):

def replace_flags(flags, replaces):
for k, v in replaces.items():
if k in flags:
if k not in flags:
continue
if v is None:
flags.remove(k)
else:
flags[flags.index(k)] = v


Expand All @@ -33,11 +37,11 @@ if env["godot_version"] == "3":
if "platform" in ARGUMENTS and ARGUMENTS["platform"] == "macos":
ARGUMENTS["platform"] = "osx" # compatibility with old osx name

env = SConscript("godot-cpp-3.x/SConstruct")
cpp_env = SConscript("godot-cpp-3.x/SConstruct")

# Patch base env
replace_flags(
env["CCFLAGS"],
cpp_env["CCFLAGS"],
{
"-mios-simulator-version-min=10.0": "-mios-simulator-version-min=11.0",
"-miphoneos-version-min=10.0": "-miphoneos-version-min=11.0",
Expand All @@ -46,7 +50,7 @@ if env["godot_version"] == "3":
},
)

env = env.Clone()
env = cpp_env.Clone()

if env["target"] == "debug":
env.Append(CPPDEFINES=["DEBUG_ENABLED"])
Expand All @@ -64,7 +68,7 @@ if env["godot_version"] == "3":

# Normalize suffix
if env["platform"] in ["windows", "linux"]:
env["arch"] = "x86_32" if env["bits"] == "32" else "x86_64"
env["arch"] = ARGUMENTS.get("arch", "x86_32" if env["bits"] == "32" else "x86_64")
env["arch_suffix"] = env["arch"]
elif env["platform"] == "macos":
env["arch"] = env["macos_arch"]
Expand Down Expand Up @@ -96,6 +100,10 @@ if env["godot_version"] == "3":
elif not env["use_mingw"]:
# Mark as MSVC build (would have failed to build the library otherwise).
env["is_msvc"] = True
# Some linux specific hacks to allow cross-compiling for non-x86 machines.
if env["platform"] == "linux" and env["arch"] not in ("x86_32", "x86_64"):
for flags in (env["CCFLAGS"], env["LINKFLAGS"], cpp_env["CCFLAGS"], cpp_env["LINKFLAGS"]):
replace_flags(flags, {"-m32": None, "-m64": None})
elif env["godot_version"] == "4.0":
env = SConscript("godot-cpp-4.0/SConstruct").Clone()
else:
Expand Down
34 changes: 34 additions & 0 deletions misc/patches/gdnantive_arm_warnings.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/godot-cpp-3.x/godot-headers/gdnative/gdnative.h b/godot-cpp-3.x/godot-headers/gdnative/gdnative.h
index c0573d21b5d7a..ec95c4c4ebfcc 100644
--- a/godot-cpp-3.x/godot-headers/gdnative/gdnative.h
+++ b/godot-cpp-3.x/godot-headers/gdnative/gdnative.h
@@ -37,20 +37,24 @@ extern "C" {

#if defined(_WIN32) || defined(__ANDROID__)
#define GDCALLINGCONV
-#define GDAPI GDCALLINGCONV
+
#elif defined(__APPLE__)
#include "TargetConditionals.h"
#if TARGET_OS_IPHONE
#define GDCALLINGCONV __attribute__((visibility("default")))
-#define GDAPI GDCALLINGCONV
#elif TARGET_OS_MAC
#define GDCALLINGCONV __attribute__((sysv_abi))
-#define GDAPI GDCALLINGCONV
#endif
-#else // !_WIN32 && !__APPLE__
+
+#else // Linux/BSD/Web
+#if defined(__aarch64__) || defined(__arm__)
+#define GDCALLINGCONV
+#else
#define GDCALLINGCONV __attribute__((sysv_abi))
-#define GDAPI GDCALLINGCONV
#endif
+#endif
+
+#define GDAPI GDCALLINGCONV

// This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!!
#if !defined(GDN_EXPORT)
2 changes: 2 additions & 0 deletions misc/scripts/file_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ for f in "${files[@]}"; do
continue
elif [[ "$f" == "thirdparty/"* ]]; then
continue
elif [[ "$f" == "misc/patches/"* ]]; then
continue
elif [[ "$f" == *"/thirdparty/"* ]]; then
continue
elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then
Expand Down
12 changes: 8 additions & 4 deletions misc/webrtc.tres
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ reloadable = false
entry/OSX.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.macos.{TARGET}.universal.dylib"
entry/Windows.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.windows.{TARGET}.x86_64.dll"
entry/Windows.32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.windows.{TARGET}.x86_32.dll"
entry/X11.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_64.so"
entry/X11.32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_32.so"
entry/Server.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_64.so"
entry/Server.32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_32.so"
entry/X11.64.x86_64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_64.so"
entry/X11.32.x86_32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_32.so"
entry/X11.64.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.arm64.so"
entry/X11.32.arm32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.arm32.so"
entry/Server.64.x86_64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_64.so"
entry/Server.32.x86_32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_32.so"
entry/Server.64.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.arm64.so"
entry/Server.32.arm32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.arm32.so"
entry/Android.arm64-v8a = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.arm64.so"
entry/Android.x64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.x86_64.so"
entry/iOS.armv7 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.armv32.dylib"
Expand Down
2 changes: 2 additions & 0 deletions tools/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def cmake_default_flags(env):
linux_flags = {
"x86_64": "-m64",
"x86_32": "-m32",
"arm32": "-march=armv7-a",
"arm64": "-march=armv8-a",
}.get(env["arch"], "")
if linux_flags:
config["CMAKE_C_FLAGS"] = linux_flags
Expand Down

0 comments on commit 762365d

Please sign in to comment.