Skip to content

Commit

Permalink
Add flag to compile gpr with compatibility for musl
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Apr 19, 2017
1 parent 5ef2087 commit 9805833
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
11 changes: 10 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
# will let users recompile gRPC to work without ALPN.
'grpc_alpn%': 'true',
# Indicates that the library should be built with gcov.
'grpc_gcov%': 'false'
'grpc_gcov%': 'false',
# Indicates that the library should be built with compatibility for musl
# libc, so that it can run on Alpine Linux. This is only necessary if not
# building on Alpine Linux
'grpc_alpine%': 'false'
},
'target_defaults': {
'configurations': {
Expand Down Expand Up @@ -115,6 +119,11 @@
'-rdynamic',
],
}],
['grpc_alpine=="true"', {
'defines': [
'GPR_MUSL_LIBC_COMPAT'
]
}],
['OS!="win" and runtime=="electron"', {
"defines": [
'OPENSSL_NO_THREADS'
Expand Down
2 changes: 1 addition & 1 deletion include/grpc/impl/codegen/port_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
#ifdef __GLIBC__
#define GPR_POSIX_CRASH_HANDLER 1
#else /* musl libc */
#define GRPC_MSG_IOVLEN_TYPE int
#define GPR_MUSL_LIBC_COMPAT 1
#endif
#elif defined(__APPLE__)
#include <Availability.h>
Expand Down
1 change: 1 addition & 0 deletions src/core/lib/iomgr/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
#ifndef __GLIBC__
#define GRPC_LINUX_EPOLL 1
#define GRPC_LINUX_EVENTFD 1
#define GRPC_MSG_IOVLEN_TYPE int
#endif
#ifndef GRPC_LINUX_EVENTFD
#define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1
Expand Down
8 changes: 4 additions & 4 deletions src/core/lib/support/cpu_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ unsigned gpr_cpu_num_cores(void) {
}

unsigned gpr_cpu_current_cpu(void) {
#ifdef __GLIBC__
#ifdef GPR_MUSL_LIBC_COMPAT
// sched_getcpu() is undefined on musl
return 0;
#else
int cpu = sched_getcpu();
if (cpu < 0) {
gpr_log(GPR_ERROR, "Error determining current CPU: %s\n", strerror(errno));
return 0;
}
return (unsigned)cpu;
#else
// sched_getcpu() is undefined on musl
return 0;
#endif
}

Expand Down
4 changes: 3 additions & 1 deletion src/core/lib/support/wrap_memcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*
*/

#include <grpc/support/port_platform.h>

#include <string.h>

/* Provide a wrapped memcpy for targets that need to be backwards
Expand All @@ -40,7 +42,7 @@
*/

#ifdef __linux__
#if defined(__x86_64__) && defined(__GNU_LIBRARY__)
#if defined(__x86_64__) && !defined(GPR_MUSL_LIBC_COMPAT)
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
void *__wrap_memcpy(void *destination, const void *source, size_t num) {
return memcpy(destination, source, num);
Expand Down
11 changes: 10 additions & 1 deletion templates/binding.gyp.template
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
# will let users recompile gRPC to work without ALPN.
'grpc_alpn%': 'true',
# Indicates that the library should be built with gcov.
'grpc_gcov%': 'false'
'grpc_gcov%': 'false',
# Indicates that the library should be built with compatibility for musl
# libc, so that it can run on Alpine Linux. This is only necessary if not
# building on Alpine Linux
'grpc_alpine%': 'false'
},
'target_defaults': {
'configurations': {
Expand Down Expand Up @@ -105,6 +109,11 @@
% endif
% endfor
}],
['grpc_alpine=="true"', {
'defines': [
'GPR_MUSL_LIBC_COMPAT'
]
}],
['OS!="win" and runtime=="electron"', {
"defines": [
'OPENSSL_NO_THREADS'
Expand Down
2 changes: 1 addition & 1 deletion tools/run_tests/artifacts/build_artifact_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ electron_versions=( 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 )

for version in ${node_versions[@]}
do
./node_modules/.bin/node-pre-gyp configure rebuild package testpackage --target=$version --target_arch=$NODE_TARGET_ARCH
./node_modules/.bin/node-pre-gyp configure rebuild package testpackage --target=$version --target_arch=$NODE_TARGET_ARCH --grpc_alpine=true
cp -r build/stage/* artifacts/
done

Expand Down

0 comments on commit 9805833

Please sign in to comment.