@huaqiu/js-gerbv 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +151 -0
- package/LICENSE +674 -0
- package/README.md +71 -2
- package/include/config.h +34 -0
- package/include/gettext.h +9 -0
- package/index.js +41 -0
- package/package.json +46 -4
- package/prebuilds/darwin-arm64/gerbv_node.node +0 -0
- package/prebuilds/darwin-arm64/libglib-2.0.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libintl.8.dylib +0 -0
- package/prebuilds/darwin-arm64/libpcre2-8.0.dylib +0 -0
- package/prebuilds/darwin-arm64/meta.json +9 -0
- package/prebuilds/win32-x64/gerbv_node.node +0 -0
- package/prebuilds/win32-x64/libffi-8.dll +0 -0
- package/prebuilds/win32-x64/libgcc_s_seh-1.dll +0 -0
- package/prebuilds/win32-x64/libgio-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libglib-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libgmodule-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libgobject-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libiconv-2.dll +0 -0
- package/prebuilds/win32-x64/libintl-8.dll +0 -0
- package/prebuilds/win32-x64/libpcre2-8-0.dll +0 -0
- package/prebuilds/win32-x64/libstdc++-6.dll +0 -0
- package/prebuilds/win32-x64/libwinpthread-1.dll +0 -0
- package/prebuilds/win32-x64/meta.json +9 -0
- package/prebuilds/win32-x64/zlib1.dll +0 -0
- package/scripts/cmake-build.js +231 -0
- package/scripts/ensure-gerbv.js +42 -0
- package/scripts/pack-prebuild.js +208 -0
- package/scripts/smoke.js +25 -0
- package/shim/gdk/gdk.h +15 -0
- package/shim/gdk/gdkkeysyms.h +3 -0
- package/shim/gtk/gtk.h +7 -0
- package/src/addon.cc +191 -0
- package/src/gerber_min.c +67 -0
- package/src/gerbv_stubs.c +79 -0
- package/vcpkg.json +8 -0
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
#
|
|
1
|
+
# js-gerbv
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Node N-API 封装 [efa/gerbv](https://github.com/efa/gerbv) 核心导出路径(RS-274X / Excellon)。
|
|
4
|
+
|
|
5
|
+
仓库:https://github.com/Huaqiu-Electronics/js-gerbv
|
|
6
|
+
|
|
7
|
+
> 与 libgerbv 一并使用时,整体按 **GPL-2.0-or-later** 义务理解(见 `package.json`)。根目录 `LICENSE` 为仓库初始文件。
|
|
8
|
+
|
|
9
|
+
## 布局
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
prebuilds/<platform>-<arch>/gerbv_node.node # CI / 本机 pack 产物
|
|
13
|
+
build/gerbv_node.node # 本地 cmake 输出
|
|
14
|
+
vendor/gerbv/ # 构建时浅克隆(gitignore)
|
|
15
|
+
index.js # 按平台加载
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`platform-arch` 例:`darwin-arm64`、`linux-x64`、`win32-x64`。Windows 还会拷贝 glib 等运行时 DLL 到同目录。
|
|
19
|
+
|
|
20
|
+
## 本机构建
|
|
21
|
+
|
|
22
|
+
| 平台 | 依赖 |
|
|
23
|
+
|------|------|
|
|
24
|
+
| macOS | `brew install glib pkg-config cmake`;Node ≥ 20 |
|
|
25
|
+
| Linux | `libglib2.0-dev pkg-config cmake` |
|
|
26
|
+
| Windows | CMake + vcpkg `glib:x64-windows`(设 `VCPKG_ROOT`),或 MSYS2 mingw64(自动检测 `C:/msys64`,需 `glib2`/`pkgconf`/`gcc`) |
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install
|
|
30
|
+
npm run build # ensure-gerbv → cmake → pack prebuild
|
|
31
|
+
npm run smoke
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
可选:`GERBV_SRC=/path/to/gerbv` 指向已有 efa/gerbv 树,跳过克隆。
|
|
35
|
+
|
|
36
|
+
## 在应用中使用
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
const gerbv = require("@huaqiu/js-gerbv");
|
|
40
|
+
const img = gerbv.createImage();
|
|
41
|
+
gerbv.addLine(img, 0, 0, 0.5, 0, 0.01);
|
|
42
|
+
const buf = gerbv.exportRs274x(img);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
安装(含已发布的 **darwin-arm64** prebuild,无需本机编):
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install @huaqiu/js-gerbv
|
|
49
|
+
# 或尚未上 npm 时:
|
|
50
|
+
npm install github:Huaqiu-Electronics/js-gerbv#v0.1.2
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
GitHub Release 资产:`js-gerbv-v*-darwin-arm64.tar.gz`、`js-gerbv-v*-win32-x64.tar.gz`(见 Releases)。
|
|
54
|
+
|
|
55
|
+
本地联调可用 `"@huaqiu/js-gerbv": "file:../js-gerbv"`。
|
|
56
|
+
|
|
57
|
+
### 发布 mac prebuild
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm run build && npm run smoke # 产出 prebuilds/darwin-arm64(含捆绑 dylib)
|
|
61
|
+
git add prebuilds/darwin-arm64
|
|
62
|
+
git commit -m "chore: add darwin-arm64 prebuild"
|
|
63
|
+
git tag v0.1.2 && git push origin main --tags # 触发 release workflow
|
|
64
|
+
# npm(需登录或仓库 secret NPM_TOKEN;scoped 包需 public):
|
|
65
|
+
npm publish --access public
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## CI
|
|
69
|
+
|
|
70
|
+
`.github/workflows/ci.yml`:`macos-14` / `ubuntu-22.04` / `windows-2022` 矩阵编 prebuild 并上传 artifact。
|
|
71
|
+
|
|
72
|
+
不支持单机交叉编译到 Windows;请在对应 OS runner 上编。
|
package/include/config.h
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#ifndef GERBV_NODE_CONFIG_H
|
|
2
|
+
#define GERBV_NODE_CONFIG_H
|
|
3
|
+
|
|
4
|
+
#define VERSION "2.10.0-hqpcb-lite"
|
|
5
|
+
#define PACKAGE "gerbv"
|
|
6
|
+
#define PACKAGE_BUGREPORT ""
|
|
7
|
+
#define PACKAGE_NAME "gerbv"
|
|
8
|
+
#define PACKAGE_STRING "gerbv 2.10.0-hqpcb-lite"
|
|
9
|
+
#define PACKAGE_TARNAME "gerbv"
|
|
10
|
+
#define PACKAGE_VERSION "2.10.0-hqpcb-lite"
|
|
11
|
+
|
|
12
|
+
#define HAVE_CONFIG_H 1
|
|
13
|
+
#define HAVE_STRING_H 1
|
|
14
|
+
#define HAVE_STDLIB_H 1
|
|
15
|
+
#define HAVE_UNISTD_H 1
|
|
16
|
+
#define HAVE_LIBGEN_H 1
|
|
17
|
+
|
|
18
|
+
/* headless: no gettext catalog */
|
|
19
|
+
#undef ENABLE_NLS
|
|
20
|
+
#define gettext(str) (str)
|
|
21
|
+
#define dgettext(d, str) (str)
|
|
22
|
+
#define dcgettext(d, str, c) (str)
|
|
23
|
+
#define ngettext(a, b, n) ((n) == 1 ? (a) : (b))
|
|
24
|
+
#define gettext_noop(str) (str)
|
|
25
|
+
|
|
26
|
+
/* Prefer GDK stubs over cairo in public header */
|
|
27
|
+
#define RENDER_USING_GDK 1
|
|
28
|
+
|
|
29
|
+
#ifndef DEBUG
|
|
30
|
+
#define DEBUG 0
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
#endif
|
|
34
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#ifndef GERBV_NODE_GETTEXT_H
|
|
2
|
+
#define GERBV_NODE_GETTEXT_H
|
|
3
|
+
#define gettext(String) (String)
|
|
4
|
+
#define dgettext(Domain, String) (String)
|
|
5
|
+
#define dcgettext(Domain, String, Type) (String)
|
|
6
|
+
#define ngettext(Msgid1, Msgid2, N) ((N) == 1 ? (Msgid1) : (Msgid2))
|
|
7
|
+
#define dngettext(Domain, Msgid1, Msgid2, N) ((N) == 1 ? (Msgid1) : (Msgid2))
|
|
8
|
+
#define gettext_noop(String) (String)
|
|
9
|
+
#endif
|
package/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 加载当前平台的 gerbv_node 原生插件。
|
|
3
|
+
* 优先 prebuilds/<platform>-<arch>/,其次 build/。
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
|
|
10
|
+
function platformKey() {
|
|
11
|
+
return process.platform + "-" + process.arch;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function candidates() {
|
|
15
|
+
const key = platformKey();
|
|
16
|
+
const root = __dirname;
|
|
17
|
+
return [
|
|
18
|
+
path.join(root, "prebuilds", key, "gerbv_node.node"),
|
|
19
|
+
path.join(root, "build", "gerbv_node.node"),
|
|
20
|
+
path.join(root, "build", "Release", "gerbv_node.node"),
|
|
21
|
+
path.join(root, "build", "Debug", "gerbv_node.node"),
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function resolveAddon() {
|
|
26
|
+
for (const p of candidates()) {
|
|
27
|
+
if (fs.existsSync(p)) return p;
|
|
28
|
+
}
|
|
29
|
+
throw new Error(
|
|
30
|
+
"gerbv_node.node not found for " +
|
|
31
|
+
platformKey() +
|
|
32
|
+
".\nTried:\n - " +
|
|
33
|
+
candidates().join("\n - ") +
|
|
34
|
+
"\nBuild: npm run build (see https://github.com/Huaqiu-Electronics/js-gerbv)"
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const addonPath = resolveAddon();
|
|
39
|
+
module.exports = require(addonPath);
|
|
40
|
+
module.exports.__addonPath = addonPath;
|
|
41
|
+
module.exports.__platformKey = platformKey();
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huaqiu/js-gerbv",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Node N-API binding for libgerbv (efa/gerbv) RS-274X/Drill export",
|
|
5
|
+
"license": "GPL-2.0-or-later",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Huaqiu-Electronics/js-gerbv.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/Huaqiu-Electronics/js-gerbv/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/Huaqiu-Electronics/js-gerbv#readme",
|
|
14
|
+
"main": "index.js",
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"ensure-gerbv": "node scripts/ensure-gerbv.js",
|
|
21
|
+
"build": "node scripts/ensure-gerbv.js && node scripts/cmake-build.js && node scripts/pack-prebuild.js",
|
|
22
|
+
"pack": "node scripts/pack-prebuild.js",
|
|
23
|
+
"smoke": "node scripts/smoke.js",
|
|
24
|
+
"prepack": "node -e \"const fs=require('fs');if(!fs.existsSync('prebuilds')){console.error('missing prebuilds/; run npm run build');process.exit(1)}\"",
|
|
25
|
+
"install:deps": "npm install --no-fund --no-audit"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"index.js",
|
|
32
|
+
"prebuilds/**",
|
|
33
|
+
"src/**",
|
|
34
|
+
"include/**",
|
|
35
|
+
"shim/**",
|
|
36
|
+
"CMakeLists.txt",
|
|
37
|
+
"scripts/**",
|
|
38
|
+
"vcpkg.json",
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"node-addon-api": "^8.9.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"node-api-headers": "^1.9.0"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 跨平台 CMake 配置并编译 gerbv_node。
|
|
4
|
+
* 环境变量:
|
|
5
|
+
* CMAKE_BUILD_TYPE / GERBV_BUILD_TYPE — Debug|Release(默认 Release)
|
|
6
|
+
* CMAKE_PREFIX_PATH / VCPKG_ROOT — Windows 找 glib
|
|
7
|
+
* NODE_INC — 覆盖 node 头路径
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
|
|
11
|
+
const { spawnSync } = require("child_process");
|
|
12
|
+
const fs = require("fs");
|
|
13
|
+
const path = require("path");
|
|
14
|
+
const os = require("os");
|
|
15
|
+
|
|
16
|
+
const root = path.resolve(__dirname, "..");
|
|
17
|
+
const buildDir = path.join(root, "build");
|
|
18
|
+
const buildType =
|
|
19
|
+
process.env.GERBV_BUILD_TYPE || process.env.CMAKE_BUILD_TYPE || "Release";
|
|
20
|
+
|
|
21
|
+
function run(cmd, args, opts = {}) {
|
|
22
|
+
console.log("+", cmd, args.join(" "));
|
|
23
|
+
// Do not use shell:true — Windows would split arguments containing spaces
|
|
24
|
+
// (e.g. -DCMAKE_JS_INC=C:\Program Files\nodejs\include\node).
|
|
25
|
+
const r = spawnSync(cmd, args, {
|
|
26
|
+
stdio: "inherit",
|
|
27
|
+
shell: false,
|
|
28
|
+
env: process.env,
|
|
29
|
+
...opts,
|
|
30
|
+
});
|
|
31
|
+
if (r.status !== 0) {
|
|
32
|
+
process.exit(r.status == null ? 1 : r.status);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function which(bin) {
|
|
37
|
+
const r = spawnSync(
|
|
38
|
+
process.platform === "win32" ? "where" : "which",
|
|
39
|
+
[bin],
|
|
40
|
+
{ encoding: "utf8", shell: process.platform === "win32" }
|
|
41
|
+
);
|
|
42
|
+
return r.status === 0 ? String(r.stdout).split(/\r?\n/)[0].trim() : "";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function nodeInc() {
|
|
46
|
+
if (process.env.NODE_INC) return process.env.NODE_INC;
|
|
47
|
+
try {
|
|
48
|
+
return require("path").dirname(process.execPath) === process.execPath
|
|
49
|
+
? ""
|
|
50
|
+
: require("child_process")
|
|
51
|
+
.execSync('node -p "require(\'path\').dirname(process.execPath)"', {
|
|
52
|
+
encoding: "utf8",
|
|
53
|
+
})
|
|
54
|
+
.trim();
|
|
55
|
+
} catch (_) {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function resolveNodeInc() {
|
|
61
|
+
if (process.env.NODE_INC) return process.env.NODE_INC;
|
|
62
|
+
// Prefer headers next to the running node binary (official installers).
|
|
63
|
+
const candidates = [
|
|
64
|
+
path.join(path.dirname(process.execPath), "include", "node"),
|
|
65
|
+
path.join(path.dirname(process.execPath), "..", "include", "node"),
|
|
66
|
+
];
|
|
67
|
+
// Homebrew node@20 etc.
|
|
68
|
+
if (process.platform === "darwin") {
|
|
69
|
+
candidates.push("/opt/homebrew/include/node");
|
|
70
|
+
candidates.push("/usr/local/include/node");
|
|
71
|
+
}
|
|
72
|
+
if (process.platform === "linux") {
|
|
73
|
+
candidates.push("/usr/include/node");
|
|
74
|
+
}
|
|
75
|
+
for (const c of candidates) {
|
|
76
|
+
if (fs.existsSync(path.join(c, "node_api.h")) || fs.existsSync(path.join(c, "node.h"))) {
|
|
77
|
+
return c;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Let CMake fall back to the `node-api-headers` npm package.
|
|
81
|
+
return "";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Windows without vcpkg: use MSYS2 mingw64 glib (matches the MinGW toolchain).
|
|
86
|
+
* Mutates PATH / pkg-config env and returns extra CMake args.
|
|
87
|
+
*/
|
|
88
|
+
function setupMsys2() {
|
|
89
|
+
if (process.platform !== "win32" || process.env.VCPKG_ROOT) return [];
|
|
90
|
+
const root = process.env.MSYS2_ROOT || "C:/msys64";
|
|
91
|
+
const mingw = path.join(root, "mingw64");
|
|
92
|
+
const bin = path.join(mingw, "bin");
|
|
93
|
+
if (!fs.existsSync(path.join(bin, "gcc.exe"))) return [];
|
|
94
|
+
process.env.PATH = bin + path.delimiter + (process.env.PATH || "");
|
|
95
|
+
const prefix = process.env.CMAKE_PREFIX_PATH;
|
|
96
|
+
process.env.CMAKE_PREFIX_PATH = prefix ? mingw + path.delimiter + prefix : mingw;
|
|
97
|
+
const pc = path.join(mingw, "lib", "pkgconfig");
|
|
98
|
+
if (fs.existsSync(pc)) {
|
|
99
|
+
const prev = process.env.PKG_CONFIG_PATH;
|
|
100
|
+
process.env.PKG_CONFIG_PATH = prev ? pc + path.delimiter + prev : pc;
|
|
101
|
+
}
|
|
102
|
+
const pkgconf = path.join(bin, "pkg-config.exe");
|
|
103
|
+
if (fs.existsSync(pkgconf)) return ["-DPKG_CONFIG_EXECUTABLE=" + pkgconf];
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Windows: link against node.lib so N-API symbols resolve at link time.
|
|
109
|
+
* node-gyp caches it under %LOCALAPPDATA%/node-gyp/Cache/<version>/<arch>/node.lib.
|
|
110
|
+
*/
|
|
111
|
+
function resolveNodeLib() {
|
|
112
|
+
if (process.env.CMAKE_JS_LIB) return process.env.CMAKE_JS_LIB;
|
|
113
|
+
const candidates = [path.join(path.dirname(process.execPath), "node.lib")];
|
|
114
|
+
const local =
|
|
115
|
+
process.env.LOCALAPPDATA || path.join(os.homedir(), "AppData", "Local");
|
|
116
|
+
candidates.push(
|
|
117
|
+
path.join(
|
|
118
|
+
local,
|
|
119
|
+
"node-gyp",
|
|
120
|
+
"Cache",
|
|
121
|
+
process.versions.node,
|
|
122
|
+
process.arch,
|
|
123
|
+
"node.lib"
|
|
124
|
+
)
|
|
125
|
+
);
|
|
126
|
+
for (const c of candidates) {
|
|
127
|
+
if (fs.existsSync(c)) return c;
|
|
128
|
+
}
|
|
129
|
+
return "";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function cmakeGeneratorArgs() {
|
|
133
|
+
if (process.platform !== "win32") return [];
|
|
134
|
+
// Prefer Ninja if present; else VS 2022.
|
|
135
|
+
if (which("ninja")) {
|
|
136
|
+
return ["-G", "Ninja"];
|
|
137
|
+
}
|
|
138
|
+
return ["-G", "Visual Studio 17 2022", "-A", "x64"];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function cmakePrefixArgs() {
|
|
142
|
+
const args = [];
|
|
143
|
+
const prefixes = [];
|
|
144
|
+
if (process.env.CMAKE_PREFIX_PATH) {
|
|
145
|
+
prefixes.push(process.env.CMAKE_PREFIX_PATH);
|
|
146
|
+
}
|
|
147
|
+
if (process.env.VCPKG_ROOT) {
|
|
148
|
+
const triplet = process.env.VCPKG_DEFAULT_TRIPLET || "x64-windows";
|
|
149
|
+
const installed = path.join(process.env.VCPKG_ROOT, "installed", triplet);
|
|
150
|
+
prefixes.push(installed);
|
|
151
|
+
args.push(
|
|
152
|
+
"-DCMAKE_TOOLCHAIN_FILE=" +
|
|
153
|
+
path.join(process.env.VCPKG_ROOT, "scripts", "buildsystems", "vcpkg.cmake")
|
|
154
|
+
);
|
|
155
|
+
// 让 PkgConfig 能找到 vcpkg 的 glib .pc
|
|
156
|
+
const pc = path.join(installed, "lib", "pkgconfig");
|
|
157
|
+
if (fs.existsSync(pc)) {
|
|
158
|
+
const prev = process.env.PKG_CONFIG_PATH || "";
|
|
159
|
+
process.env.PKG_CONFIG_PATH = prev ? pc + path.delimiter + prev : pc;
|
|
160
|
+
}
|
|
161
|
+
const pkgconfBin = path.join(installed, "tools", "pkgconf");
|
|
162
|
+
if (fs.existsSync(pkgconfBin)) {
|
|
163
|
+
process.env.PATH = pkgconfBin + path.delimiter + (process.env.PATH || "");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (prefixes.length) {
|
|
167
|
+
args.push("-DCMAKE_PREFIX_PATH=" + prefixes.join(";"));
|
|
168
|
+
}
|
|
169
|
+
return args;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function main() {
|
|
173
|
+
const msys2Args = setupMsys2();
|
|
174
|
+
const cmake = which("cmake");
|
|
175
|
+
if (!cmake) {
|
|
176
|
+
console.error("error: cmake not found in PATH");
|
|
177
|
+
process.exit(1);
|
|
178
|
+
}
|
|
179
|
+
fs.mkdirSync(buildDir, { recursive: true });
|
|
180
|
+
|
|
181
|
+
const nodeIncPath = resolveNodeInc();
|
|
182
|
+
const configure = [
|
|
183
|
+
"-S",
|
|
184
|
+
root,
|
|
185
|
+
"-B",
|
|
186
|
+
buildDir,
|
|
187
|
+
"-DCMAKE_BUILD_TYPE=" + buildType,
|
|
188
|
+
...cmakeGeneratorArgs(),
|
|
189
|
+
...cmakePrefixArgs(),
|
|
190
|
+
...msys2Args,
|
|
191
|
+
];
|
|
192
|
+
if (nodeIncPath) {
|
|
193
|
+
configure.push("-DCMAKE_JS_INC=" + nodeIncPath);
|
|
194
|
+
}
|
|
195
|
+
if (process.platform === "win32") {
|
|
196
|
+
const nodeLib = resolveNodeLib();
|
|
197
|
+
if (nodeLib) configure.push("-DCMAKE_JS_LIB=" + nodeLib);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
run(cmake, configure);
|
|
201
|
+
|
|
202
|
+
const buildArgs = ["--build", buildDir, "--config", buildType];
|
|
203
|
+
// Parallel
|
|
204
|
+
const jobs = Math.max(2, (os.cpus() || []).length || 2);
|
|
205
|
+
if (process.platform === "win32") {
|
|
206
|
+
buildArgs.push("--parallel", String(jobs));
|
|
207
|
+
} else {
|
|
208
|
+
buildArgs.push("--parallel", String(jobs));
|
|
209
|
+
}
|
|
210
|
+
run(cmake, buildArgs);
|
|
211
|
+
|
|
212
|
+
// Normalize: ensure build/gerbv_node.node exists (VS puts it under Release/)
|
|
213
|
+
const flat = path.join(buildDir, "gerbv_node.node");
|
|
214
|
+
if (!fs.existsSync(flat)) {
|
|
215
|
+
for (const sub of ["Release", "Debug", "RelWithDebInfo"]) {
|
|
216
|
+
const p = path.join(buildDir, sub, "gerbv_node.node");
|
|
217
|
+
if (fs.existsSync(p)) {
|
|
218
|
+
fs.copyFileSync(p, flat);
|
|
219
|
+
console.log("normalized", p, "->", flat);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (!fs.existsSync(flat)) {
|
|
225
|
+
console.error("error: gerbv_node.node missing after build");
|
|
226
|
+
process.exit(1);
|
|
227
|
+
}
|
|
228
|
+
console.log("built", flat);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
main();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 确保 vendor/gerbv 存在(浅克隆 efa/gerbv)。
|
|
4
|
+
* 可用 GERBV_SRC 指向已有源码树以跳过克隆。
|
|
5
|
+
*/
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const { spawnSync } = require("child_process");
|
|
9
|
+
const fs = require("fs");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
|
|
12
|
+
const root = path.resolve(__dirname, "..");
|
|
13
|
+
const dest = process.env.GERBV_SRC
|
|
14
|
+
? path.resolve(process.env.GERBV_SRC)
|
|
15
|
+
: path.join(root, "vendor", "gerbv");
|
|
16
|
+
const header = path.join(dest, "src", "gerbv.h");
|
|
17
|
+
|
|
18
|
+
function main() {
|
|
19
|
+
if (fs.existsSync(header)) {
|
|
20
|
+
console.log("gerbv ok", dest);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (process.env.GERBV_SRC) {
|
|
24
|
+
console.error("error: GERBV_SRC set but missing", header);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
28
|
+
console.log("[gerbv] cloning https://github.com/efa/gerbv …");
|
|
29
|
+
const r = spawnSync(
|
|
30
|
+
"git",
|
|
31
|
+
["clone", "--depth", "1", "https://github.com/efa/gerbv.git", dest],
|
|
32
|
+
{ stdio: "inherit" }
|
|
33
|
+
);
|
|
34
|
+
if (r.status !== 0) process.exit(r.status == null ? 1 : r.status);
|
|
35
|
+
if (!fs.existsSync(header)) {
|
|
36
|
+
console.error("error: clone finished but missing", header);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
console.log("gerbv ok", dest);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
main();
|