Skip to content

Commit 1c4a6eb

Browse files
authored
Merge pull request #1 from touchHLE/toolchain
Migrate to toolchain sdk
2 parents 82e1357 + 338703a commit 1c4a6eb

3 files changed

Lines changed: 53 additions & 108 deletions

File tree

.github/workflows/build_dylib.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
env:
19-
SDK_VERSION: "0.1.1"
19+
SDK_VERSION: "0.2.1"
2020
SDK_REPO: "touchHLE/common-3.0-sdk"
2121

2222
steps:
23-
- uses: actions/checkout@v4
23+
- uses: actions/checkout@v5
2424
with:
2525
submodules: 'true'
2626

2727
- name: Download SDK
2828
run: |
29-
curl -L -o sdk.tar.gz "https://github.com/${{ env.SDK_REPO }}/releases/download/v${{ env.SDK_VERSION }}/common-3.0.sdk.tar.gz"
29+
curl -L -o sdk.tar.gz "https://github.com/${{ env.SDK_REPO }}/releases/download/v${{ env.SDK_VERSION }}/common-3.0.sdk-linux-x86_64.tar.gz"
3030
tar xzf sdk.tar.gz
3131
chmod -R +x common-3.0.sdk/usr/bin/
3232
3333
- name: Configure CMake
34-
run: cmake -B ${{github.workspace}}/build
34+
run: cmake -DCMAKE_TOOLCHAIN_FILE="common-3.0.sdk/cmake/Toolchain/common-3.0.cmake" -B build
3535

3636
- name: Build
3737
run: cmake --build ${{github.workspace}}/build
3838

3939
- uses: actions/upload-artifact@v4
4040
with:
41-
name: libz.1.dylib
42-
path: build/libz.1.dylib
41+
name: libz.1.2.3.dylib
42+
path: build/libz.1.2.3.dylib
4343

4444
- name: Create Release
4545
uses: softprops/action-gh-release@v2
4646
if: startsWith(github.ref, 'refs/tags/')
4747
with:
48-
files: build/libz.1.dylib
48+
files: build/libz.1.2.3.dylib
4949

CMakeLists.txt

Lines changed: 39 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,16 @@
11
cmake_minimum_required(VERSION 3.20)
22

3-
# TODO: Can this be replaced with a toolchain file?
4-
set(CMAKE_LINK_DEPENDS_NO_SHARED TRUE)
5-
# Workaround for getting the build to work on Windows
6-
# This should be replaced with a iOS system at some point,
7-
# but there is still much left to do for that to happen.
8-
set(CMAKE_SYSTEM_NAME Linux)
9-
set(CMAKE_C_COMPILER clang)
10-
11-
set(SDK_PATH ${CMAKE_SOURCE_DIR}/common-3.0.sdk)
12-
set(CMAKE_LINKER ${SDK_PATH}/usr/bin/ld)
13-
set(LIPO ${SDK_PATH}/usr/bin/lipo)
14-
15-
set(CMAKE_OSX_SYSROOT ${SDK_PATH}) # Does not seem to work
16-
set(CMAKE_OSX_ARCHITECTURES armv6 armv7)
17-
set(CMAKE_OSX_DEPLOYMENT_TARGET 3.0)
18-
set(CMAKE_C_COMPILER_TARGET arm-apple-ios3.0)
19-
20-
set(CMAKE_C_CREATE_SHARED_LIBRARY
21-
"<CMAKE_LINKER> <LINK_FLAGS> -o <TARGET> <OBJECTS>"
22-
) # Force CMake to use
23-
# custom linker
24-
25-
# Setting OSX Flags breaks the test on Ubuntu. Claim it works as a workaround
26-
# (since it does)
27-
set(CMAKE_C_COMPILER_WORKS TRUE)
28-
#
3+
set(CMAKE_ARCHITECTURES "armv6;armv7")
294

305
project(zlib VERSION 1.2.3 LANGUAGES C)
316

32-
set(LIB_NAME "libz.1.dylib")
7+
set(LIB_NAME "libz.1.2.3.dylib")
338
set(INSTALL_PATH /usr/lib)
349
set(VERSION 1.2.3)
3510
set(COMPAT_VERSION 1.0.0)
3611

