@customize-agent/cad-native 1.0.1 → 1.0.3
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 +7 -0
- package/README.md +5 -0
- package/build-windows.ps1 +9 -1
- package/cad-native.c +13 -2
- package/native/darwin-arm64/cad-native +0 -0
- package/native/win32-x64/cad-native.exe +0 -0
- package/package.json +1 -1
- package/scripts/check-native-cad-assets.cjs +7 -1
package/CMakeLists.txt
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
cmake_minimum_required(VERSION 3.20)
|
|
2
2
|
project(cad-native C)
|
|
3
3
|
|
|
4
|
+
# Windows 用户机不一定安装 VC++ 2015-2022 运行库;动态 CRT 会让 sidecar 在加载阶段
|
|
5
|
+
# 直接失败(0xC0000135,进程不产生 stderr,只能看到空错误)。静态 CRT 后 exe 只依赖
|
|
6
|
+
# KERNEL32 + 随包的 libredwg-0.dll。
|
|
7
|
+
if(MSVC)
|
|
8
|
+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
9
|
+
endif()
|
|
10
|
+
|
|
4
11
|
set(CMAKE_C_STANDARD 99)
|
|
5
12
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
6
13
|
|
package/README.md
CHANGED
|
@@ -49,6 +49,11 @@ Visual Studio 2022, and copies `libredwg-0.dll` and its runtime DLLs beside the
|
|
|
49
49
|
.\build-windows.ps1 -LibreDwgWin64Zip C:\path\to\libredwg-0.14-win64.zip
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
The sidecar links the **static** MSVC CRT (`CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded`). It must not
|
|
53
|
+
depend on `VCRUNTIME140.dll` or the UCRT: end-user machines without the VC++ 2015-2022
|
|
54
|
+
Redistributable would fail to start it at load time (exit `0xC0000135`, no stderr). The build script
|
|
55
|
+
verifies the dependency table with `dumpbin /dependents` and fails on any MSVC/UCRT runtime DLL.
|
|
56
|
+
|
|
52
57
|
The build scripts write the result to the platform directory:
|
|
53
58
|
|
|
54
59
|
- macOS: `native/darwin-arm64/cad-native` or `native/darwin-x64/cad-native`
|
package/build-windows.ps1
CHANGED
|
@@ -40,4 +40,12 @@ cmake --build $build --config Release --parallel
|
|
|
40
40
|
New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
|
|
41
41
|
Copy-Item (Join-Path $build 'Release\cad-native.exe') (Join-Path $OutDir 'cad-native.exe') -Force
|
|
42
42
|
Get-ChildItem -Path $work -Filter '*.dll' | Copy-Item -Destination $OutDir -Force
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
# 发布门禁:exe 不得依赖 MSVC/UCRT 运行库。用户机未装 VC++ 运行库时,动态 CRT
|
|
45
|
+
# 会在加载阶段失败(0xC0000135),进程不产生 stderr,现场只能看到空错误。
|
|
46
|
+
$exe = Join-Path $OutDir 'cad-native.exe'
|
|
47
|
+
$dependents = cmd /c "call `"$vcvars`" >nul && dumpbin /dependents `"$exe`""
|
|
48
|
+
if ($LASTEXITCODE -ne 0) { throw "dumpbin /dependents 执行失败:$($dependents -join '; ')" }
|
|
49
|
+
$runtime = $dependents | Select-String -Pattern 'VCRUNTIME|MSVCP|api-ms-win-crt|ucrtbase'
|
|
50
|
+
if ($runtime) { throw "cad-native.exe 仍依赖 MSVC/UCRT 运行库:$($runtime -join '; ')" }
|
|
51
|
+
Write-Host "built $OutDir\cad-native.exe (static CRT; with official libredwg runtime DLLs)"
|
package/cad-native.c
CHANGED
|
@@ -131,7 +131,14 @@ static void emit_entity_fields(FILE *out, Dwg_Object *obj, void *entity) {
|
|
|
131
131
|
if (f->is_string || is_string_type(f->type)) {
|
|
132
132
|
char *raw = NULL; int isnew = 0;
|
|
133
133
|
if (dwg_dynapi_entity_utf8text(entity, obj->name, f->name, &raw, &isnew, NULL) && raw) pair_text(out, code, raw);
|
|
134
|
+
#ifndef _WIN32
|
|
135
|
+
/* isnew=1 means LibreDWG allocated the UTF-8 string with its own allocator.
|
|
136
|
+
* On Windows the sidecar links the official libredwg-0.dll (msvcrt heap),
|
|
137
|
+
* which is a different heap from this sidecar's CRT: freeing it here
|
|
138
|
+
* corrupts the heap (0xC0000374 / 0xC0000005). This process handles one
|
|
139
|
+
* DWG and exits, so the Windows build leaves library strings to the OS. */
|
|
134
140
|
if (isnew && raw) free(raw);
|
|
141
|
+
#endif
|
|
135
142
|
continue;
|
|
136
143
|
}
|
|
137
144
|
if (is_int_type(f->type)) {
|
|
@@ -240,14 +247,18 @@ static char *resolve_block_header_name(Dwg_Data *dwg, Dwg_Object_BLOCK_HEADER *h
|
|
|
240
247
|
char *name = NULL; int isnew = 0;
|
|
241
248
|
if (!dwg_dynapi_entity_utf8text(h, "BLOCK_HEADER", "name", &name, &isnew, NULL) || !name) return NULL;
|
|
242
249
|
char *result = strdup(name);
|
|
243
|
-
|
|
250
|
+
#ifndef _WIN32
|
|
251
|
+
if (isnew) free(name); /* library-owned on Windows: see emit_entity_fields */
|
|
252
|
+
#endif
|
|
244
253
|
if (result && result[0] == '*' && h->block_entity) {
|
|
245
254
|
Dwg_Object *bl = h->block_entity->obj ? h->block_entity->obj : dwg_ref_object_silent(dwg, h->block_entity);
|
|
246
255
|
if (bl && bl->fixedtype == DWG_TYPE_BLOCK && bl->tio.entity && bl->tio.entity->tio.BLOCK) {
|
|
247
256
|
char *bn = NULL; int bnew = 0;
|
|
248
257
|
if (dwg_dynapi_entity_utf8text(bl->tio.entity->tio.BLOCK, "BLOCK", "name", &bn, &bnew, NULL) && bn && *bn) {
|
|
249
258
|
free(result); result = strdup(bn);
|
|
250
|
-
|
|
259
|
+
#ifndef _WIN32
|
|
260
|
+
if (bnew) free(bn); /* library-owned on Windows: see emit_entity_fields */
|
|
261
|
+
#endif
|
|
251
262
|
}
|
|
252
263
|
}
|
|
253
264
|
}
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -25,8 +25,14 @@ if (fs.existsSync(path.join(native, 'win32-x64', 'cad-native.exe'))
|
|
|
25
25
|
&& !fs.existsSync(path.join(native, 'win32-x64', 'libredwg-0.dll'))) {
|
|
26
26
|
missing.push(['win32-x64', 'libredwg-0.dll']);
|
|
27
27
|
}
|
|
28
|
+
// 静态 CRT 门禁(跨平台生效):动态 CRT 的导入表含 VCRUNTIME140,用户机未装 VC++ 运行库时
|
|
29
|
+
// 进程在加载阶段就失败(0xC0000135 且无 stderr)。发布前不依赖 Windows 工具即可拦截。
|
|
30
|
+
const winExe = path.join(native, 'win32-x64', 'cad-native.exe');
|
|
31
|
+
if (fs.existsSync(winExe) && fs.readFileSync(winExe).includes(Buffer.from('VCRUNTIME140'))) {
|
|
32
|
+
missing.push(['win32-x64', 'cad-native.exe 依赖 VCRUNTIME140(须用静态 CRT 重建)']);
|
|
33
|
+
}
|
|
28
34
|
if (missing.length) {
|
|
29
|
-
console.error('[cad-native]
|
|
35
|
+
console.error('[cad-native] 原生 DWG sidecar 缺失或不合格:');
|
|
30
36
|
for (const [platform, name] of missing) console.error(` - native/${platform}/${name}`);
|
|
31
37
|
console.error('请在各平台用 CMake/Clang(macOS)或 CMake/MSVC(Windows)构建后再打包;禁止用 MinGW 交叉编译。');
|
|
32
38
|
process.exit(1);
|