Skip to content

Commit 9a327fa

Browse files
authored
Merge pull request #723 from zeromq/cmake-build
feat: update cmake-ts to 1.0.0
2 parents 4e785d5 + af16a22 commit 9a327fa

File tree

6 files changed

+15
-310
lines changed

6 files changed

+15
-310
lines changed

.github/workflows/CI.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
- name: Build Native Windows 32
153153
if: ${{ matrix.os == 'windows-2019' && matrix.node_arch == 'ia32' }}
154154
run:
155-
node ./node_modules/cmake-ts/build/main.js named-configs windows-x86
155+
node --enable-source-maps ./node_modules/cmake-ts/build/main.js build --config win32-ia32-release
156156

157157
- name: Use Node 20
158158
if: ${{ matrix.native }}

lib/load-addon.js

+2-82
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/load-addon.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-98
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"homepage": "http://zeromq.github.io/zeromq.js/",
2121
"dependencies": {
22-
"cmake-ts": "^0.6.1",
22+
"cmake-ts": "1.0.0",
2323
"node-addon-api": "^8.3.0"
2424
},
2525
"devDependencies": {
@@ -71,7 +71,7 @@
7171
"engines": {
7272
"node": ">= 12"
7373
},
74-
"packageManager": "pnpm@10.6.5",
74+
"packageManager": "pnpm@10.8.0",
7575
"overrides": {
7676
"typescript": "~4.9.5",
7777
"node-gyp": "10.0.1"
@@ -113,8 +113,8 @@
113113
"docs.preview": "servor --browse --reload docs",
114114
"docs.dev": "run-s docs.build docs.preview",
115115
"docs.deploy": "run-s docs.build && gh-pages --dist \"./docs\"",
116-
"build.native": "cmake-ts nativeonly",
117-
"build.native.debug": "cross-env npm_config_zmq_enable_sanitizer_undefined=true cmake-ts dev-os-only",
116+
"build.native": "cmake-ts build --logger=debug",
117+
"build.native.debug": "cross-env npm_config_zmq_enable_sanitizer_undefined=true cmake-ts build --config debug",
118118
"build": "run-p build.js build.native",
119119
"build.debug": "run-s build.js build.native.debug",
120120
"test": "run-s test.unit test.examples",
@@ -142,100 +142,6 @@
142142
},
143143
"cmake-ts": {
144144
"nodeAPI": "node-addon-api",
145-
"configurations": [
146-
{
147-
"name": "linux-x64",
148-
"os": "linux",
149-
"arch": "x64",
150-
"runtime": "node",
151-
"runtimeVersion": "12.22.12"
152-
},
153-
{
154-
"name": "linux-x64-dev",
155-
"dev": true,
156-
"buildType": "Debug",
157-
"os": "linux",
158-
"arch": "x64",
159-
"runtime": "node",
160-
"runtimeVersion": "12.22.12"
161-
},
162-
{
163-
"name": "darwin-arm64-dev",
164-
"dev": true,
165-
"buildType": "Debug",
166-
"os": "darwin",
167-
"arch": "arm64",
168-
"runtime": "node",
169-
"runtimeVersion": "12.22.12"
170-
},
171-
{
172-
"name": "windows-x64-dev",
173-
"dev": true,
174-
"buildType": "Debug",
175-
"os": "win32",
176-
"arch": "x64",
177-
"runtime": "node",
178-
"runtimeVersion": "12.22.12"
179-
},
180-
{
181-
"name": "windows-x64",
182-
"os": "win32",
183-
"arch": "x64",
184-
"runtime": "node",
185-
"runtimeVersion": "12.22.12"
186-
},
187-
{
188-
"name": "windows-x86",
189-
"os": "win32",
190-
"arch": "ia32",
191-
"runtime": "node",
192-
"runtimeVersion": "12.22.12"
193-
},
194-
{
195-
"name": "darwin-x64",
196-
"os": "darwin",
197-
"arch": "x64",
198-
"runtime": "node",
199-
"runtimeVersion": "12.22.12"
200-
},
201-
{
202-
"name": "darwin-arm64",
203-
"os": "darwin",
204-
"arch": "arm64",
205-
"runtime": "node",
206-
"runtimeVersion": "12.22.12"
207-
},
208-
{
209-
"name": "linux-x64-electron",
210-
"os": "linux",
211-
"arch": "x64",
212-
"runtime": "electron",
213-
"runtimeVersion": "12.22.12"
214-
},
215-
{
216-
"name": "windows-x64-electron",
217-
"os": "win32",
218-
"arch": "x64",
219-
"runtime": "electron",
220-
"runtimeVersion": "12.22.12"
221-
},
222-
{
223-
"name": "darwin-x64-electron",
224-
"os": "darwin",
225-
"arch": "x64",
226-
"runtime": "electron",
227-
"runtimeVersion": "12.22.12"
228-
},
229-
{
230-
"name": "darwin-arm64-electron",
231-
"os": "darwin",
232-
"arch": "arm64",
233-
"runtime": "electron",
234-
"runtimeVersion": "12.22.12"
235-
}
236-
],
237-
"targetDirectory": "build",
238-
"buildType": "Release",
239145
"projectName": "addon"
240146
},
241147
"keywords": [

pnpm-lock.yaml

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/load-addon.ts

+2-123
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,5 @@
1+
import {loadAddon} from "cmake-ts/build/loader"
12
import path from "path"
2-
import fs from "fs"
33

4-
function errStr(error: unknown) {
5-
return error instanceof Error
6-
? `${error.name}: ${error.message}\n${error.stack}`
7-
: String(error)
8-
}
9-
10-
function devWarn(message: string) {
11-
if (process.env.NODE_ENV !== "production") {
12-
console.warn(message)
13-
}
14-
}
15-
16-
function findAddon(): any | undefined {
17-
let addon: undefined | any = undefined
18-
try {
19-
const buildDir = path.resolve(__dirname, "..", "build")
20-
21-
const manifest = JSON.parse(
22-
fs.readFileSync(path.resolve(buildDir, "manifest.json"), "utf-8"),
23-
) as Record<string, string>
24-
25-
// compatible addons (abi -> addon path)
26-
const compatibleAddons: Map<BuildConfiguration, string> = new Map()
27-
28-
const libc = detectLibc()
29-
30-
const configs = Object.keys(manifest)
31-
for (const configStr of configs) {
32-
const config = JSON.parse(configStr) as BuildConfiguration
33-
34-
// check if the config is compatible with the current runtime
35-
if (
36-
config.os !== process.platform ||
37-
config.arch !== process.arch ||
38-
config.libc !== libc
39-
) {
40-
continue
41-
}
42-
43-
const addonRelativePath = manifest[configStr]
44-
compatibleAddons.set(config, path.resolve(buildDir, addonRelativePath))
45-
}
46-
if (compatibleAddons.size === 0) {
47-
throw new Error(
48-
`No compatible zeromq.js addon found for ${process.platform} ${process.arch} ${libc}. The candidates were:\n${configs.join(
49-
"\n",
50-
)}`,
51-
)
52-
}
53-
54-
// sort the compatible abis in descending order
55-
const compatibleAddonsSorted = [...compatibleAddons.entries()].sort(
56-
([c1, _p1], [c2, _p2]) => {
57-
return (c2.abi ?? 0) - (c1.abi ?? 0)
58-
},
59-
)
60-
61-
// try each available addon ABI
62-
for (const [_config, addonPath] of compatibleAddonsSorted) {
63-
try {
64-
addon = require(addonPath)
65-
break
66-
} catch (err) {
67-
if (fs.existsSync(addonPath)) {
68-
devWarn(
69-
`Failed to load addon at ${addonPath}: ${errStr(err)}\nTrying others...`,
70-
)
71-
} else {
72-
devWarn(`No addon.node found in ${addonPath}\nTrying others...`)
73-
}
74-
}
75-
}
76-
} catch (err) {
77-
throw new Error(`Failed to load zeromq.js addon.node: ${errStr(err)}`)
78-
}
79-
80-
if (addon === undefined) {
81-
throw new Error("No compatible zeromq.js addon found")
82-
}
83-
84-
return addon
85-
}
86-
87-
/**
88-
* Build configuration (from cmake-ts)
89-
*/
90-
type BuildConfiguration = {
91-
name: string
92-
dev: boolean
93-
os: typeof process.platform
94-
arch: typeof process.arch
95-
runtime: string
96-
runtimeVersion: string
97-
toolchainFile: string | null
98-
CMakeOptions?: {name: string; value: string}[]
99-
addonSubdirectory: string
100-
// list of additional definitions to fixup node quirks for some specific versions
101-
additionalDefines: string[]
102-
/** The ABI number that is used by the runtime. */
103-
abi?: number
104-
/** The libc that is used by the runtime. */
105-
libc?: string
106-
}
107-
108-
/**
109-
* Detect the libc used by the runtime (from cmake-ts)
110-
*/
111-
function detectLibc() {
112-
if (process.platform === "linux") {
113-
if (fs.existsSync("/etc/alpine-release")) {
114-
return "musl"
115-
}
116-
return "glibc"
117-
} else if (process.platform === "darwin") {
118-
return "libc"
119-
} else if (process.platform === "win32") {
120-
return "msvc"
121-
}
122-
return "unknown"
123-
}
124-
125-
const addon = findAddon()
4+
const addon = loadAddon(path.resolve(__dirname, "..", "build"))
1265
export default addon

0 commit comments

Comments
 (0)