-
-
Notifications
You must be signed in to change notification settings - Fork 349
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
Avoid compiling native dependencies for common build targets #899
Comments
The latest version of Pact JS (10.x.x) doesn't download anything at runtime, however it needs scripts enabled to compile native code. We previously had optional build dependencies (~4-5 years ago), this might be an option long term but is not something I'll be picking up any time soon. If it were to be done, it would actually be in the |
ah ok. is the compilation of the native code required? |
Yes, we have raw cpp files that link to the shared library. I believe we could look to precompile them and bundle or ship as optional dependencies. If that's something you'd be interested in contributing, we could definitely discuss further.
That would be great, however unless I'm mistaken, wasm can't write files to disk or spin up mock servers - so I think it's a non starter. |
Wasm could export the matcher and plugin part. This would have the benefit that (in theory) all languages could use it and just the http part would need to be implemented in the respective language. I can look into the pre compile topic. Issue here is that the pact library is surprisingly difficult to wrap the head around, so it might take some time for me 😅 |
Unfortunately there is a bit more to it than that. For example, there is also a sophisticated plugin framework that installs, discovers and communicates remotely to plugins.
The key bit is in the |
I guess, you could use https://github.com/mapbox/node-pre-gyp to distribute the binaries. |
but that still means, that we have to have a post install hook |
That's right. I'd prefer to explore the optional dependencies approach if it could be done, but that won't work on platforms like alpine because the os/architecture combination is not enough to determine the runtime needs (for clarity, we don't officially support Alpine because dynamic linking to glibc is challenging. |
Hey, probably it would be good to deliver some pre-build Docker-Images containing the correct built binaries. What do you think about this? In consequence, the Images versions should always be aligned with the version of pact-js, so consumers can align their image and package.json dependency. |
Is the docker images for building the pact JS versions, or for users to run their Pact JS builds on? |
I can't figure out how to get node-gyp to cross-compile the binaries 😖. If it's not possible I could create a github action and run it for every major architecture 🤔 |
Yeah, I think that is probably what is going to be required. I'm almost certain you won't be able to cross-compile all future targets such Alpine, for example. In fact, I'm not sure how you'd even be able to detect what alpine package to install at runtime as the package constraints aren't that granular - so that almost certainly would have to be a post install script. Alpine aside, it gets tricky though, because you need to only publish the top level package if all of the optional dependencies publish successfully. I think tools like https://github.com/semantic-release/semantic-release can help with that kind of process, but it would require substantial changes to our release process (I'm not against it, but it's going to be an involved process to setup a test set of packages first to demonstrate the workflow on a test npm package). |
is there a difference between alpine and 'standard' linux? esbuild seems to also not make a difference |
Yes, alpine uses musl not glibc
…On Tue, 27 Sept 2022, 18:37 Constantin, ***@***.***> wrote:
is there a difference between alpine and 'standard' linux? esbuild seems
to also not make a difference
—
Reply to this email directly, view it on GitHub
<#899 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAANFDHOBMB3BNH24AFQXFLWAKW23ANCNFSM54YLCLEA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Why not static link instead to avoid the problem? |
I think it's plausible, albeit there is probably a reason we didn't do this earlier (despite the size of the lib being 3x bigger). We do release static artifacts (see https://github.com/pact-foundation/pact-reference/releases/tag/libpact_ffi-v0.3.19), so if somebody wanted to try I'd be more than open to accepting a PR (as noted, it would need to be done here https://github.com/pact-foundation/pact-js-core/). |
This worked in on Windows 10 and Node 18 I would love to help out, I just need to understand what changed? |
Thanks @andreasmarkussen, a lot has changed since that version. TL;DR the current situation:
If we want to avoid compilation at install time, there are several options all with their own set of tradeoffs:
(3) seems the most promising approach to me and I recommend we start there. The hard part here is finding a way to x-compile the targets and get them into the distribution, possibly spread across a number of GH actions (see this suggestion above) A reminder - the above would need to happen in the I think we would want to aim for an initial compatibility table as follows; OS/Arch support
✅ = installs without build hooks, pre-built native library NOTE: the core does not release arm artifacts for windows, but there is no reason we couldn't support that if they did. |
@jaecktec how do those who use ignore scripts actually work with npm properly as a large amount of packages have pre install and post install scripts. i don’t assume you are checking the full contents of every top level dependency you have in your project and the pact ffi as a shared lib brings in its own set of dependencies and attack vectors |
interestingly pact is the only library that I've noticed actually requiring the post-install in all our products. |
node pre gyp demo in pact js core pact-foundation/pact-js-core@master...YOU54F:pact-js-core:master all the prebuilt node binaries https://github.com/YOU54F/pact-js-core/releases/tag/v13.16.1
bonus points - i’ve built pact.node for arm64 windows machines too, your mileage may vary |
thanks buddy, that is useful to know! :) |
if no-one is concerned about the size of the npm package, then pre compiling all the pact.nice binaries and including them in the package would be the simplest as it doesn’t involve any install time fetching or building. i’m not sure on the versioning node pre gyp provides, for node. it shows node versions 93/111 etc but i think it should be against node api versions which have 1-8 also in doing this exercise it’s makes me definitely think pulling out the ruby standalone into a sep package is a smart idea, as saves having to store the standalone in the release tarball and users can just add it in as an extra import if they want |
Ah, that's a good point. I believe the node ABI is forwards compatible, so if we built the |
So I was trying to work it out last night ABI Matrix https://nodejs.org/api/n-api.html#node-api-version-matrix https://nodejs.org/en/download/releases
We can see version in https://github.com/YOU54F/pact-js-core/blob/master/native/ffi.cc#L1 anything lower and it fails to build. Looking at the ABI compat matrix, version 8 supports v12 which is EOL, v14 which is going EOL end of the month, but raises minimum compat up to v15.12.0 (for v15 users) I'm not sure what the implications are of leaving it at the lowest version it will compile with (which is NAPI_VERSION=3). I also don't understand why that chart isn't updated, to include v17->v20, especially as that matrix for the node-api version matrix is on the node v20 ref docs |
Thanks for sharing. We could probably update to 8 if I'm reading that table correctly, given that 14 (our lowest major version officially supported) works with it. I'm not sure what we gain from it, so it might be worth looking into after we first get it all running (or we just test to see what happens). |
Yeah just best spinning it through a set of docker containers on diff node versions and seeing what happens, As well as node-pre-gyp, there are also another couple of options, as recommended by node https://nodejs.org/api/n-api.html#uploading-precompiled-binaries https://github.com/prebuild/prebuildify/ These will look up via the detected node/arch/abi version and look for a pre-compiled version that you ship with the package (for multi arches)
|
Nice, yes prebuildify looks like another way to go.
…On Fri, Apr 21, 2023, 22:26 Yousaf Nabi ***@***.***> wrote:
Yeah just best spinning it through a set of docker containers on diff node
versions and seeing what happens,
As well as node-pre-gyp, there are also another couple of options, as
recommended by node
https://nodejs.org/api/n-api.html#uploading-precompiled-binaries
https://github.com/prebuild/prebuildify/
https://github.com/prebuild/prebuild
These will look up via the detected node/arch/abi version and look for a
pre-compiled version that you ship with the package (for multi arches)
[image: Screenshot 2023-04-21 at 13 23 39]
<https://user-images.githubusercontent.com/19932401/233634467-610e771b-4125-4ad2-8a3d-fc0f46785749.png>
npx prebuildify --napi --arch x64+arm64
npx prebuildify --napi --arch x64
—
Reply to this email directly, view it on GitHub
<#899 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAANFDG7APHQPCNHWABRWOTXCJ4IBANCNFSM54YLCLEA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-963). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps. |
Checklist
Before making a feature request, I have:
Feature description
When installing Pact the binaries should be downloaded through an optional platform specific dependency like esbuild
Use case
Due to recent supply chain attacks a lot of developers have npm scripts globally disabled.
Second we wouldn't need to care about proxy settings in the post-install.
The text was updated successfully, but these errors were encountered: