Skip to content

Commit

Permalink
fix: correct ffi library name on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyJones committed Aug 25, 2021
1 parent c7c984f commit 814ed9c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
28 changes: 28 additions & 0 deletions src/ffi/internals/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import chai = require('chai');
import { libName } from '.';
import chaiAsPromised = require('chai-as-promised');
const expect = chai.expect;
chai.use(chaiAsPromised);

describe('ffi names', () => {
it('has the correct name for windows', () => {
expect(libName('pact_ffi', 'v0.0.1', 'x64', 'win32')).to.be.equal(
'v0.0.1-pact_ffi-windows-x86_64.dll'
);
});
it('has the correct name for linux', () => {
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 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'
);
});
});
19 changes: 12 additions & 7 deletions src/ffi/internals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const PLATFORM_LOOKUP = {
const LIBNAME_PREFIX_LOOKUP = {
linux: 'lib',
darwin: 'lib',
win32: 'lib', // yes, 'win32' is what process.platform returns on windows 64 bit
win32: '', // yes, 'win32' is what process.platform returns on windows 64 bit
};

// This is a lookup between process.arch and
Expand Down Expand Up @@ -44,13 +44,18 @@ export const initialiseFfi = <T>(
description as { [k: string]: any }
);

export const libName = (library: string, version: string): string => {
const arch = ARCH_LOOKUP[process.arch];
const platform = PLATFORM_LOOKUP[process.platform];
export const libName = (
library: string,
version: string,
processArch = process.arch,
processPlatform = process.platform
): string => {
const arch = ARCH_LOOKUP[processArch];
const platform = PLATFORM_LOOKUP[processPlatform];

if (!arch || !platform) {
throw new Error(
`Pact does not currently support the operating system and architecture combination '${process.platform}/${process.arch}'`
`Pact does not currently support the operating system and architecture combination '${processPlatform}/${processArch}'`
);
}

Expand All @@ -63,10 +68,10 @@ export const libName = (library: string, version: string): string => {
);
}

const libnamePrefix = LIBNAME_PREFIX_LOOKUP[process.platform];
const libnamePrefix = LIBNAME_PREFIX_LOOKUP[processPlatform];
if (libnamePrefix === undefined) {
throw new Error(
`Pact doesn't know what prefix to use for the libraries on '${process.platform}'`
`Pact doesn't know what prefix to use for the libraries on '${processPlatform}'`
);
}

Expand Down

0 comments on commit 814ed9c

Please sign in to comment.