Skip to content

Commit 128fb30

Browse files
committed
build: enable usage on Windows
Adjust the build for Windows to permit the isa pointer to successfully link. They will be off by a level of indirection and need to be patched up at runtime.
1 parent 8aa73a1 commit 128fb30

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
144144
add_library(BlocksRuntime
145145
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/data.c
146146
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/runtime.c)
147+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
148+
target_sources(BlocksRuntime
149+
PRIVATE
150+
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/BlocksRuntime.def)
151+
if(NOT BUILD_SHARED_LIBS)
152+
target_compile_definitions(BlocksRuntime
153+
PRIVATE
154+
BlocksRuntime_STATIC)
155+
endif()
156+
endif()
147157
set_target_properties(BlocksRuntime
148158
PROPERTIES
149159
POSITION_INDEPENDENT_CODE TRUE)

src/BlocksRuntime/Block.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,25 @@
1111
#ifndef _Block_H_
1212
#define _Block_H_
1313

14+
#if defined(_WIN32)
15+
# if defined(BlocksRuntime_STATIC)
16+
# define BLOCK_ABI
17+
# else
18+
# if defined(BlocksRuntime_EXPORTS)
19+
# define BLOCK_ABI __declspec(dllexport)
20+
# else
21+
# define BLOCK_ABI __declspec(dllimport)
22+
# endif
23+
# endif
24+
#else
25+
# define BLOCK_ABI __attribute__((__visibility__("default")))
26+
#endif
27+
1428
#if !defined(BLOCK_EXPORT)
1529
# if defined(__cplusplus)
16-
# define BLOCK_EXPORT extern "C" __attribute__((visibility("default")))
30+
# define BLOCK_EXPORT extern "C" BLOCK_ABI
1731
# else
18-
# define BLOCK_EXPORT extern __attribute__((visibility("default")))
32+
# define BLOCK_EXPORT extern BLOCK_ABI
1933
# endif
2034
#endif
2135

@@ -38,8 +52,13 @@ BLOCK_EXPORT void _Block_object_assign(void *, const void *, const int);
3852
BLOCK_EXPORT void _Block_object_dispose(const void *, const int);
3953

4054
// Used by the compiler. Do not use these variables yourself.
55+
#if defined(_WIN32)
56+
extern void * _NSConcreteGlobalBlock[32];
57+
extern void * _NSConcreteStackBlock[32];
58+
#else
4159
BLOCK_EXPORT void * _NSConcreteGlobalBlock[32];
4260
BLOCK_EXPORT void * _NSConcreteStackBlock[32];
61+
#endif
4362

4463
#if __cplusplus
4564
}

src/BlocksRuntime/BlocksRuntime.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
LIBRARY BlocksRuntime
2+
EXPORTS
3+
_NSConcreteGlobalBlock CONSTANT
4+
_NSConcreteStackBlock CONSTANT

src/BlocksRuntime/data.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ We allocate space and export a symbol to be used as the Class for the on-stack a
1414
1515
We keep these in a separate file so that we can include the runtime code in test subprojects but not include the data so that compiled code that sees the data in libSystem doesn't get confused by a second copy. Somehow these don't get unified in a common block.
1616
**********************/
17-
#define BLOCK_EXPORT __attribute__((visibility("default")))
17+
#include "Block.h"
1818

19-
BLOCK_EXPORT void * _NSConcreteStackBlock[32] = { 0 };
20-
BLOCK_EXPORT void * _NSConcreteMallocBlock[32] = { 0 };
21-
BLOCK_EXPORT void * _NSConcreteAutoBlock[32] = { 0 };
22-
BLOCK_EXPORT void * _NSConcreteFinalizingBlock[32] = { 0 };
23-
BLOCK_EXPORT void * _NSConcreteGlobalBlock[32] = { 0 };
24-
BLOCK_EXPORT void * _NSConcreteWeakBlockVariable[32] = { 0 };
19+
#if defined(_WIN32)
20+
void * _NSConcreteStackBlock[32] = { 0 };
21+
void * _NSConcreteGlobalBlock[32] = { 0 };
22+
#else
23+
BLOCK_ABI void * _NSConcreteStackBlock[32] = { 0 };
24+
BLOCK_ABI void * _NSConcreteGlobalBlock[32] = { 0 };
25+
#endif
26+
27+
BLOCK_ABI void * _NSConcreteMallocBlock[32] = { 0 };
28+
BLOCK_ABI void * _NSConcreteAutoBlock[32] = { 0 };
29+
BLOCK_ABI void * _NSConcreteFinalizingBlock[32] = { 0 };
30+
BLOCK_ABI void * _NSConcreteWeakBlockVariable[32] = { 0 };

0 commit comments

Comments
 (0)