Skip to content

Commit 2a6b2c1

Browse files
committed
build: convert internal BlocksRuntime to shared
This converts the internal BlocksRuntime to a dynamic library. This is the way that BlocksRuntime is most likely distributed in other cases and makes the internal build be more similar to that. 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 84ac6ac commit 2a6b2c1

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,14 @@ if(NOT BlocksRuntime_FOUND)
137137
set(BlocksRuntime_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src/BlocksRuntime)
138138

139139
add_library(BlocksRuntime
140-
STATIC
140+
SHARED
141141
${CMAKE_SOURCE_DIR}/src/BlocksRuntime/data.c
142142
${CMAKE_SOURCE_DIR}/src/BlocksRuntime/runtime.c)
143+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
144+
target_sources(BlocksRuntime
145+
PRIVATE
146+
${CMAKE_SOURCE_DIR}/src/BlocksRuntime/BlocksRuntime.def)
147+
endif()
143148
set_target_properties(BlocksRuntime
144149
PROPERTIES
145150
POSITION_INDEPENDENT_CODE TRUE)

src/BlocksRuntime/Block.h

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

14+
#if defined(_WIN32)
15+
# if defined(BlocksRuntime_EXPORTS)
16+
# define BLOCK_ABI __declspec(dllexport)
17+
# else
18+
# define BLOCK_ABI __declspec(dllimport)
19+
# endif
20+
#else
21+
# define BLOCK_ABI __attribute__((__visibility__("default")))
22+
#endif
23+
1424
#if !defined(BLOCK_EXPORT)
1525
# if defined(__cplusplus)
16-
# define BLOCK_EXPORT extern "C" __attribute__((visibility("default")))
26+
# define BLOCK_EXPORT extern "C" BLOCK_ABI
1727
# else
18-
# define BLOCK_EXPORT extern __attribute__((visibility("default")))
28+
# define BLOCK_EXPORT extern BLOCK_ABI
1929
# endif
2030
#endif
2131

@@ -38,8 +48,13 @@ BLOCK_EXPORT void _Block_object_assign(void *, const void *, const int);
3848
BLOCK_EXPORT void _Block_object_dispose(const void *, const int);
3949

4050
// Used by the compiler. Do not use these variables yourself.
51+
#if defined(_WIN32)
52+
extern void * _NSConcreteGlobalBlock[32];
53+
extern void * _NSConcreteStackBlock[32];
54+
#else
4155
BLOCK_EXPORT void * _NSConcreteGlobalBlock[32];
4256
BLOCK_EXPORT void * _NSConcreteStackBlock[32];
57+
#endif
4358

4459
#if __cplusplus
4560
}

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: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ 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")))
1817

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 };
18+
#include "Block.h"
19+
20+
#if defined(_WIN32)
21+
void * _NSConcreteStackBlock[32] = { 0 };
22+
void * _NSConcreteGlobalBlock[32] = { 0 };
23+
#else
24+
BLOCK_ABI void * _NSConcreteStackBlock[32] = { 0 };
25+
BLOCK_ABI void * _NSConcreteGlobalBlock[32] = { 0 };
26+
#endif
27+
28+
BLOCK_ABI void * _NSConcreteMallocBlock[32] = { 0 };
29+
BLOCK_ABI void * _NSConcreteAutoBlock[32] = { 0 };
30+
BLOCK_ABI void * _NSConcreteFinalizingBlock[32] = { 0 };
31+
BLOCK_ABI void * _NSConcreteWeakBlockVariable[32] = { 0 };

0 commit comments

Comments
 (0)