Closed
Description
Specification
As js-quic is a native package, it has much more complicated packaging procedure making it similar to js-db. However this is different because it uses Rust instead of C++, therefore the entire toolchain is different from js-db.
Rather than tsc
, node
, node-gyp
, napi-macros
and node-gyp-build
. This is just tsc
, node
and napi-rs
.
What needs to be done is:
- Remove initial experimental scaffolding that was using
neon
. For example theneon-cli
package is no longer needed andcargo-cp-artifact
is also not required. - Remove initial experimental scaffolding that was using
napi-macros
andnode-addon-api
andnode-gyp
. All of these packages and related configuration is no longer needed. This includes removingnode-gyp-build
too. - We are only using
napi-rs
and the related rust and cargo tools are brought in from theshell.nix
. - Unrelated and useless packages should be removed like
threads
. - The
npm run napi-build
andnpm run napi-build-prod
should be integrated into thenpm run prebuild
script located insrc/scripts/prebuild.js
. - The entire
prebuild.js
was ported fromjs-db
which usesnode-gyp
. This does not usenode-gyp
at all, and instead needs to usenapi build
command instead. All relevant flags and options should be adapted tonapi build
which comes from the@napi-rs/cli
package. - The purpose of
prebuild.js
is be able to build binaries and put them into aprebuild
directory. This directory is packaged as part of the npm distribution, and so binary compiled artifacts are "prebuilt" before they are downloaded by downstream users. We should maintain this structure. - There is some work on native packages that spread their binary artifacts into different NPM pacakges, and for the npm to install the ones that are required, thus reducing the final closure size. Haven't experimented with this yet, but I see some other native packages making use of this pattern.
- Currently the
napi build
ends up putting the artifact intoquic.linux-x64-gnu.node
on the project root. This should be put into the equivalent prebuild directories that js-db does. - If we do use the same
prebuild
directories... we might recover the ability to usenode-gyp-build
to look it up. But right now all that logic is written intosrc/native/quiche.ts
. Alternatively we give up onnode-gyp-build
entirely and just use our own script to find the right bindings.
Note that on MacOS and Windows we are using homebrew and chocolatey respectively. This means the rust toolchain would come from those 2 areas instead of Nix. No way to use Nix on MacOS just yet, so it's just a good idea to ensure that we are in fact building with the same Rust version.
Additional context
- Clean up superfluous compilation flags js-db#43 - superfluous compilation flags are no longer a thing with the Rust toolchain, alot more efficient
- Cross-Compilation for linux-arm64 and win-arm64 TypeScript-Demo-Lib-Native#3
- MacOS Runner Nix Integration for Platform-Specific Build TypeScript-Demo-Lib-Native#1
- Follow how js-db looks and feels at the end, just knowing that rust toolchain is more streamlined
- Darwin universal architecture napi-rs/napi-rs#1397 - How to build universal binaries with
napi
.
Tasks
- 1. Remove initial experimental scaffolding that was using
neon
. For example theneon-cli
package is no longer needed andcargo-cp-artifact
is also not required. - 2. Remove initial experimental scaffolding that was using
napi-macros
andnode-addon-api
andnode-gyp
. All of these packages and related configuration is no longer needed. This includes removingnode-gyp-build
too. - 3. We are only using
napi-rs
and the related rust and cargo tools are brought in from theshell.nix
. - 4. Unrelated and useless packages should be removed like
threads
. - 6. The
npm run napi-build
andnpm run napi-build-prod
should be integrated into thenpm run prebuild
script located insrc/scripts/prebuild.js
. - 7. The entire
prebuild.js
was ported fromjs-db
which usesnode-gyp
. This does not usenode-gyp
at all, and instead needs to usenapi build
command instead. All relevant flags and options should be adapted tonapi build
which comes from the@napi-rs/cli
package. - 8. The purpose of
prebuild.js
is be able to build binaries and put them into aprebuild
directory. This directory is packaged as part of the npm distribution, and so binary compiled artifacts are "prebuilt" before they are downloaded by downstream users. We should maintain this structure. - 9. There is some work on native packages that spread their binary artifacts into different NPM pacakges, and for the npm to install the ones that are required, thus reducing the final closure size. Haven't experimented with this yet, but I see some other native packages making use of this pattern.
- 10. Currently the
napi build
ends up putting the artifact intoquic.linux-x64-gnu.node
on the project root. This should be put into the equivalent prebuild directories that js-db does. - 11. If we do use the same
prebuild
directories... we might recover the ability to usenode-gyp-build
to look it up. But right now all that logic is written intosrc/native/quiche.ts
. Alternatively we give up onnode-gyp-build
entirely and just use our own script to find the right bindings. - Test on CI/CD