You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Docs on publishing of header-only C++ libs (include in node c++ modules) #20
We are increasingly working on small node C++ modules that depend on header-only C++ libs.
Node.js's Nan module has pioneered a best practice for how to include header only C++ libs in node C++ addons by simply adding a package.json and include_dirs.js file to the root of the project. I think we should follow the lead of howNan does this and package all our C++ header only libs in npm as well as mason. I think publishing in two places is worth it because it makes including the libraries from node modules very easy and consistent with how JS modules work.
method
Add:
package.json
include_dirs.js
files parameter to package.json so that only the include/ directory is included
Example:
{
"name": "@mapbox/geometry-hpp",
"version": "0.9.0",
"description": "A C++ header only geometry type library",
"main": "./include_dirs.js",
"repository" : {
"type" : "git",
"url" : "git://github.com/mapbox/geometry.hpp.git"
},
"files": [
"include"
]
}
Then test that only the right files are going to be packaged:
npm pack
tar -ztvf *tgz
^^ that should list just the headers and the default files npm includes like README.md and package.json etc
Nice @springmeyer! You may have a look over at hpp-skel as well, which implements some of the features you mention above. The README has a brief description of publishing as well.
Instead we'll need to come up with some other method to recommend and consistently use via node c++ modules, like using a shell script + mason like carmen-cache does
This is now implemented in node-cpp-skel. To recap the idea is:
We no longer publish any header only C++ projects to npm
We only publish to mason
To include these header only C++ projects we integration mason into the node build system
changed the title [-]Docs on npm publishing of header-only C++ libs[/-][+]Docs on publishing of header-only C++ libs (include in node c++ modules)[/+]on Jun 30, 2017
Activity
springmeyer commentedon Jan 12, 2017
The drawbacks of publishing C++ header-only libs in npm are:
node_moduleseven when deployment is done with binaries (and they are essentially unused in that case)These are downsides enough that npm publishing of C++ headers is not the ideal method / best practice at Mapbox.
Instead we'll need to come up with some other method to recommend and consistently use via node c++ modules, like using a shell script + mason like carmen-cache does to install rocksdb (https://github.com/mapbox/carmen-cache/blob/1aaf88413be2243e3e3c772b1a9c777ea527578c/binding.gyp#L3-L16 + https://github.com/mapbox/carmen-cache/blob/4182501f748e2ca2635485cbd51e17b6c49329f1/install_mason.sh. This would have the added benefit that it would work for both header only libs and dependencies that are precompiled libs.
mapsam commentedon Jan 26, 2017
Nice @springmeyer! You may have a look over at hpp-skel as well, which implements some of the features you mention above. The README has a brief description of publishing as well.
https://github.com/mapbox/hpp-skel
move back to npm packages for protozero - refs mapbox/mason/396 mapbo…
springmeyer commentedon Jun 30, 2017
This is now implemented in node-cpp-skel. To recap the idea is:
Now that the best practice is in place the remaining actions are:
[-]Docs on npm publishing of header-only C++ libs[/-][+]Docs on publishing of header-only C++ libs (include in node c++ modules)[/+]