[New Port Request] nodejs
Library name: node.js
Library description: Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.
Source repository URL: https://github.com/nodejs/node
Project homepage (if different from the source repository): https://nodejs.org/
Anything else that is useful to know when adding (such as optional features the library may have that should be included): None
I noticed that node.js can be embedded into c++ as a library.
But vcpkg doesn't seem to provide this library.Only a vcpkg-tool-nodejs package provided as a building tool.
If you wish to add this port in the future, you can reopen this issue, but we're closing it for now.
I too would like to see this port. I started trying to make my own port for this but have run into an issue where nodejs seems to only do in-source builds (which doesn't agree with vcpkg assumption to always use out-of-tree builds (one from debug and one for release).
have run into an issue where nodejs seems to only do in-source builds (which doesn't agree with vcpkg assumption to always use out-of-tree builds (one from debug and one for release).
@r-rojo It is possible to copy the source for each build type. (Some) maintainer function have an option to do that.
@dg0yt , I suppose it's possible to do that. However, after reading up on the node build process (and studying it as well), I've come to realize that the configure script provided is really just a Python script that configures a (Python) gyp build configuration (and also generates Makefiles). When configure is run with the --debug flag, it configures so that both Release and Debug configurations are built. Also, the build trees are at ${SOURCE_PATH}/out/(Debug|Release). When you run "make install", it only installs the Release files. What I've done for now is to create a port that calls vcpkg_execute_build process for configure, make all, and make install. After that, I call execute_build_process again to install the debug files. There's probably a much better way to do this which is why it would be nice to have a MS supported portfile for node. 😄
Well, after some more trial and error, I realize that configure with the "--debug" flag is not what I wanted. I'm now this (forgive the weird pseudocode):
- call configure with whatever flags necessary (prefix doesn't really matter here)
- for each config in (Release, Debug)
- call "make -C out BUILDTYPE=${config} -j ${VCPKG_CONCURRENCY}"
- call "python3 ./tools/installl.py install / ${CURRENT_PACKAGES_DIR} + (config == Debug ? "/debug" : '')"
install.py assumes prefix as /usr if only one argument is given which is why I give it "/" and ${CURRENT_PACKAGES_DIR} Also, I had to patch install.py to support installing from either out/Debug or out/Release as it only supports installing from out/Release.
@r-rojo have you any progress with this?
Hope this works, I want to use it to host nodejs.
ref: https://github.com/nodejs/node/issues/51824
@r-rojo do you have a fork, I can give you a hand if possible. I think Monkey Patch should be accepted, and the upstream changes in the future.
I want to make https://chromium.googlesource.com/v8/v8/+/refs/heads/main/samples/process.cc work in a CMake project.
If nodejs shared library can be installed by vcpkg, my part will be easy.
I do have a port file that I can use with some success. It's a big hack right now but it does most of what it needs. The part I'm struggling now is having other packages find it. I just made a fork and added what I have so far for the node port.
@r-rojo cmake part should be easy, you need custom them all, as nodejs does not support cmake native, they are gyp/gn funs, which inherits from v8
maybe we can set prefix for configure, install them, and then,
- Copy installed artifacts to vcpkg
- Generate a cmake config file to set the include dir and libraries, or simple a new dummy target
I think v8/uv/node three part is enough to link and work with
Port skia builds with gn and generates cmake config from gn desc. But the functions still need to be generalized.
Port skia builds with gn and generates cmake config from gn desc. But the functions still need to be generalized.
@dg0yt Hi, maybe we use some trick of cmake file glob to find core parts, no need to be so generalized here too:)
No system detection? No macros and conditional compiles? "Maybe". From my experience, this is not very portable and a comes with a maintenance burden backpack. Even "trivial" packages quickly turn out as not so trivial.
There is packages vcpkg-tool-gyp-next and vcpkg-gn available, may be it can help with making portfile for Node.js in some kind?
@congzhangzh , are you suggesting adding support for gyp in new vcpkg functions?
@congzhangzh , are you suggesting adding support for gyp in new vcpkg functions?
@r-rojo No, I do some nodejs build for Windows/Linux these days, I would prefer to configure/build/install by nodejs itself, and we focus on cmake part for use like:
- copy include files
- copy lib/dll/so files
- export an interface target
for windows:
vcbuild x64 dll debug?
: do the 1/2/3 steps
for linux:
# libuv needs to be a shard library, as we need it later, v8 should be sure to be static.
./configure --shared --debug-node --shared-libuv?
# do the 1/2/3 steps
for mac (TBD):
My mac book is intel and out of date, it's a little hard to test
@r-rojo Hi Rodrigo, just a message, I am trying to add a node port to vcpkg, It is very beginning.
A sample is first made, which uses a local nodejs install on Linux, hope the sample work after the node port is added to vcpkg! https://github.com/congzhangzh/vcpkg/tree/add_node_port
Btw, I found a great article 4 vcpkg: https://decovar.dev/blog/2022/10/30/cpp-dependencies-with-vcpkg/