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

Add scons boilerplate for building library and test on Android/iOS, add them to CI. #635

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 57 additions & 116 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,52 @@ name: Continuous integration
on: [push, pull_request]

jobs:
linux:
name: Build (Linux, GCC)
runs-on: ubuntu-18.04
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: 🐧 Linux (GCC)
os: ubuntu-18.04
platform: linux
artifact-name: godot-cpp-linux-glibc2.27-x86_64-release
artifact-path: bin/libgodot-cpp.linux.release.64.a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these artifact names and paths make sense? it's not the libgodot-cpp that forms the artifact of the plugin itself.
We probably need to store the name of the library and its path somewhere at the top in a variable and then reuse it to build the final artifact name so it's easy to update the CI for your own library

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually thinking about this, we'll also need to add something to build the deliverable. I still want to do this for the godot-cpp CI as well, where we gather all header files and all compiled libraries and combine them in a downloadable library zip.

Have a look at https://github.com/GodotVR/godot_openxr/blob/master/.github/workflows/build-on-push.yml#L143 for an example of how we currently do this for OpenXR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I suddenly realise the top remark is DUMB because offcourse we build both the godot-cpp and the test library in CI here :( Sorry I just woke up


- name: 🏁 Windows (x86_64, MSVC)
os: windows-2019
platform: windows
artifact-name: godot-cpp-windows-msvc2019-x86_64-release
artifact-path: bin/libgodot-cpp.windows.release.64.lib

- name: 🏁 Windows (x86_64, MinGW)
os: windows-2019
platform: windows
artifact-name: godot-cpp-linux-mingw-x86_64-release
artifact-path: bin/libgodot-cpp.windows.release.64.a
flags: use_mingw=yes

- name: 🍎 macOS (universal)
os: macos-11
platform: osx
artifact-name: godot-cpp-macos-universal-release
artifact-path: bin/libgodot-cpp.osx.release.universal.a
flags: macos_arch=universal

- name: 🤖 Android (arm64)
os: ubuntu-18.04
platform: android
artifact-name: godot-cpp-android-arm64-release
artifact-path: bin/libgodot-cpp.android.release.arm64v8.a
flags: android_arch=arm64v8

- name: 🍏 iOS (arm64)
os: macos-11
platform: ios
artifact-name: godot-cpp-ios-arm64-release
artifact-path: bin/libgodot-cpp.ios.release.arm64.a

steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -16,142 +59,40 @@ jobs:
with:
python-version: '3.x'

- name: Install dependencies
- name: Linux dependencies
if: ${{ matrix.platform == 'linux' }}
run: |
sudo apt-get update -qq
sudo apt-get install -qqq build-essential pkg-config
python -m pip install scons

- name: Build godot-cpp
run: |
scons target=release generate_bindings=yes -j $(nproc)

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: godot-cpp-linux-glibc2.27-x86_64-release
path: bin/libgodot-cpp.linux.release.64.a
if-no-files-found: error

windows-msvc:
name: Build (Windows, MSVC)
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up Python (for SCons)
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
- name: Install scons
run: |
python -m pip install scons

- name: Build godot-cpp
run: |
scons target=release generate_bindings=yes -j $env:NUMBER_OF_PROCESSORS

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: godot-cpp-windows-msvc2019-x86_64-release
path: bin/libgodot-cpp.windows.release.64.lib
if-no-files-found: error

windows-mingw:
name: Build (Windows, MinGW)
runs-on: windows-2019
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up Python (for SCons)
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install scons

- name: Build godot-cpp
- name: Windows GCC dependency
if: ${{ matrix.platform == 'windows' }}
# Install GCC from Scoop as the default supplied GCC doesn't work ("Error 1").
run: |
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
scoop install gcc
g++ --version
gcc --version
scons target=release generate_bindings=yes use_mingw=yes -j $env:NUMBER_OF_PROCESSORS

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: godot-cpp-linux-mingw-x86_64-release
path: bin/libgodot-cpp.windows.release.64.a
if-no-files-found: error

macos:
name: Build (macOS, Clang)
runs-on: macos-10.15
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up Python (for SCons)
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
- name: Build godot-cpp
run: |
python -m pip install scons
scons platform=${{ matrix.platform }} target=release generate_bindings=yes ${{ matrix.flags }} -j2

- name: Build godot-cpp
- name: Build test
run: |
scons target=release generate_bindings=yes -j $(sysctl -n hw.logicalcpu)
scons -C test platform=${{ matrix.platform }} target=release ${{ matrix.flags }} -j2

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: godot-cpp-macos-x86_64-release
path: bin/libgodot-cpp.osx.release.64.a
name: ${{ matrix.artifact-name }}
path: ${{ matrix.artifact-path }}
if-no-files-found: error

macos-arm64:
name: Build (macOS, Clang, cross-compile arm64)
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up Python (for SCons)
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install scons

- name: Build godot-cpp
run: |
# The default SDK in github the actions environemnt seems to have problems compiling for arm64.
# Use the latest 11.x SDK.
SDK_BASE=/Library/Developer/CommandLineTools/SDKs
SDK_VER=$(ls $SDK_BASE | grep "MacOSX11." | sort -r | head -n1)
echo $SDK_BASE/$SDK_VER/
scons target=release generate_bindings=yes macos_arch=arm64 macos_deployment_target=10.15 macos_sdk_path="$SDK_BASE/$SDK_VER/" -j $(sysctl -n hw.logicalcpu)

