npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cmake-node

v0.2.0

Published

node.js toolchain for cmake

Downloads

68

Readme

cmake-node

Node.js build system on top of CMake.

Features

  • No node.js dependencies
  • No network IO (no downloading headers or import libraries)
  • MinGW support for cross-compiling to Windows
  • WASM support (see below for an explanation)

Todo

  • osxcross support for cross-compiling to Darwin

Design

cmake-node provides an include file and an accompanying wrapper for CMake. In contrast to other projects, it avoids modification of the global state, and instead exposes just two functions: add_node_library and add_node_module.

cmake-node is very lightweight and requires no dependencies. This provides a nice alternative to other node build systems, which pull in half of npm just to build a project.

The latest NAPI headers are bundled and automatically added to your include paths. While there is a chance cmake-node could fall behind in updating these headers, it should not be that severe of a issue as NAPI provides a stable ABI. Support for other node headers (v8, node, openssl, nan, etc) is intentionally excluded for this reason.

While cmake-node requires no node.js dependencies, it does require that the user have certain other dependencies: this includes CMake itself, Visual Studio on Windows, Xcode on OSX, and Make on unix.

Example

CMakeLists.txt:

project(my_project LANGUAGES C)

include(NodeJS)

add_node_library(my_library STATIC src/my_lib.c)

add_node_module(my_project src/my_code.c)
target_compile_definitions(my_project PRIVATE FOOBAR=1)
target_link_libraries(my_project PRIVATE my_library)

To build:

$ cmake-node rebuild

To load (CJS):

const cmake = require('cmake-node');
const binding = cmake.load('my_project', __dirname);

To load (ESM):

import cmake from 'cmake-node';

const binding = cmake.load('my_project', import.meta.url);

Building for production

cmake-node commands accept a --production flag which will clean the workspace for release. This removes all files generated during the build aside from your resulting .node file.

$ cmake-node rebuild --production

It is recommended to put this in your package.json's install script.

MinGW Support

cmake-node allows native modules to be cross-compiled for win32 using the mingw toolchain.

$ cmake-node rebuild --mingw --arch=x64

The prefixed mingw toolchain must be in your PATH.

WASM Support

A while ago, some node.js contributors had the brilliant idea of exposing NAPI to WASM. In theory, this means you can cross-compile your NAPI module to WASM and have it work transparently. Combined with WASI, this means only minimal (or no) changes need to be made to your code. cmake-node has experimental support for this.

$ cmake-node rebuild --wasm --wasi-sdk=/path/to/wasi-sdk

This feature requires wasi-sdk 12 or above as it requires reactor support (i.e. -mexec-model=reactor).

You can find a proof-of-concept WASM NAPI module here (credit to @devsnek).

Usage

  Usage: cmake-node [options] [command] -- [cmake args]

  Options:

    -v, --version        output the version number
    -c, --config <type>  build type (default: Release)
    -C, --cmake <path>   path to cmake binary (default: cmake{,.exe})
    -r, --root <path>    path to root directory (default: .)
    -p, --production     clean all files except for .node files
    --node-bin <name>    name of node binary (win32 only)
    --node-def <path>    path to node.def (win32 only)
    --node-lib <path>    path to node.lib (win32 only)
    --node-exp <path>    path to node.exp/libnode.x (aix/zos only)
    --mingw              cross-compile for win32 using mingw
    --wasm               cross-compile for wasm using wasi-sdk
    --toolchain <file>   path to toolchain file
    -G, --gen <name>     generator name (see cmake --help)
    -A, --arch <arch>    select win32 arch (ia32, x64, arm, arm64)
    --wasi-sdk <path>    path to wasi-sdk
    -h, --help           output usage information

  Commands:

    install              install necessary files
    list                 list currently installed files
    clear                clear cache
    configure            configure package
    build                build package
    clean                clean root directory
    reconfigure          reconfigure package
    rebuild              rebuild package
    ui                   open ui for package (ccmake/cmake-gui)

Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license. You are also implicitly verifying that all code is your original work. </legalese>

License

  • Copyright (c) 2020, Christopher Jeffrey (MIT License).

See LICENSE for more info.