Skip to content

Commit

Permalink
build: enable usage on Windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
compnerd committed Oct 4, 2018
1 parent 8aa73a1 commit 128fb30
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Expand Up @@ -144,6 +144,16 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_library(BlocksRuntime
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/data.c
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/runtime.c)
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
target_sources(BlocksRuntime
PRIVATE
${PROJECT_SOURCE_DIR}/src/BlocksRuntime/BlocksRuntime.def)
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(BlocksRuntime
PRIVATE
BlocksRuntime_STATIC)
endif()
endif()
set_target_properties(BlocksRuntime
PROPERTIES
POSITION_INDEPENDENT_CODE TRUE)
Expand Down
23 changes: 21 additions & 2 deletions src/BlocksRuntime/Block.h
Expand Up @@ -11,11 +11,25 @@
#ifndef _Block_H_
#define _Block_H_

#if defined(_WIN32)
# if defined(BlocksRuntime_STATIC)
# define BLOCK_ABI
# else
# if defined(BlocksRuntime_EXPORTS)
# define BLOCK_ABI __declspec(dllexport)
# else
# define BLOCK_ABI __declspec(dllimport)
# endif
# endif
#else
# define BLOCK_ABI __attribute__((__visibility__("default")))
#endif

#if !defined(BLOCK_EXPORT)
# if defined(__cplusplus)
# define BLOCK_EXPORT extern "C" __attribute__((visibility("default")))
# define BLOCK_EXPORT extern "C" BLOCK_ABI
# else
# define BLOCK_EXPORT extern __attribute__((visibility("default")))
# define BLOCK_EXPORT extern BLOCK_ABI
# endif
#endif

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

// Used by the compiler. Do not use these variables yourself.
#if defined(_WIN32)
extern void * _NSConcreteGlobalBlock[32];
extern void * _NSConcreteStackBlock[32];
#else
BLOCK_EXPORT void * _NSConcreteGlobalBlock[32];
BLOCK_EXPORT void * _NSConcreteStackBlock[32];
#endif

#if __cplusplus
}
Expand Down
4 changes: 4 additions & 0 deletions src/BlocksRuntime/BlocksRuntime.def
@@ -0,0 +1,4 @@
LIBRARY BlocksRuntime
EXPORTS
_NSConcreteGlobalBlock CONSTANT
_NSConcreteStackBlock CONSTANT
20 changes: 13 additions & 7 deletions src/BlocksRuntime/data.c
Expand Up @@ -14,11 +14,17 @@ We allocate space and export a symbol to be used as the Class for the on-stack a
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.
**********************/
#define BLOCK_EXPORT __attribute__((visibility("default")))
#include "Block.h"

BLOCK_EXPORT void * _NSConcreteStackBlock[32] = { 0 };
BLOCK_EXPORT void * _NSConcreteMallocBlock[32] = { 0 };
BLOCK_EXPORT void * _NSConcreteAutoBlock[32] = { 0 };
BLOCK_EXPORT void * _NSConcreteFinalizingBlock[32] = { 0 };
BLOCK_EXPORT void * _NSConcreteGlobalBlock[32] = { 0 };
BLOCK_EXPORT void * _NSConcreteWeakBlockVariable[32] = { 0 };
#if defined(_WIN32)
void * _NSConcreteStackBlock[32] = { 0 };
void * _NSConcreteGlobalBlock[32] = { 0 };
#else
BLOCK_ABI void * _NSConcreteStackBlock[32] = { 0 };
BLOCK_ABI void * _NSConcreteGlobalBlock[32] = { 0 };
#endif

BLOCK_ABI void * _NSConcreteMallocBlock[32] = { 0 };
BLOCK_ABI void * _NSConcreteAutoBlock[32] = { 0 };
BLOCK_ABI void * _NSConcreteFinalizingBlock[32] = { 0 };
BLOCK_ABI void * _NSConcreteWeakBlockVariable[32] = { 0 };

0 comments on commit 128fb30

Please sign in to comment.