Skip to content

Commit

Permalink
Hide unused symbols in unix libraries
Browse files Browse the repository at this point in the history
manually added android ndk r23
  • Loading branch information
DmitriySalnikov committed Nov 20, 2023
1 parent 725c92f commit 4b0586f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/actions/compile_gdextension/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ runs:
run: |
echo "::group::🛠️ GDExtesion Compilation 🛠️"
cd godot-cpp
git apply --ignore-space-change --ignore-whitespace ../patches/visibilty_hidden.patch
git apply --ignore-space-change --ignore-whitespace ../patches/godot_cpp_exclude_unused_classes.patch
git apply --ignore-space-change --ignore-whitespace ../patches/unity_build.patch
cd ..
Expand Down
24 changes: 23 additions & 1 deletion .github/workflows/gdextension_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,37 @@ jobs:
lfs: true
submodules: recursive

- name: Install Android NDK r23
uses: nttld/setup-ndk@v1.4.1
id: setup-ndk
with:
ndk-version: r23
add-to-path: true
local-cache: true

# TODO revisit after some updates of nttld/setup-ndk
- name: Restore Android Symlinks
run: |
directory="${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin"
find "$directory" -type l | while read link; do
current_target=$(readlink "$link")
new_target="$directory/$(basename "$current_target")"
ln -sf "$new_target" "$link"
echo "Changed $(basename "$link") from $current_target to $new_target"
done
- name: Compile GDExtension
uses: ./.github/actions/compile_gdextension
env:
ANDROID_NDK_ROOT: ${{ steps.setup-ndk.outputs.ndk-path }}
with:
platform: android
target: ${{matrix.target}}
arch: ${{matrix.arch}}
output_libs_path: ${{env.OUTPUT_LIBS_PATH}}
artifact: android
additional: lto=yes
additional: lto=yes ANDROID_HOME=""

# ============================================

Expand Down
1 change: 1 addition & 0 deletions dev_build_godot_cpp.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cd godot-cpp
::set api=custom_api_file="../api.json"
set api=

git apply --ignore-space-change --ignore-whitespace ../patches/visibilty_hidden.patch
git apply --ignore-space-change --ignore-whitespace ../patches/godot_cpp_exclude_unused_classes.patch
git apply --ignore-space-change --ignore-whitespace ../patches/unity_build.patch
::git apply --ignore-space-change --ignore-whitespace ../patches/debug_string.patch
Expand Down
35 changes: 35 additions & 0 deletions patches/visibilty_hidden.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
diff --git a/tools/godotcpp.py b/tools/godotcpp.py
index efe632a..46d64fb 100644
--- a/tools/godotcpp.py
+++ b/tools/godotcpp.py
@@ -183,6 +183,15 @@ def options(opts, env):
)
)

+ opts.Add(
+ EnumVariable(
+ key="symbols_visibility",
+ help="Symbols visibility on GNU platforms. Use 'auto' to apply the default values.",
+ default=env.get("symbols_visibility", "hidden"),
+ allowed_values=["auto", "visible", "hidden"],
+ )
+ )
+
# Add platform options
for pl in platforms:
tool = Tool(pl, toolpath=["tools"])
@@ -258,6 +267,14 @@ def generate(env):
elif env.get("is_msvc", False):
env.Append(CXXFLAGS=["/EHsc"])

+ if not env.get("is_msvc", False):
+ if env["symbols_visibility"] == "visible":
+ env.Append(CCFLAGS=["-fvisibility=default"])
+ env.Append(LINKFLAGS=["-fvisibility=default"])
+ elif env["symbols_visibility"] == "hidden":
+ env.Append(CCFLAGS=["-fvisibility=hidden"])
+ env.Append(LINKFLAGS=["-fvisibility=hidden"])
+
# Require C++17
if env.get("is_msvc", False):
env.Append(CXXFLAGS=["/std:c++17"])

0 comments on commit 4b0586f

Please sign in to comment.