static-checks:
name: Static Checks (clang-format)
runs-on: ubuntu-20.04
Expand Down
38 changes: 25 additions & 13 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ elif sys.platform == "darwin":
elif sys.platform == "win32" or sys.platform == "msys":
host_platform = "windows"
else:
raise ValueError("Could not detect platform automatically, please specify with " "platform=<platform>")
raise ValueError("Could not detect platform automatically, please specify with platform=<platform>")

env = Environment(ENV=os.environ)

Expand Down Expand Up @@ -124,7 +124,7 @@ opts.Add(
opts.Add(EnumVariable("android_arch", "Target Android architecture", "armv7", ["armv7", "arm64v8", "x86", "x86_64"]))
opts.Add("macos_deployment_target", "macOS deployment target", "default")
opts.Add("macos_sdk_path", "macOS SDK path", "")
opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "x86_64", ["x86_64", "arm64"]))
opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "universal", ["universal", "x86_64", "arm64"]))
opts.Add(EnumVariable("ios_arch", "Target iOS architecture", "arm64", ["armv7", "arm64", "x86_64"]))
opts.Add(BoolVariable("ios_simulator", "Target iOS Simulator", False))
opts.Add(
Expand All @@ -147,6 +147,13 @@ opts.Add(BoolVariable("generate_template_get_node", "Generate a template version
opts.Update(env)
Help(opts.GenerateHelpText(env))

# Require C++17
if host_platform == "windows" and env["platform"] == "windows" and not env["use_mingw"]:
# MSVC
env.Append(CCFLAGS=["/std:c++17"])
else:
env.Append(CCFLAGS=["-std=c++17"])

# This makes sure to keep the session environment variables on Windows.
# This way, you can run SCons in a Visual Studio 2017 prompt and it will find
# all the required tools
Expand All @@ -165,7 +172,7 @@ if env["platform"] == "linux" or env["platform"] == "freebsd":
if env["use_llvm"]:
env["CXX"] = "clang++"

env.Append(CCFLAGS=["-fPIC", "-std=c++17", "-Wwrite-strings"])
env.Append(CCFLAGS=["-fPIC", "-Wwrite-strings"])
env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])

if env["target"] == "debug":
Expand All @@ -187,7 +194,12 @@ elif env["platform"] == "osx":
if env["bits"] == "32":
raise ValueError("Only 64-bit builds are supported for the macOS target.")

env.Append(CCFLAGS=["-std=c++17", "-arch", env["macos_arch"]])
if env["macos_arch"] == "universal":
env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"])
env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"])
else:
env.Append(LINKFLAGS=["-arch", env["macos_arch"]])
env.Append(CCFLAGS=["-arch", env["macos_arch"]])

if env["macos_deployment_target"] != "default":
env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
Expand All @@ -199,8 +211,6 @@ elif env["platform"] == "osx":

env.Append(
LINKFLAGS=[
"-arch",
env["macos_arch"],
"-framework",
"Cocoa",
"-Wl,-undefined,dynamic_lookup",
Expand Down Expand Up @@ -234,13 +244,11 @@ elif env["platform"] == "ios":
env["AR"] = compiler_path + "ar"
env["RANLIB"] = compiler_path + "ranlib"

env.Append(CCFLAGS=["-std=c++17", "-arch", env["ios_arch"], "-isysroot", sdk_path])
env.Append(CCFLAGS=["-arch", env["ios_arch"], "-isysroot", sdk_path])
env.Append(
LINKFLAGS=[
"-arch",
env["ios_arch"],
"-framework",
"Cocoa",
"-Wl,-undefined,dynamic_lookup",
"-isysroot",
sdk_path,
Expand Down Expand Up @@ -280,14 +288,16 @@ elif env["platform"] == "windows":
# Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
env = Environment(ENV=os.environ, tools=["mingw"])
opts.Update(env)
# env = env.Clone(tools=['mingw'])

# Still need to use C++17.
env.Append(CCFLAGS=["-std=c++17"])

env["SPAWN"] = mySpawn

# Native or cross-compilation using MinGW
if host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx" or env["use_mingw"]:
# These options are for a release build even using target=debug
env.Append(CCFLAGS=["-O3", "-std=c++17", "-Wwrite-strings"])
env.Append(CCFLAGS=["-O3", "-Wwrite-strings"])
env.Append(
LINKFLAGS=[
"--static",
Expand Down Expand Up @@ -454,10 +464,12 @@ add_sources(sources, "gen/src/classes", "cpp")
arch_suffix = env["bits"]
if env["platform"] == "android":
arch_suffix = env["android_arch"]
if env["platform"] == "ios":
elif env["platform"] == "ios":
arch_suffix = env["ios_arch"]
if env["platform"] == "javascript":
elif env["platform"] == "javascript":
arch_suffix = "wasm"
elif env["platform"] == "osx":
arch_suffix = env["macos_arch"]

library = env.StaticLibrary(
target="bin/" + "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["LIBSUFFIX"]),
Expand Down
Loading