Skip to content

Commit 9d5caf6

Browse files
authored
Merge pull request #636 from Faless/build/tools_pr
Android/iOS build, Scons boilerplate for building projects.
2 parents 75b180d + 90b7d05 commit 9d5caf6

File tree

3 files changed

+112
-270
lines changed

3 files changed

+112
-270
lines changed

.github/workflows/ci.yml

Lines changed: 71 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,52 @@ name: Continuous integration
22
on: [push, pull_request]
33

44
jobs:
5-
linux:
6-
name: Build (Linux, GCC)
7-
runs-on: ubuntu-18.04
5+
build:
6+
name: ${{ matrix.name }}
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
include:
12+
- name: 🐧 Linux (GCC)
13+
os: ubuntu-18.04
14+
platform: linux
15+
artifact-name: godot-cpp-linux-glibc2.27-x86_64-release
16+
artifact-path: bin/libgodot-cpp.linux.release.64.a
17+
18+
- name: 🏁 Windows (x86_64, MSVC)
19+
os: windows-2019
20+
platform: windows
21+
artifact-name: godot-cpp-windows-msvc2019-x86_64-release
22+
artifact-path: bin/libgodot-cpp.windows.release.64.lib
23+
24+
- name: 🏁 Windows (x86_64, MinGW)
25+
os: windows-2019
26+
platform: windows
27+
artifact-name: godot-cpp-linux-mingw-x86_64-release
28+
artifact-path: bin/libgodot-cpp.windows.release.64.a
29+
flags: use_mingw=yes
30+
31+
- name: 🍎 macOS (universal)
32+
os: macos-11
33+
platform: osx
34+
artifact-name: godot-cpp-macos-universal-release
35+
artifact-path: bin/libgodot-cpp.osx.release.universal.a
36+
flags: macos_arch=universal
37+
38+
- name: 🤖 Android (arm64)
39+
os: ubuntu-18.04
40+
platform: android
41+
artifact-name: godot-cpp-android-arm64-release
42+
artifact-path: bin/libgodot-cpp.android.release.arm64v8.a
43+
flags: android_arch=arm64v8
44+
45+
- name: 🍏 iOS (arm64)
46+
os: macos-11
47+
platform: ios
48+
artifact-name: godot-cpp-ios-arm64-release
49+
artifact-path: bin/libgodot-cpp.ios.release.arm64.a
50+
851
steps:
952
- name: Checkout
1053
uses: actions/checkout@v2
@@ -16,26 +59,44 @@ jobs:
1659
with:
1760
python-version: '3.x'
1861

19-
- name: Install dependencies
62+
- name: Linux dependencies
63+
if: ${{ matrix.platform == 'linux' }}
2064
run: |
2165
sudo apt-get update -qq
2266
sudo apt-get install -qqq build-essential pkg-config
67+
68+
- name: Install scons
69+
run: |
2370
python -m pip install scons
2471
25-
- name: Build godot-cpp
72+
- name: Windows GCC dependency
73+
if: ${{ matrix.platform == 'windows' }}
74+
# Install GCC from Scoop as the default supplied GCC doesn't work ("Error 1").
2675
run: |
27-
scons target=release generate_bindings=yes -j $(nproc)
76+
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
77+
scoop install gcc
78+
g++ --version
79+
gcc --version
2880
29-
- name: Build test project
81+
- name: Build godot-cpp (debug)
82+
run: |
83+
scons platform=${{ matrix.platform }} target=debug generate_bindings=yes ${{ matrix.flags }} -j2
84+
85+
- name: Build test without rebuilding godot-cpp (debug)
86+
run: |
87+
cd test
88+
scons platform=${{ matrix.platform }} target=debug ${{ matrix.flags }} build_library=no -j2
89+
90+
- name: Build test and godot-cpp (release)
3091
run: |
3192
cd test
32-
scons target=release -j $(nproc)
93+
scons platform=${{ matrix.platform }} target=release ${{ matrix.flags }} -j2
3394
3495
- name: Upload artifact
3596
uses: actions/upload-artifact@v2
3697
with:
37-
name: godot-cpp-linux-glibc2.27-x86_64-release
38-
path: bin/libgodot-cpp.linux.release.64.a
98+
name: ${{ matrix.artifact-name }}
99+
path: ${{ matrix.artifact-path }}
39100
if-no-files-found: error
40101

