Skip to content

Commit bccb137

Browse files
committed
fix discord for flatpak
- don't require discord to run - fix some bad things with the prepackaged libraries of the discord sdk: it has no SONAME set, so linking add the absolut path instead of teh SONAME name, this causes the installed game to not work correctly, this is fixed by patching the .so and that requires some workarounds, since "patchelf" is not available in the sdk we use to build the flatpak app
1 parent 653d0e7 commit bccb137

File tree

6 files changed

+122
-23
lines changed

6 files changed

+122
-23
lines changed

com.github.mgerhold.OOPetris.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ runtime-version: "23.08"
44
sdk: org.freedesktop.Sdk
55
command: oopetris
66
modules:
7+
#TODO: remove after discord sets SONAME
8+
- name: patchelf
9+
buildsystem: simple
10+
sources:
11+
- type: archive
12+
url: https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0.tar.gz
13+
sha256: 64de10e4c6b8b8379db7e87f58030f336ea747c0515f381132e810dbf84a86e7
14+
build-commands:
15+
- ./configure --prefix=/app
16+
- make
17+
- make install
18+
719
- name: OOPetris
820
buildsystem: meson
921
config-opts:
@@ -28,6 +40,13 @@ cleanup:
2840
- /include
2941
- /lib/pkgconfig
3042
- /share/pkgconfig
43+
## all for the patchelf executable
44+
#TODO: remove after removing patchelf build
45+
- /bin/patchelf
46+
- /lib/debug
47+
- /share/doc
48+
- /share/man
49+
- /share/zsh
3150

3251
finish-args:
3352
- --socket=x11
@@ -36,3 +55,4 @@ finish-args:
3655
- --device=dri
3756
- --socket=pulseaudio
3857
- --share=network
58+
- --filesystem=xdg-run/discord-ipc-0:rw

