Skip to content

Commit

Permalink
feat: Add Linux/arm64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoll committed Sep 2, 2022
1 parent ee80d74 commit a174d7b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
20 changes: 19 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}
],
[
"OS==\"linux\"",
"OS==\"linux\" and target_arch ==\"x64\"",
{
"link_settings": {
"libraries": [
Expand All @@ -80,6 +80,18 @@
]
}
}
],
[
"OS==\"linux\" and target_arch ==\"arm64\"",
{
"link_settings": {
"libraries": [
"-lpact_ffi",
"-L<(module_root_dir)/ffi/linuxaarch64",
"-Wl,-rpath,'$$ORIGIN'/linuxaarch64"
]
}
}
]
],
"library_dirs": [
Expand Down Expand Up @@ -113,6 +125,12 @@
"<(module_root_dir)/ffi/osxaarch64/libpact_ffi.dylib",
],
"destination": "<(PRODUCT_DIR)/osxaarch64"
},
{
"files": [
"<(module_root_dir)/ffi/linuxaarch64/libpact_ffi.so",
],
"destination": "<(PRODUCT_DIR)/linuxaarch64"
}
]
},
Expand Down
2 changes: 2 additions & 0 deletions script/lib/download-ffi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fi
warn "Cleaning ffi directory $FFI_DIR"
rm -rf "${FFI_DIR:?}/*"
mkdir -p "$FFI_DIR/osxaarch64"
mkdir -p "$FFI_DIR/linuxaarch64"

function download_ffi_file {
if [ -z "${1:-}" ]; then
Expand Down Expand Up @@ -56,6 +57,7 @@ function download_ffi {

if [ -z "${ONLY_DOWNLOAD_PACT_FOR_WINDOWS:-}" ]; then
download_ffi "linux-x86_64.so.gz" "lib" "libpact_ffi.so.gz"
download_ffi "linux-aarch64.so.gz" "lib" "linuxaarch64/libpact_ffi.so.gz"
download_ffi "osx-x86_64.dylib.gz" "lib" "libpact_ffi.dylib.gz"
download_ffi "osx-aarch64-apple-darwin.dylib.gz" "lib" "osxaarch64/libpact_ffi.dylib.gz"
else
Expand Down
9 changes: 7 additions & 2 deletions src/ffi/internals/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,24 @@ describe('ffi names', () => {
'v0.0.1-pact_ffi-windows-x86_64.dll'
);
});
it('has the correct name for linux', () => {
it('has the correct name for linux intel', () => {
expect(libName('pact_ffi', 'v0.0.1', 'x64', 'linux')).to.be.equal(
'v0.0.1-libpact_ffi-linux-x86_64.so'
);
});
it('has the correct name for linux arm', () => {
expect(libName('pact_ffi', 'v0.0.1', 'arm64', 'linux')).to.be.equal(
'v0.0.1-libpact_ffi-linux-aarch64.so'
);
});
it('has the correct name for osx intel', () => {
expect(libName('pact_ffi', 'v0.0.1', 'x64', 'darwin')).to.be.equal(
'v0.0.1-libpact_ffi-osx-x86_64.dylib'
);
});
it('has the correct name for osx arm', () => {
expect(libName('pact_ffi', 'v0.0.1', 'arm64', 'darwin')).to.be.equal(
'v0.0.1-libpact_ffi-osx-aarch64-apple-darwin.dylib'
'v0.0.1-libpact_ffi-osx-aarch64.dylib'
);
});
});
5 changes: 3 additions & 2 deletions src/ffi/internals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ const LIBNAME_PREFIX_LOOKUP = {

// This is a lookup between process.arch and
// the architecture names used in pact-reference
const ARCH_LOOKUP = { x64: 'x86_64', arm64: 'aarch64-apple-darwin' };
const ARCH_LOOKUP = { x64: 'x86_64', arm64: 'aarch64' };

// This is a lookup between "${platform}-${arch}" and
// the file extensions to link on that platform/arch combination
const EXTENSION_LOOKUP = {
'osx-x86_64': 'dylib',
'osx-aarch64-apple-darwin': 'dylib',
'osx-aarch64': 'dylib',
'linux-x86_64': 'so',
'linux-aarch64': 'so',
'windows-x86_64': 'dll',
};

Expand Down

0 comments on commit a174d7b

Please sign in to comment.