Skip to content

Commit

Permalink
Merge pull request #4 from Totto16/fix_Static_build_on_windows
Browse files Browse the repository at this point in the history
Fix static build on windows
  • Loading branch information
Totto16 authored Oct 15, 2024
2 parents f033ae4 + bc3378b commit e23c634
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
26 changes: 22 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ jobs:
fail-fast: false
matrix:
config:
- name: Windows MSVC
- name: Windows MSVC (dynamic)
os: windows
os-version: 2022
environment: msvc
shell: pwsh
static: false

- name: Windows MSVC (static)
os: windows
os-version: 2022
environment: msvc
shell: pwsh
static: true

- name: Windows MingGW
os: windows
Expand All @@ -35,7 +43,7 @@ jobs:
architecture: ucrt-x86_64
shell: 'msys2 {0}'

- name: Linux
- name: Linux
os: ubuntu
os-version: 24.04
use-clang: false
Expand Down Expand Up @@ -157,6 +165,16 @@ jobs:
echo "CXX_LD=lld" >> "$GITHUB_ENV"
echo "OBJC_LD=lld" >> "$GITHUB_ENV"
- name: Unbreak Python in GHA (MacOS 13 image)
if: matrix.config.os == 'macos' && matrix.config.os-version == 13
run: |
# TODO: remove this, after it works again
# A workaround for "The `brew link` step did not complete successfully" error.
# See e.g. https://github.com/Homebrew/homebrew-core/issues/165793#issuecomment-1991817938
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
sudo rm -rf /Library/Frameworks/Python.framework/
brew install --force python3 && brew unlink python3 && brew unlink python3 && brew link --overwrite python3
- name: Setup meson (MacOS)
if: matrix.config.os == 'macos'
run: |
Expand Down Expand Up @@ -186,10 +204,10 @@ jobs:
- name: Build and Install OOPetris
run: |
cd oopetris
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}/' || ''}}
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}/' || ''}}
${{ matrix.config.os == 'ubuntu' && 'sudo' || '' }} meson install -C build
- name: Build Wrapper
run: |
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' || '' }}
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') || '' }}
meson compile -C build
8 changes: 8 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ subdir('src')

subdir('tools')

c_args = [
'-DOOPETRIS_LIBRARY_C_WRAPPER_TYPE='
+ (get_option('default_library') == 'static' ? '1' : '0'),
]

liboopetris_c_wrapper = library(
'oopetris_c_wrapper',
src_files,
dependencies: deps,
cpp_args: c_args,
cpp_shared_args: ['-DOOPETRIS_LIBRARY_C_WRAPPER_EXPORT'],
override_options: {
'warning_level': '3',
Expand All @@ -40,6 +46,7 @@ liboopetris_c_wrapper_dep = declare_dependency(
link_with: liboopetris_c_wrapper,
dependencies: deps,
version: meson.project_version(),
compile_args: c_args,
include_directories: include_directories('src'),
)
meson.override_dependency('liboopetris-c-wrapper', liboopetris_c_wrapper_dep)
Expand All @@ -60,6 +67,7 @@ pkg.generate(
name: 'oopetris-c-wrapper',
filebase: 'oopetris-c-wrapper',
subdirs: 'oopetris',
extra_cflags: c_args,
variables: ['compiler=' + pkg_cpp_compiler, 'cpp_stdlib=' + pkg_cpp_stdlib],
)

Expand Down
4 changes: 4 additions & 0 deletions src/c_wrapper/windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern "C" {


#if defined(_MSC_VER)
#if defined(OOPETRIS_LIBRARY_C_WRAPPER_TYPE) && OOPETRIS_LIBRARY_C_WRAPPER_TYPE == 0
#if defined(OOPETRIS_LIBRARY_C_WRAPPER_EXPORT)
#define OOPETRIS_C_WRAPPER_EXPORTED __declspec(dllexport)
#else
Expand All @@ -14,6 +15,9 @@ extern "C" {
#else
#define OOPETRIS_C_WRAPPER_EXPORTED
#endif
#else
#define OOPETRIS_C_WRAPPER_EXPORTED
#endif


#ifdef __cplusplus
Expand Down

0 comments on commit e23c634

Please sign in to comment.