src/discord/core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ DiscordInstance::DiscordInstance(discord::Core* core) : m_core{ core }, m_curren
2222
[[nodiscard]] helper::expected<DiscordInstance, std::string> DiscordInstance::initialize() {
2323

2424
discord::Core* core{};
25-
auto result = discord::Core::Create(constants::discord::client_id, DiscordCreateFlags_Default, &core);
25+
auto result = discord::Core::Create(constants::discord::client_id, DiscordCreateFlags_NoRequireDiscord, &core);
2626
if (core == nullptr) {
2727
return helper::unexpected<std::string>{
2828
fmt::format("Failed to instantiate discord core: {}", magic_enum::enum_name(result))

src/discord/core.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ namespace constants::discord {
1313

1414
//TODO: this isn't correct for all platforms and needs to be tested
1515
#if defined(__ANDROID__)
16-
constexpr const char* platform_dependent_launch_arguments = ""
16+
constexpr const char* platform_dependent_launch_arguments = "";
1717
#elif defined(__SWITCH__)
1818
#error "Not supported"
1919
#elif defined(FLATPAK_BUILD)
20-
constexpr const char* platform_dependent_launch_arguments = "flatpak run com.github.mgerhold.OOPetris --discord"
20+
constexpr const char* platform_dependent_launch_arguments = "flatpak run com.github.mgerhold.OOPetris --discord";
2121
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
22-
constexpr const char* platform_dependent_launch_arguments = "oopetris.exe --discord"
22+
constexpr const char* platform_dependent_launch_arguments = "oopetris.exe --discord";
2323
#elif defined(__APPLE__)
24-
constexpr const char* platform_dependent_launch_arguments = "TODO"
24+
constexpr const char* platform_dependent_launch_arguments = "TODO";
2525
#elif defined(__linux__)
2626
constexpr const char* platform_dependent_launch_arguments = "oopetris --discord";
2727
#else

src/helper/utils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <filesystem>
1111
#include <string>
1212
#include <type_traits>
13+
#include <vector>
1314

1415
namespace helper {
1516

subprojects/discord-game-sdk.wrap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[wrap-file]
2-
directory = discord_game_sdk
2+
directory = discord_game_sdk-3.2.1
33
lead_directory_missing = true
44
source_url = https://dl-game-sdk.discordapp.net/3.2.1/discord_game_sdk.zip
55
source_filename = discord_game_sdk.zip

subprojects/packagefiles/discord_game_sdk/cpp/meson.build

Lines changed: 95 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
11

22
inc_dirs = include_directories('.')
33

4-
src_files = files(
5-
'achievement_manager.cpp',
4+
header_files = files(
65
'achievement_manager.h',
7-
'activity_manager.cpp',
86
'activity_manager.h',
9-
'application_manager.cpp',
107
'application_manager.h',
11-
'core.cpp',
128
'core.h',
139
'discord.h',
1410
'event.h',
1511
'ffi.h',
16-
'image_manager.cpp',
1712
'image_manager.h',
18-
'lobby_manager.cpp',
1913
'lobby_manager.h',
20-
'network_manager.cpp',
2114
'network_manager.h',
22-
'overlay_manager.cpp',
2315
'overlay_manager.h',
24-
'relationship_manager.cpp',
2516
'relationship_manager.h',
26-
'storage_manager.cpp',
2717
'storage_manager.h',
28-
'store_manager.cpp',
2918
'store_manager.h',
30-
'types.cpp',
3119
'types.h',
32-
'user_manager.cpp',
3320
'user_manager.h',
34-
'voice_manager.cpp',
3521
'voice_manager.h',
3622
)
3723

24+
install_headers(header_files, subdir: 'discord')
25+
26+
src_files = files(
27+
'achievement_manager.cpp',
28+
'activity_manager.cpp',
29+
'application_manager.cpp',
30+
'core.cpp',
31+
'image_manager.cpp',
32+
'lobby_manager.cpp',
33+
'network_manager.cpp',
34+
'overlay_manager.cpp',
35+
'relationship_manager.cpp',
36+
'storage_manager.cpp',
37+
'store_manager.cpp',
38+
'types.cpp',
39+
'user_manager.cpp',
40+
'voice_manager.cpp',
41+
)
42+
3843
lib_dir = ''
44+
dynamic_lib = ''
3945

4046
if host_machine.system() == 'darwin'
47+
dynamic_lib = 'discord_game_sdk.dylib'
4148
if host_machine.cpu_family() == 'aarch64'
4249
lib_dir = 'lib' / 'aarch64'
4350
elif host_machine.cpu_family() == 'x86_64'
@@ -47,12 +54,14 @@ if host_machine.system() == 'darwin'
4754
endif
4855

4956
elif host_machine.system() == 'linux'
57+
dynamic_lib = 'discord_game_sdk.so'
5058
if host_machine.cpu_family() == 'x86_64'
5159
lib_dir = 'lib' / 'x86_64'
5260
else
5361
error('unsuported architectue for linux: ' + host_machine.cpu_family())
5462
endif
5563
elif host_machine.system() == 'windows'
64+
dynamic_lib = 'discord_game_sdk.dll'
5665
if host_machine.cpu_family() == 'x86'
5766
lib_dir = 'lib' / 'x86'
5867
elif host_machine.cpu_family() == 'x86_64'
@@ -66,13 +75,82 @@ endif
6675

6776
c = meson.get_compiler('c')
6877

69-
discord_lib_c = c.find_library('discord_game_sdk', dirs: [meson.project_source_root() / lib_dir])
78+
lib_deps = []
79+
80+
## prefrerring the static vartiant, if not found we need to copy the danmic lib to the libdir on installation!
81+
82+
discord_lib_c = c.find_library(
83+
'discord_game_sdk',
84+
dirs: [meson.project_source_root() / lib_dir],
85+
static: true,
86+
required: false,
87+
)
88+
89+
if discord_lib_c.found()
90+
lib_deps += discord_lib_c
91+
else
92+
lib_deps += c.find_library(
93+
'discord_game_sdk',
94+
dirs: [meson.project_source_root() / lib_dir],
95+
)
96+
97+
dynamic_lib_rename = dynamic_lib
98+
99+
if host_machine.system() == 'linux'
100+
dynamic_lib_rename = 'libdiscord_game_sdk_c.so'
101+
102+
objdump = find_program('objdump')
103+
104+
objdump_result = run_command(
105+
objdump,
106+
'-p',
107+
meson.project_source_root() / lib_dir / dynamic_lib,
108+
check: true,
109+
).stdout().strip()
110+
111+
if objdump_result.contains('SONAME')
112+
message('discord game sdk has a SONAME')
113+
114+
else
115+
message('discord game sdk has no SONAME')
116+
117+
patchelf = find_program('patchelf')
118+
119+
#TODO: file issue to discord, to set SONAME
120+
run_command(
121+
patchelf,
122+
'--set-soname',
123+
dynamic_lib_rename,
124+
meson.project_source_root() / lib_dir / dynamic_lib,
125+
check: true,
126+
)
127+
128+
run_command(
129+
find_program('cp'),
130+
meson.project_source_root() / lib_dir / dynamic_lib,
131+
meson.project_source_root() / lib_dir / dynamic_lib_rename,
132+
check: true,
133+
)
134+
135+
endif
136+
endif
137+
138+
install_data(
139+
meson.project_source_root() / lib_dir / dynamic_lib,
140+
install_dir: get_option('libdir'),
141+
rename: [dynamic_lib_rename],
142+
)
143+
144+
endif
145+
70146

71147
discord_lib = library(
72148
'discord-game-sdk',
73149
src_files,
150+
header_files,
74151
include_directories: inc_dirs,
75-
dependencies: discord_lib_c,
152+
dependencies: lib_deps,
153+
install: true,
76154
)
77155

78156
discord_dep = declare_dependency(

0 commit comments

Comments
 (0)