41102
linux-cmake:
@@ -86,106 +147,6 @@ jobs:
86147
cd test && cmake -DCMAKE_BUILD_TYPE=Release -GNinja .
87148
cmake --build . -j $(nproc)
88149
89-
windows-msvc:
90-
name: Build (Windows, MSVC)
91-
runs-on: windows-2019
92-
steps:
93-
- name: Checkout
94-
uses: actions/checkout@v2
95-
with:
96-
submodules: recursive
97-
98-
- name: Set up Python (for SCons)
99-
uses: actions/setup-python@v2
100-
with:
101-
python-version: '3.x'
102-
103-
- name: Install dependencies
104-
run: |
105-
python -m pip install scons
106-
107-
- name: Build godot-cpp
108-
run: |
109-
scons target=release generate_bindings=yes -j $env:NUMBER_OF_PROCESSORS
110-
111-
- name: Build test project
112-
run: |
113-
cd test
114-
scons target=release -j $env:NUMBER_OF_PROCESSORS
115-
116-
- name: Upload artifact
117-
uses: actions/upload-artifact@v2
118-
with:
119-
name: godot-cpp-windows-msvc2019-x86_64-release
120-
path: bin/libgodot-cpp.windows.release.64.lib
121-
if-no-files-found: error
122-
123-
windows-mingw:
124-
name: Build (Windows, MinGW)
125-
runs-on: windows-2019
126-
steps:
127-
- name: Checkout
128-
uses: actions/checkout@v2
129-
with:
130-
submodules: recursive
131-
132-
- name: Set up Python (for SCons)
133-
uses: actions/setup-python@v2
134-
with:
135-
python-version: '3.x'
136-
137-
- name: Install dependencies
138-
run: |
139-
python -m pip install scons
140-
141-
- name: Build godot-cpp
142-
# Install GCC from Scoop as the default supplied GCC doesn't work ("Error 1").
143-
run: |
144-
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
145-
scoop install gcc
146-
g++ --version
147-
gcc --version
148-
scons target=release generate_bindings=yes use_mingw=yes -j $env:NUMBER_OF_PROCESSORS
149-
150-
#- name: Build test project (TODO currently not supported, leaving uncommented as a reminder to fix this)
151-
# run: |
152-
# cd test
153-
# scons target=release use_mingw=yes -j $env:NUMBER_OF_PROCESSORS
154-
155-
- name: Upload artifact
156-
uses: actions/upload-artifact@v2
157-
with:
158-
name: godot-cpp-linux-mingw-x86_64-release
159-
path: bin/libgodot-cpp.windows.release.64.a
160-
if-no-files-found: error
161-
162-
macos:
163-
name: Build (macOS, Clang, universal / x86_64 + arm64)
164-
runs-on: macos-11
165-
steps:
166-
- name: Checkout
167-
uses: actions/checkout@v2
168-
with:
169-
submodules: recursive
170-
171-
- name: Set up Python (for SCons)
172-
uses: actions/setup-python@v2
173-
with:
174-
python-version: '3.x'
175-
176-
- name: Install dependencies
177-
run: |
178-
python -m pip install scons
179-
180-
- name: Build godot-cpp
181-
run: |
182-
scons target=release generate_bindings=yes -j $(sysctl -n hw.logicalcpu)
183-
184-
- name: Build test project
185-
run: |
186-
cd test
187-
scons target=release -j $(sysctl -n hw.logicalcpu)
188-
189150
static-checks:
190151
name: Static Checks (clang-format)
191152
runs-on: ubuntu-20.04

SConstruct

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ opts.Add(
144144
)
145145
opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True))
146146

147+
opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))
148+
opts.Add("build_projects", "List of projects to build (comma-separated list of paths).", "")
149+
147150
opts.Update(env)
148151
Help(opts.GenerateHelpText(env))
149152

@@ -165,14 +168,21 @@ if host_platform == "windows" and env["platform"] != "android":
165168

166169
opts.Update(env)
167170