12+
set(IMAGE_BASE 0x301f6000)
13+
3714
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/zlib-src")
3815
message(
3916
FATAL_ERROR
@@ -58,80 +35,43 @@ set(ZLIB_SOURCES
5835
${zlib_SOURCE_DIR}/zlib/zutil.c
5936
)
6037

61-
add_compile_options(
62-
-Wno-deprecated-non-prototype
63-
-Wno-incompatible-sysroot
64-
-Wno-expansion-to-defined
65-
-fno-stack-protector
66-
-isysroot
67-
${SDK_PATH} # Workardound for missing
68-
# __stack_chk_*
69-
)
70-
71-
add_compile_definitions(USE_MMAP NDEBUG)
38+
add_library(${LIB_NAME} SHARED ${ZLIB_SOURCES})
7239

73-
# There are more idiomatic ways of setting some of these but stuff like
74-
# target_link_libraries was not working for some reason
75-
add_link_options(
76-
${SDK_PATH}/usr/lib/dylib1.o
77-
-L${SDK_PATH}/usr/lib
78-
-lSystem.B
79-
-lgcc_s.1
80-
-ios_version_min
81-
${CMAKE_OSX_DEPLOYMENT_TARGET}
82-
-exported_symbols_list
83-
${zlib_SOURCE_DIR}/libz.exp
84-
-dead_strip
85-
-dead_strip_dylibs
86-
-dylib
87-
-single_module
88-
-prebind
89-
-dynamic
90-
-twolevel_namespace
91-
-twolevel_namespace_hints
92-
-image_base
93-
0x301f6000
94-
-install_name
95-
${INSTALL_PATH}/${LIB_NAME}
40+
set_target_properties(${LIB_NAME} PROPERTIES
41+
OUTPUT_NAME "z.${VERSION}"
42+
VERSION ${VERSION}
43+
INSTALL_NAME_DIR "${INSTALL_PATH}"
44+
POSITION_INDEPENDENT_CODE OFF
45+
C_STANDARD 99
9646
)
9747

98-
set(arch_targets "")
99-
# Create a target for each architecture
100-
foreach(ARCH IN LISTS CMAKE_OSX_ARCHITECTURES)
101-
set(target_name libz_${ARCH})
102-
list(APPEND arch_targets ${target_name})
103-
add_library(${target_name} SHARED ${ZLIB_SOURCES})
104-
105-
set_target_properties(
106-
${target_name}
107-
PROPERTIES
108-
OUTPUT_NAME "${LIB_NAME}.${ARCH}"
109-
INSTALL_NAME_DIR "${INSTALL_PATH}"
110-
PREFIX ""
111-
SUFFIX ""
112-
POSITION_INDEPENDENTCODE OFF
113-
C_STANDARD 99
114-
)
115-
116-
target_include_directories(
117-
${target_name}
118-
PRIVATE ${CMAKE_SOURCE_DIR}/zlib ${SDK_PATH}/usr/include
119-
)
120-
121-
target_compile_options(${target_name} PRIVATE -arch ${ARCH})
122-
123-
target_link_options(${target_name} PRIVATE -arch ${ARCH} -dylib)
124-
endforeach()
125-
126-
set(lipo_inputs "")
127-
foreach(ARCH IN LISTS CMAKE_OSX_ARCHITECTURES)
128-
list(APPEND lipo_inputs "${CMAKE_BINARY_DIR}/${LIB_NAME}.${ARCH}")
129-
endforeach()
48+
target_compile_options(${LIB_NAME}
49+
PRIVATE
50+
-Wno-deprecated-non-prototype
51+
-Wno-expansion-to-defined
52+
-fno-stack-protector
53+
)
13054

131-
add_custom_target(
132-
${LIB_NAME}
133-
ALL
134-
COMMAND
135-
${LIPO} -create ${lipo_inputs} -output ${CMAKE_BINARY_DIR}/${LIB_NAME}
136-
DEPENDS ${arch_targets}
55+
target_compile_definitions(${LIB_NAME}
56+
PRIVATE
57+
USE_MMAP
58+
NDEBUG
13759
)
60+
61+
target_link_options(${LIB_NAME}
62+
PRIVATE
63+
-exported_symbols_list
64+
${zlib_SOURCE_DIR}/libz.exp
65+
-dead_strip
66+
-dead_strip_dylibs
67+
-dylib
68+
-single_module
69+
-prebind
70+
-dynamic
71+
-twolevel_namespace
72+
-twolevel_namespace_hints
73+
-image_base
74+
${IMAGE_BASE}
75+
-install_name
76+
${INSTALL_PATH}/${LIB_NAME}
77+
)

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
# Building zlib dylib
22

3+
## Prerequisites
4+
Download and extract the common-3.0.sdk:
5+
- Download the latest sdk from: <https://github.com/touchHLE/common-3.0-sdk/releases/latest>
6+
- Extract in project root
7+
38
## Build Dylib
49

5-
`cmake -S . -B build`
10+
`cmake -DCMAKE_TOOLCHAIN_FILE="common-3.0.sdk/cmake/Toolchain/common-3.0.cmake" -S . -B build`
611

712
`cmake --build build`
813

914
## Licensing
1015

11-
This SDK contains components under multiple licenses:
16+
This repository contains components under multiple licenses:
1217

1318
zlib dylib binary
1419
- Licensed under zlib License

0 commit comments

Comments
 (0)