Skip to content

Commit 81f7327

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 21c6b2e commit 81f7327

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

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/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ option(INSTALL_PRIVATE_HEADERS "install private headers in the same location as
2525
add_library(BlocksRuntime
2626
${PROJECT_SOURCE_DIR}/data.c
2727
${PROJECT_SOURCE_DIR}/runtime.c)
28+
if(CMAKE_SYSTEM_NAME MATCHES Windows)
29+
target_sources(BlocksRuntime
30+
PRIVATE
31+
${PROJECT_SOURCE_DIR}/BlocksRuntime.def)
32+
if(NOT BUILD_SHARED_LIBS)
33+
target_compile_definitions(BlockRuntime
34+
PUBLIC
35+
BlocksRuntime_STATIC)
36+
endif()
37+
endif()
2838
set_target_properties(BlocksRuntime
2939
PROPERTIES
3040
POSITION_INDEPENDENT_CODE TRUE)

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)