Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches to help build node as a shared library for Android #29388

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@
'ldflags': [ '-Wl,-bbigtoc' ],
}],
['OS == "android"', {
'cflags': [ '-fPIE' ],
'ldflags': [ '-fPIE', '-pie' ]
'cflags': [ '-fPIC' ],
'ldflags': [ '-fPIC' ]
}],
],
'msvs_settings': {
Expand Down Expand Up @@ -216,8 +216,8 @@
],
},],
['OS == "android"', {
'cflags': [ '-fPIE' ],
'ldflags': [ '-fPIE', '-pie' ]
'cflags': [ '-fPIC' ],
'ldflags': [ '-fPIC' ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only build the shared library, don't you? Does this also work when building the node executable? -fPIE means Position Independent Executable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will work, because you can build an executable with PIC code, but it will not be as efficient as PIE code. Not sure about the -pie link flag though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check that it still produces a working binary? I have no way to test myself.

}],
],
'msvs_settings': {
Expand Down
7 changes: 5 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,14 +1103,17 @@ def configure_node(o):
o['variables']['node_shared'] = b(options.shared)
node_module_version = getmoduleversion.get_version()

if sys.platform == 'darwin':
if options.dest_os == 'android':
shlib_suffix = 'so'
elif sys.platform == 'darwin':
shlib_suffix = '%s.dylib'
elif sys.platform.startswith('aix'):
shlib_suffix = '%s.a'
else:
shlib_suffix = 'so.%s'
if '%s' in shlib_suffix:
shlib_suffix %= node_module_version
bnoordhuis marked this conversation as resolved.
Show resolved Hide resolved

shlib_suffix %= node_module_version
o['variables']['node_module_version'] = int(node_module_version)
o['variables']['shlib_suffix'] = shlib_suffix

Expand Down
6 changes: 6 additions & 0 deletions src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "node_v8_platform-inl.h"
#include "util-inl.h"

#ifdef __ANDROID__
#include <android/log.h>
#endif

namespace node {

using errors::TryCatchScope;
Expand Down Expand Up @@ -413,6 +417,8 @@ void PrintErrorString(const char* format, ...) {
// Don't include the null character in the output
CHECK_GT(n, 0);
WriteConsoleW(stderr_handle, wbuf.data(), n - 1, nullptr, nullptr);
#elif defined(__ANDROID__)
__android_log_vprint(ANDROID_LOG_ERROR, "nodejs", format, ap);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nodejs -> Node.js

#else
vfprintf(stderr, format, ap);
#endif
Expand Down