171+
# Require C++17
172+
if host_platform == "windows" and env["platform"] == "windows" and not env["use_mingw"]:
173+
# MSVC
174+
env.Append(CCFLAGS=["/std:c++17"])
175+
else:
176+
env.Append(CCFLAGS=["-std=c++17"])
177+
168178
if env["target"] == "debug":
169179
env.Append(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"])
170180

171181
if env["platform"] == "linux" or env["platform"] == "freebsd":
172182
if env["use_llvm"]:
173183
env["CXX"] = "clang++"
174184

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

178188
if env["target"] == "debug":
@@ -201,8 +211,6 @@ elif env["platform"] == "osx":
201211
env.Append(LINKFLAGS=["-arch", env["macos_arch"]])
202212
env.Append(CCFLAGS=["-arch", env["macos_arch"]])
203213

204-
env.Append(CCFLAGS=["-std=c++17"])
205-
206214
if env["macos_deployment_target"] != "default":
207215
env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
208216
env.Append(LINKFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
@@ -245,14 +253,13 @@ elif env["platform"] == "ios":
245253
env["CXX"] = compiler_path + "clang++"
246254
env["AR"] = compiler_path + "ar"
247255
env["RANLIB"] = compiler_path + "ranlib"
256+
env["SHLIBSUFFIX"] = ".dylib"
248257

249-
env.Append(CCFLAGS=["-std=c++17", "-arch", env["ios_arch"], "-isysroot", sdk_path])
258+
env.Append(CCFLAGS=["-arch", env["ios_arch"], "-isysroot", sdk_path])
250259
env.Append(
251260
LINKFLAGS=[
252261
"-arch",
253262
env["ios_arch"],
254-
"-framework",
255-
"Cocoa",
256263
"-Wl,-undefined,dynamic_lookup",
257264
"-isysroot",
258265
sdk_path,
@@ -292,14 +299,21 @@ elif env["platform"] == "windows":
292299
# Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
293300
env = Environment(ENV=os.environ, tools=["mingw"])
294301
opts.Update(env)
295-
# env = env.Clone(tools=['mingw'])
296302

303+
# Still need to use C++17.
304+
env.Append(CCFLAGS=["-std=c++17"])
305+
# Don't want lib prefixes
306+
env["IMPLIBPREFIX"] = ""
307+
env["SHLIBPREFIX"] = ""
308+
309+
# Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
297310
env["SPAWN"] = mySpawn
311+
env.Replace(ARFLAGS=["q"])
298312

299313
# Native or cross-compilation using MinGW
300314
if host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx" or env["use_mingw"]:
301315
# These options are for a release build even using target=debug
302-
env.Append(CCFLAGS=["-O3", "-std=c++17", "-Wwrite-strings"])
316+
env.Append(CCFLAGS=["-O3", "-Wwrite-strings"])
303317
env.Append(
304318
LINKFLAGS=[
305319
"--static",
@@ -314,9 +328,10 @@ elif env["platform"] == "android":
314328
# Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
315329
env = Environment(ENV=os.environ, tools=["mingw"])
316330
opts.Update(env)
317-
# env = env.Clone(tools=['mingw'])
318331

332+
# Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
319333
env["SPAWN"] = mySpawn
334+
env.Replace(ARFLAGS=["q"])
320335

321336
# Verify NDK root
322337
if not "ANDROID_NDK_ROOT" in env:
@@ -382,11 +397,13 @@ elif env["platform"] == "android":
382397
env["CC"] = toolchain + "/bin/clang"
383398
env["CXX"] = toolchain + "/bin/clang++"
384399
env["AR"] = toolchain + "/bin/" + arch_info["tool_path"] + "-ar"
400+
env["SHLIBSUFFIX"] = ".so"
385401

386402
env.Append(
387403
CCFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"], "-fPIC"]
388404
) # , '-fPIE', '-fno-addrsig', '-Oz'])
389405
env.Append(CCFLAGS=arch_info["ccflags"])
406+
env.Append(LINKFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"]])
390407

391408
if env["target"] == "debug":
392409
env.Append(CCFLAGS=["-Og", "-g"])
@@ -474,8 +491,16 @@ elif env["platform"] == "javascript":
474491
elif env["platform"] == "osx":
475492
arch_suffix = env["macos_arch"]
476493

477-
library = env.StaticLibrary(
478-
target="bin/" + "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["LIBSUFFIX"]),
479-
source=sources,
480-
)
481-
Default(library)
494+
library = None
495+
env["OBJSUFFIX"] = ".{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["OBJSUFFIX"])
496+
library_name = "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["LIBSUFFIX"])
497+
498+
if env["build_library"]:
499+
library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources)
500+
Default(library)
501+
502+
env["SHLIBSUFFIX"] = "{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["SHLIBSUFFIX"])
503+
env.Append(CPPPATH=[env.Dir(f) for f in ["gen/include", "include", "godot-headers"]])
504+
env.Append(LIBPATH=[env.Dir("bin")])
505+
env.Append(LIBS=library_name)
506+
Return("env")

0 commit comments

Comments
 (0)