Skip to content

Commit e23c634

Browse files
authored
Merge pull request #4 from Totto16/fix_Static_build_on_windows
Fix static build on windows
2 parents f033ae4 + bc3378b commit e23c634

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
config:
18-
- name: Windows MSVC
18+
- name: Windows MSVC (dynamic)
1919
os: windows
2020
os-version: 2022
2121
environment: msvc
2222
shell: pwsh
23+
static: false
24+
25+
- name: Windows MSVC (static)
26+
os: windows
27+
os-version: 2022
28+
environment: msvc
29+
shell: pwsh
30+
static: true
2331

2432
- name: Windows MingGW
2533
os: windows
@@ -35,7 +43,7 @@ jobs:
3543
architecture: ucrt-x86_64
3644
shell: 'msys2 {0}'
3745

38-
- name: Linux
46+
- name: Linux
3947
os: ubuntu
4048
os-version: 24.04
4149
use-clang: false
@@ -157,6 +165,16 @@ jobs:
157165
echo "CXX_LD=lld" >> "$GITHUB_ENV"
158166
echo "OBJC_LD=lld" >> "$GITHUB_ENV"
159167
168+
- name: Unbreak Python in GHA (MacOS 13 image)
169+
if: matrix.config.os == 'macos' && matrix.config.os-version == 13
170+
run: |
171+
# TODO: remove this, after it works again
172+
# A workaround for "The `brew link` step did not complete successfully" error.
173+
# See e.g. https://github.com/Homebrew/homebrew-core/issues/165793#issuecomment-1991817938
174+
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
175+
sudo rm -rf /Library/Frameworks/Python.framework/
176+
brew install --force python3 && brew unlink python3 && brew unlink python3 && brew link --overwrite python3
177+
160178
- name: Setup meson (MacOS)
161179
if: matrix.config.os == 'macos'
162180
run: |
@@ -186,10 +204,10 @@ jobs:
186204
- name: Build and Install OOPetris
187205
run: |
188206
cd oopetris
189-
meson setup build -Dbuildtype=release -Ddefault_library=shared -Dclang_libcpp=${{ ( ( matrix.config.os == 'ubuntu' && matrix.config.use-clang == true && matrix.config.use-clang_stdlib ) || matrix.config.os == 'macos' ) && 'enabled' || 'disabled' }} -Donly_build_libs=true ${{ matrix.config.os == 'windows' && '-Db_vscrt=from_buildtype' || '' }} ${{ (matrix.config.os == 'windows' && ( matrix.config.environment == 'mingw' || matrix.config.environment == 'ucrt' )) && '-Dprefix=$RUNNER_TEMP/msys64${MINGW_PREFIX}/' || ''}}
207+
meson setup build -Dbuildtype=release -Ddefault_library=${{( matrix.config.os == 'windows' && matrix.config.environment == 'msvc' && matrix.config.static ) && 'static' ||'shared' }} -Dclang_libcpp=${{ ( ( matrix.config.os == 'ubuntu' && matrix.config.use-clang == true && matrix.config.use-clang_stdlib ) || matrix.config.os == 'macos' ) && 'enabled' || 'disabled' }} -Donly_build_libs=true ${{ matrix.config.os == 'windows' && ( ( matrix.config.environment == 'msvc' && matrix.config.static ) && '-Db_vscrt=static_from_buildtype' || '-Db_vscrt=from_buildtype') || '' }} ${{ (matrix.config.os == 'windows' && ( matrix.config.environment == 'mingw' || matrix.config.environment == 'ucrt' )) && '-Dprefix=$RUNNER_TEMP/msys64${MINGW_PREFIX}/' || ''}}
190208
${{ matrix.config.os == 'ubuntu' && 'sudo' || '' }} meson install -C build
191209
192210
- name: Build Wrapper
193211
run: |
194-
meson setup -Dtests=false -Dexample=true build -Dbuildtype=release -Ddefault_library=shared -Dclang_libcpp=${{ ( ( matrix.config.os == 'ubuntu' && matrix.config.use-clang == true && matrix.config.use-clang_stdlib ) || matrix.config.os == 'macos' ) && 'enabled' || 'disabled' }} ${{ matrix.config.os == 'windows' && '-Db_vscrt=from_buildtype' || '' }}
212+
meson setup -Dtests=false -Dexample=true build -Dbuildtype=release -Ddefault_library=${{( matrix.config.os == 'windows' && matrix.config.environment == 'msvc' && matrix.config.static ) && 'static' ||'shared' }} -Dclang_libcpp=${{ ( ( matrix.config.os == 'ubuntu' && matrix.config.use-clang == true && matrix.config.use-clang_stdlib ) || matrix.config.os == 'macos' ) && 'enabled' || 'disabled' }} ${{ matrix.config.os == 'windows' && ( ( matrix.config.environment == 'msvc' && matrix.config.static ) && '-Db_vscrt=static_from_buildtype' || '-Db_vscrt=from_buildtype') || '' }}
195213
meson compile -C build

meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ subdir('src')
2323

2424
subdir('tools')
2525

26+
c_args = [
27+
'-DOOPETRIS_LIBRARY_C_WRAPPER_TYPE='
28+
+ (get_option('default_library') == 'static' ? '1' : '0'),
29+
]
30+
2631
liboopetris_c_wrapper = library(
2732
'oopetris_c_wrapper',
2833
src_files,
2934
dependencies: deps,
35+
cpp_args: c_args,
3036
cpp_shared_args: ['-DOOPETRIS_LIBRARY_C_WRAPPER_EXPORT'],
3137
override_options: {
3238
'warning_level': '3',
@@ -40,6 +46,7 @@ liboopetris_c_wrapper_dep = declare_dependency(
4046
link_with: liboopetris_c_wrapper,
4147
dependencies: deps,
4248
version: meson.project_version(),
49+
compile_args: c_args,
4350
include_directories: include_directories('src'),
4451
)
4552
meson.override_dependency('liboopetris-c-wrapper', liboopetris_c_wrapper_dep)
@@ -60,6 +67,7 @@ pkg.generate(
6067
name: 'oopetris-c-wrapper',
6168
filebase: 'oopetris-c-wrapper',
6269
subdirs: 'oopetris',
70+
extra_cflags: c_args,
6371
variables: ['compiler=' + pkg_cpp_compiler, 'cpp_stdlib=' + pkg_cpp_stdlib],
6472
)
6573

src/c_wrapper/windows.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern "C" {
66

77

88
#if defined(_MSC_VER)
9+
#if defined(OOPETRIS_LIBRARY_C_WRAPPER_TYPE) && OOPETRIS_LIBRARY_C_WRAPPER_TYPE == 0
910
#if defined(OOPETRIS_LIBRARY_C_WRAPPER_EXPORT)
1011
#define OOPETRIS_C_WRAPPER_EXPORTED __declspec(dllexport)
1112
#else
@@ -14,6 +15,9 @@ extern "C" {
1415
#else
1516
#define OOPETRIS_C_WRAPPER_EXPORTED
1617
#endif
18+
#else
19+
#define OOPETRIS_C_WRAPPER_EXPORTED
20+
#endif
1721

1822

1923
#ifdef __cplusplus

0 commit comments

Comments
 (0)