cmake-ts re-imagined
New features
Build configs, Cross-compilation, and new CLI
Now, cmake-ts can build the projects with built-in configurations that are selected depending on the arguments and the environment. This includes cross-compilation for different architectures, including Windows arm64, Linux arm64, etc.
cmake-ts build
cmake-ts build --config debug
You can cross-compile by specifying the built-in cross configs
cmake-ts build --config cross-win32-arm64-release
CLI Arguments
build
command:
Usage: cmake-ts build [options]
Build the project
Options:
--config, --configs <configs...>
Named config(s) to build, which could be from default configs or the ones defined in the config file (package.json)
If no config is provided, it will build for the current runtime on the current system with the Release build type
The default configs are combinations of `<Runtime>`, `<BuildType>`, `<Platform>`, and `<Architecture>`.
- `<Runtime>`: the runtime to use
e.g.: `node`, `electron`, `iojs`
- `<BuildType>`: the cmake build type (optimization level)
e.g.: `debug`, `release`, `relwithdebinfo`, or `minsizerel`
- `<Platform>`: the target platform
e.g.: `win32`, `linux`, `darwin`, `aix`, `android`, `freebsd`, `haiku`, `openbsd`, `sunos`, `cygwin`, `netbsd`
- `<Architecture>`: the target architecture
e.g.: `x64`, `arm64`, `ia32`, `arm`, `loong64`, `mips`, `mipsel`, `ppc`, `ppc64`, `riscv64`, `s390`, `s390x`
Any combination of `<BuildType>`, `<Runtime>`, `<Platform>`, and `<Architecture>` is valid. Some examples:
- `release`
- `debug`
- `relwithdebinfo`
- `node-release`
- `node-debug`
- `electron-release`
- `electron-debug`
- `win32-x64`
- `win32-x64-debug`
- `linux-x64-debug`
- `linux-x64-node-debug`
- `linux-x64-electron-release`
- `darwin-x64-node-release`
- `darwin-arm64-node-release`
- `darwin-arm64-electron-relwithdebinfo`
To explicitly indicate cross-compilation, prefix the config name with \`cross-\`:
- \`cross-win32-ia32-node-release\`
- \`cross-linux-arm64-node-release\`
- \`cross-darwin-x64-electron-relwithdebinfo\`
You can also define your own configs in the config file (package.json).
- `<ConfigName>`: the name of the config
e.g.: `my-config`
The configs can also be in format of `named-<property>`, which builds the configs that match the property.
- `named-os`: build all the configs in the config file that have the same OS
- `named-os-dev`: build all the configs in the config file that have the same OS and `dev` is true
- `named-all`: build all the configs in the config file
The configs can be combined with `,` or multiple `--configs` flags. They will be merged together.
(default: [])
-h, --help display help for command
Runtime Addon Loader
The runtime addon loader allows you to load the addon for the current runtime during runtime.
In ES modules:
import { loadAddon } from 'cmake-ts/build/loader.mjs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const addon = loadAddon(path.resolve(__dirname, '..', 'build'));
or in CommonJS:
const { loadAddon } = require('cmake-ts/build/loader.js');
const addon = loadAddon(path.resolve(__dirname, '..', 'build'));
You can pass the types of the addon to the loader to get type safety:
type MyAddon = {
myFunction: (name: string) => void;
};
const addon = loadAddon<MyAddon>(path.resolve(__dirname, '..', 'build'));
Changelog
- feat: introduce build configs, triplets, and Cmake config + revamp arg parsing by @aminya in #42
- test: run the zeromq tests in CI + smoke tests by @aminya in #45
- fix: improve the logger + add deprecation warnings + update dev-deps by @aminya in #47
- fix: prevent conflict between binaries by @aminya in #48
- fix: fix cmake-ts build not working without configs by @aminya in #49
- feat: support cross-compilation by @aminya in #50
- feat: set up Windows toolchain variables for cross-compilation by @aminya in #51
- feat: add the runtime loader module by @aminya in #53
- fix: prevent test/download/build conflicts in parallel runs by @aminya in #54
- test: add tests for the utils by @aminya in #55
Full Changelog: v0.6.0...v1.0.0