@deepseek-ai/libreoffice-kit 0.1.5 → 0.2.0-alpha5
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/NOTICE +4 -0
- package/README.md +44 -8
- package/README.zh.md +45 -9
- package/lib/cli.js +109 -46
- package/lib/editor.js +2061 -0
- package/lib/index.js +109 -46
- package/lib/types/editor-protocol.d.ts +29 -0
- package/lib/types/editor-transport.d.ts +36 -0
- package/lib/types/editor-types.d.ts +119 -0
- package/lib/types/editor.d.ts +105 -0
- package/lib/types/engine.d.ts +4 -2
- package/lib/types/fonts.d.ts +4 -8
- package/lib/types/native-image-renderer.d.ts +0 -1
- package/lib/types/native-process.d.ts +1 -0
- package/lib/types/native.d.ts +30 -2
- package/lib/types/runtime.d.ts +2 -0
- package/lib/types/worker.d.ts +2 -2
- package/lib/worker.js +38 -31
- package/native-render/CMakeLists.txt +40 -0
- package/native-render/LICENSE +21 -0
- package/native-render/README.md +83 -0
- package/native-render/README.zh.md +83 -0
- package/native-render/include/dsh_render.h +101 -0
- package/native-render/include/dsh_render_engine.h +66 -0
- package/native-render/include/dsh_render_node.h +27 -0
- package/native-render/include/dsh_webgpu.h +52 -0
- package/native-render/index.d.ts +145 -0
- package/native-render/index.mjs +71 -0
- package/native-render/lib/browser/display.d.ts +46 -0
- package/native-render/lib/browser/display.js +128 -0
- package/native-render/lib/browser/index.d.ts +4 -0
- package/native-render/lib/browser/index.js +3 -0
- package/native-render/lib/browser/painters.d.ts +9 -0
- package/native-render/lib/browser/painters.js +180 -0
- package/native-render/lib/browser/types.d.ts +51 -0
- package/native-render/lib/browser/types.js +1 -0
- package/native-render/lib/electron/adapter.d.ts +9 -0
- package/native-render/lib/electron/adapter.js +118 -0
- package/native-render/lib/electron/index.d.ts +3 -0
- package/native-render/lib/electron/index.js +3 -0
- package/native-render/lib/electron/preload.d.ts +13 -0
- package/native-render/lib/electron/preload.js +47 -0
- package/native-render/lib/electron/transfer.d.ts +15 -0
- package/native-render/lib/electron/transfer.js +36 -0
- package/native-render/prebuilds/darwin-arm64/libdsh_render_sdk.a +0 -0
- package/native-render/prebuilds/darwin-arm64/manifest.json +34 -0
- package/native-render/prebuilds/darwin-arm64/render.node +0 -0
- package/native-render/prebuilds/darwin-x64/libdsh_render_sdk.a +0 -0
- package/native-render/prebuilds/darwin-x64/manifest.json +34 -0
- package/native-render/prebuilds/darwin-x64/render.node +0 -0
- package/native-render/prebuilds/win32-arm64/dsh_render_sdk.lib +0 -0
- package/native-render/prebuilds/win32-arm64/manifest.json +34 -0
- package/native-render/prebuilds/win32-arm64/render.node +0 -0
- package/native-render/prebuilds/win32-x64/dsh_render_sdk.lib +0 -0
- package/native-render/prebuilds/win32-x64/manifest.json +34 -0
- package/native-render/prebuilds/win32-x64/render.node +0 -0
- package/native-render/receipt.json +23 -0
- package/native-render/scripts/build-webgpu.mjs +197 -0
- package/native-render/scripts/build.mjs +43 -0
- package/native-render/scripts/metadata.mjs +47 -0
- package/native-render/scripts/source-identity.mjs +15 -0
- package/native-render/scripts/verify-prebuilds.mjs +14 -0
- package/native-render/sdk.json +45 -0
- package/native-render/src/node-producer.cc +595 -0
- package/native-render/src/producer-internal.h +8 -0
- package/native-render/src/producer.cc +306 -0
- package/native-render/src/receiver.cc +1050 -0
- package/native-render/src/relay-transport.inc +293 -0
- package/native-render/src/transport.cc +405 -0
- package/native-render/src/transport.h +80 -0
- package/native-render/src/webgpu.cc +214 -0
- package/native-render/src/win-delay-load.LICENSE +24 -0
- package/native-render/src/win-delay-load.cc +43 -0
- package/native-render/verify.d.mts +4 -0
- package/native-render/verify.mjs +101 -0
- package/native-render/webgpu-dependencies.json +51 -0
- package/package.json +95 -10
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"package": "@deepseek-ai/libreoffice-kit",
|
|
3
|
+
"version": "0.2.0-alpha5",
|
|
4
|
+
"protocolVersion": 1,
|
|
5
|
+
"files": {
|
|
6
|
+
"LICENSE": "ebb4f09972aee8608be255debaf78451a68e95c290f55c240dec2ecfa16ea6be",
|
|
7
|
+
"CMakeLists.txt": "4dee0a2707850fd7bcfca3b6f66bf12926cd108bd1099cefbb8281c6886cec26",
|
|
8
|
+
"sdk.json": "1f145c1edc16c2d3eac78e8d7cfa118d56670e127f62b8127aee09c8387c35b9",
|
|
9
|
+
"scripts/metadata.mjs": "a93a4911175971c32a39b09f57e0cdca318dcbfa6ce9bedfca34c624f8f206c2",
|
|
10
|
+
"webgpu-dependencies.json": "99fd5b4763f3621ffe72290ca5ddaa9c26f8d2404b54c9158f20f6fd29a403c2",
|
|
11
|
+
"scripts/build-webgpu.mjs": "e0e3f20c1bcffe7a61c6d7de4d9398661dd22c28f6305caed8fe6bb2d0b01c1a",
|
|
12
|
+
"include/dsh_render.h": "df9996b78481167007c0223c803dc38d72793fa23ed1e6cf4b713ce0291ae6a0",
|
|
13
|
+
"include/dsh_render_engine.h": "01b1e6c515fdff2c2544efc2b714073273644ca5adbbba098e02e474c4302a4f",
|
|
14
|
+
"include/dsh_render_node.h": "61cde0bf941f9f4808653d468eb50c8912e4271aa443f62247a57260da43d5bd",
|
|
15
|
+
"include/dsh_webgpu.h": "7bf92af0a56fb09f55ebd285cadd1da9cc700104f887a07e3cd147ece0293b09",
|
|
16
|
+
"src/producer.cc": "5ed4c8d03f16740f0369d9da5ff1cb9f5d675c5f1116605e0db3120b99d1f6f1",
|
|
17
|
+
"src/producer-internal.h": "b5bbfd2a4cc8d8b47bcf11c2ab16913d7ed06024bf012d8786ac216a401b664f",
|
|
18
|
+
"src/transport.cc": "6b508c805adbc3820ad241cff2e5feccf5cbca3d2f255a672530bb059abcfb3a",
|
|
19
|
+
"src/transport.h": "5f18bcdc201c8e2772aadfaf17ee5fab4ca6a9301872b8a74b2622db332253e0",
|
|
20
|
+
"src/relay-transport.inc": "1dc5ec8205a2fbb8ba425fbf5396a59f5ca80a57378a9e836bc366418e0b0551",
|
|
21
|
+
"src/webgpu.cc": "454a09cca8cb484cab10d49e55882fd945cdb7d39cd8757069abd2de72e3235f"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/** Build the producer adapter with unmodified, hash-pinned Dawn and its required dependencies. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { createReadStream, createWriteStream } from 'node:fs';
|
|
4
|
+
import { cp, mkdir, readFile, readdir, readlink, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import { availableParallelism } from 'node:os';
|
|
7
|
+
import { dirname, join, resolve } from 'node:path';
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
9
|
+
import { pipeline } from 'node:stream/promises';
|
|
10
|
+
import { webgpuSources } from './metadata.mjs';
|
|
11
|
+
|
|
12
|
+
const defaultRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
13
|
+
const sha256 = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
14
|
+
async function exists(path) {
|
|
15
|
+
try { await stat(path); return true; } catch (error) { if (error.code === 'ENOENT') return false; throw error; }
|
|
16
|
+
}
|
|
17
|
+
async function fileHash(path) {
|
|
18
|
+
const hash = createHash('sha256');
|
|
19
|
+
await pipeline(createReadStream(path), hash);
|
|
20
|
+
return hash.digest('hex');
|
|
21
|
+
}
|
|
22
|
+
function run(command, args, cwd, capture = false) {
|
|
23
|
+
const result = spawnSync(command, args, { cwd, env: { ...process.env, PYTHONDONTWRITEBYTECODE: '1' },
|
|
24
|
+
stdio: capture ? 'pipe' : 'inherit', encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 });
|
|
25
|
+
if (result.error) throw result.error;
|
|
26
|
+
if (result.status !== 0) throw new Error(`${command} exited ${result.status}: ${result.stderr ?? ''}`);
|
|
27
|
+
return result.stdout?.trim();
|
|
28
|
+
}
|
|
29
|
+
async function tree(directory, prefix = '') {
|
|
30
|
+
const result = {};
|
|
31
|
+
for (const entry of (await readdir(join(directory, prefix), { withFileTypes: true })).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
|
|
32
|
+
if (entry.name === '.git') continue;
|
|
33
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
34
|
+
const path = join(directory, relative);
|
|
35
|
+
if (entry.isDirectory()) Object.assign(result, await tree(directory, relative));
|
|
36
|
+
else if (entry.isSymbolicLink()) result[relative] = `link:${await readlink(path)}`;
|
|
37
|
+
else if (entry.isFile()) result[relative] = await fileHash(path);
|
|
38
|
+
else throw new Error(`Unsupported source entry: ${path}`);
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
function verifyTree(actual, expected, name) {
|
|
43
|
+
const changed = [...new Set([...Object.keys(actual), ...Object.keys(expected)])]
|
|
44
|
+
.filter(path => actual[path] !== expected[path]);
|
|
45
|
+
if (changed.length) throw new Error(`${name} differs from its pinned archive: ${changed.slice(0, 10).join(', ')}`);
|
|
46
|
+
}
|
|
47
|
+
/** Hash every source input in the native WebGPU SDK build recipe. */
|
|
48
|
+
export async function webgpuBuildSources(root = defaultRoot) {
|
|
49
|
+
const sources = {};
|
|
50
|
+
for (const file of webgpuSources)
|
|
51
|
+
sources[file] = await fileHash(join(root, file));
|
|
52
|
+
return sources;
|
|
53
|
+
}
|
|
54
|
+
async function prepare(name, dependency, cache) {
|
|
55
|
+
const base = join(cache, `${name}-${dependency.revision}`);
|
|
56
|
+
const directory = join(base, name);
|
|
57
|
+
const archive = `${base}.tar.gz`;
|
|
58
|
+
if (!(await exists(archive))) {
|
|
59
|
+
if (dependency.sourceTreeSha256) {
|
|
60
|
+
const repository = `${base}.git`;
|
|
61
|
+
await mkdir(repository, { recursive: true });
|
|
62
|
+
try {
|
|
63
|
+
run('git', ['init', '--bare'], repository);
|
|
64
|
+
run('git', ['fetch', '--depth=1', dependency.url, dependency.revision], repository);
|
|
65
|
+
run('git', ['-c', 'core.autocrlf=false', '-c', 'core.eol=lf', 'archive', '--format=tar.gz',
|
|
66
|
+
`--output=${archive}.download`, 'FETCH_HEAD'], repository);
|
|
67
|
+
} finally { await rm(repository, { recursive: true, force: true }); }
|
|
68
|
+
} else {
|
|
69
|
+
const response = await fetch(dependency.url);
|
|
70
|
+
if (!response.ok || !response.body) throw new Error(`Download ${name} failed: ${response.status}`);
|
|
71
|
+
await pipeline(response.body, createWriteStream(`${archive}.download`));
|
|
72
|
+
}
|
|
73
|
+
if (dependency.sha256 && await fileHash(`${archive}.download`) !== dependency.sha256) throw new Error(`${name} archive SHA-256 mismatch`);
|
|
74
|
+
await rename(`${archive}.download`, archive);
|
|
75
|
+
}
|
|
76
|
+
if (dependency.sha256 && await fileHash(archive) !== dependency.sha256) throw new Error(`${name} archive SHA-256 mismatch`);
|
|
77
|
+
// Re-extract the verified archive so a modified cached receipt cannot authorize modified sources.
|
|
78
|
+
await rm(base, { recursive: true, force: true });
|
|
79
|
+
await mkdir(directory, { recursive: true });
|
|
80
|
+
run('tar', ['-xzf', archive.replaceAll('\\', '/'), '-C', directory.replaceAll('\\', '/'), `--strip-components=${dependency.stripComponents}`], cache);
|
|
81
|
+
const expected = await tree(directory);
|
|
82
|
+
// Git archives are verified by complete file contents independently of archive metadata.
|
|
83
|
+
if (dependency.sourceTreeSha256 && sha256(JSON.stringify(expected)) !== dependency.sourceTreeSha256)
|
|
84
|
+
throw new Error(`${name} source tree SHA-256 mismatch`);
|
|
85
|
+
return { path: directory, files: expected, sha256: sha256(JSON.stringify(expected)) };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Build and install a self-contained native WebGPU SDK prefix.
|
|
90
|
+
* @param options - SDK source root, architecture, output/cache directories, optional pristine Dawn source and bounded parallelism.
|
|
91
|
+
* @returns Installed prefix; receipt.json identifies source archives, build configuration and installed bytes.
|
|
92
|
+
*/
|
|
93
|
+
export async function buildWebGPU({ root = defaultRoot, arch = process.arch, output, cache, source = process.env.DSH_DAWN_SOURCE,
|
|
94
|
+
jobs = Math.min(4, availableParallelism()), prepareOnly = false } = {}) {
|
|
95
|
+
root = resolve(root);
|
|
96
|
+
if (!['darwin', 'win32'].includes(process.platform) || !['arm64', 'x64'].includes(arch)) throw new Error('WebGPU SDK requires macOS or Windows x64/ARM64');
|
|
97
|
+
if (process.platform === 'win32' && process.env.VSCMD_ARG_TGT_ARCH !== arch)
|
|
98
|
+
throw new Error(`Initialize the MSVC developer environment for ${arch}`);
|
|
99
|
+
if (!Number.isSafeInteger(jobs) || jobs < 1) throw new Error('Build jobs must be a positive integer');
|
|
100
|
+
const platform = `${process.platform}-${arch}`;
|
|
101
|
+
output = resolve(output ?? join(root, 'prebuilds', platform, 'webgpu'));
|
|
102
|
+
cache = resolve(cache ?? join(root, '.build', 'webgpu'));
|
|
103
|
+
const dependencyCache = join(cache, 'dependencies');
|
|
104
|
+
await mkdir(dependencyCache, { recursive: true });
|
|
105
|
+
const manifestBytes = await readFile(join(root, 'webgpu-dependencies.json'));
|
|
106
|
+
const { dependencies } = JSON.parse(manifestBytes);
|
|
107
|
+
const results = await Promise.allSettled(Object.entries(dependencies).map(async ([name, dependency]) =>
|
|
108
|
+
[name, await prepare(name, dependency, dependencyCache)]));
|
|
109
|
+
for (const result of results) if (result.status === 'rejected') throw result.reason;
|
|
110
|
+
const prepared = Object.fromEntries(results.map(result => result.value));
|
|
111
|
+
let dawn = prepared.dawn.path;
|
|
112
|
+
if (source) {
|
|
113
|
+
dawn = resolve(source);
|
|
114
|
+
verifyTree(await tree(dawn), prepared.dawn.files, 'DSH_DAWN_SOURCE');
|
|
115
|
+
}
|
|
116
|
+
for (const [name, dependency] of Object.entries(dependencies)) {
|
|
117
|
+
if (name !== 'dawn' && !(await readFile(join(dawn, 'DEPS'), 'utf8')).includes(dependency.revision))
|
|
118
|
+
throw new Error(`${name} revision is absent from the pinned Dawn DEPS`);
|
|
119
|
+
}
|
|
120
|
+
if (prepareOnly) return { source: dawn, dependencies: prepared, output };
|
|
121
|
+
const cmake = process.env.DSH_CMAKE ?? 'cmake';
|
|
122
|
+
const python = run(process.env.DSH_PYTHON ?? (process.platform === 'win32' ? 'python' : 'python3'),
|
|
123
|
+
['-c', 'import sys; print(sys.executable)'], root, true);
|
|
124
|
+
const build = join(cache, process.platform === 'win32' ? `${platform}-clang` : platform);
|
|
125
|
+
const pathFlags = [[root, '/dsh-sdk'], [cache, '/dsh-build'], [dawn, '/dawn']]
|
|
126
|
+
.flatMap(([from, to]) => ['file', 'debug'].map(kind =>
|
|
127
|
+
`${process.platform === 'win32' ? '/clang:' : ''}-f${kind}-prefix-map="${from.replaceAll('\\', '/')}=${to}"`)).join(' ');
|
|
128
|
+
const off = [
|
|
129
|
+
'DAWN_FETCH_DEPENDENCIES', 'DAWN_BUILD_SAMPLES', 'DAWN_BUILD_TESTS', 'DAWN_BUILD_NODE_BINDINGS',
|
|
130
|
+
'DAWN_BUILD_BENCHMARKS', 'DAWN_BUILD_FUZZERS', 'DAWN_BUILD_PROTOBUF', 'DAWN_ENABLE_NULL',
|
|
131
|
+
'DAWN_ENABLE_D3D11', 'DAWN_ENABLE_DESKTOP_GL', 'DAWN_ENABLE_OPENGLES', 'DAWN_ENABLE_VULKAN',
|
|
132
|
+
'DAWN_ENABLE_SPIRV_VALIDATION', 'DAWN_ENABLE_WEBGPU_ON_WEBGPU', 'DAWN_USE_GLFW', 'DAWN_USE_X11',
|
|
133
|
+
'DAWN_USE_WAYLAND', 'DAWN_USE_WINDOWS_UI', 'DAWN_USE_BUILT_DXC', 'TINT_BUILD_CMD_TOOLS',
|
|
134
|
+
'TINT_BUILD_TESTS', 'TINT_BUILD_BENCHMARKS', 'TINT_BUILD_FUZZERS', 'TINT_BUILD_IR_BINARY',
|
|
135
|
+
'TINT_BUILD_SPV_READER', 'TINT_BUILD_SPV_WRITER', 'TINT_BUILD_GLSL_WRITER', 'TINT_BUILD_GLSL_VALIDATOR',
|
|
136
|
+
'TINT_BUILD_NULL_WRITER',
|
|
137
|
+
];
|
|
138
|
+
const definitions = {
|
|
139
|
+
DSH_RENDER_WEBGPU: 'ON', DSH_DAWN_SOURCE_DIR: dawn, CMAKE_BUILD_TYPE: 'Release',
|
|
140
|
+
CMAKE_INSTALL_PREFIX: output, CMAKE_INSTALL_LIBDIR: 'lib', CMAKE_POSITION_INDEPENDENT_CODE: 'ON',
|
|
141
|
+
CMAKE_MSVC_RUNTIME_LIBRARY: 'MultiThreadedDLL', Python3_EXECUTABLE: python,
|
|
142
|
+
DAWN_ENABLE_PIC: 'ON', DAWN_FORCE_SYSTEM_COMPONENT_LOAD: 'ON',
|
|
143
|
+
DAWN_ENABLE_METAL: process.platform === 'darwin' ? 'ON' : 'OFF',
|
|
144
|
+
DAWN_ENABLE_D3D12: process.platform === 'win32' ? 'ON' : 'OFF',
|
|
145
|
+
TINT_BUILD_MSL_WRITER: process.platform === 'darwin' ? 'ON' : 'OFF',
|
|
146
|
+
TINT_BUILD_HLSL_WRITER: process.platform === 'win32' ? 'ON' : 'OFF',
|
|
147
|
+
DAWN_ABSEIL_DIR: prepared['abseil-cpp'].path, DAWN_SPIRV_HEADERS_DIR: prepared['spirv-headers'].path,
|
|
148
|
+
DAWN_JINJA2_DIR: prepared.jinja2.path, DAWN_MARKUPSAFE_DIR: prepared.markupsafe.path,
|
|
149
|
+
...(process.platform === 'win32' ? {
|
|
150
|
+
CMAKE_C_COMPILER: 'clang-cl', CMAKE_CXX_COMPILER: 'clang-cl',
|
|
151
|
+
CMAKE_C_COMPILER_TARGET: arch === 'arm64' ? 'aarch64-pc-windows-msvc' : 'x86_64-pc-windows-msvc',
|
|
152
|
+
CMAKE_CXX_COMPILER_TARGET: arch === 'arm64' ? 'aarch64-pc-windows-msvc' : 'x86_64-pc-windows-msvc',
|
|
153
|
+
CMAKE_SYSTEM_NAME: 'Windows', CMAKE_SYSTEM_PROCESSOR: arch === 'arm64' ? 'ARM64' : 'AMD64',
|
|
154
|
+
CMAKE_C_FLAGS: pathFlags, CMAKE_CXX_FLAGS: pathFlags, CMAKE_EXE_LINKER_FLAGS: '', CMAKE_SHARED_LINKER_FLAGS: '',
|
|
155
|
+
} : {}),
|
|
156
|
+
...(process.platform === 'darwin' ? { CMAKE_C_FLAGS: pathFlags, CMAKE_CXX_FLAGS: pathFlags, CMAKE_OBJCXX_FLAGS: pathFlags, CMAKE_OSX_ARCHITECTURES: arch === 'x64' ? 'x86_64' : 'arm64', CMAKE_OSX_DEPLOYMENT_TARGET: '11.0' } : {}),
|
|
157
|
+
};
|
|
158
|
+
const configure = ['-S', root, '-B', build, '-G', 'Ninja', ...off.map(key => `-D${key}=OFF`),
|
|
159
|
+
...Object.entries(definitions).map(([key, value]) => `-D${key}=${value}`)];
|
|
160
|
+
const sources = await webgpuBuildSources(root);
|
|
161
|
+
const start = performance.now();
|
|
162
|
+
run(cmake, configure, root);
|
|
163
|
+
run(cmake, ['--build', build, '--config', 'Release', '--target', 'dsh_webgpu', '--parallel', String(jobs)], root);
|
|
164
|
+
run(cmake, ['--install', build, '--config', 'Release'], root);
|
|
165
|
+
for (const [name, dependency] of Object.entries(dependencies)) {
|
|
166
|
+
for (const license of dependency.licenses) {
|
|
167
|
+
const destination = join(output, 'licenses', name, license);
|
|
168
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
169
|
+
await cp(join(prepared[name].path, license), destination, { recursive: true });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
await cp(join(root, 'LICENSE'), join(output, 'licenses', 'DSH-LICENSE'));
|
|
173
|
+
const artifacts = await tree(output);
|
|
174
|
+
delete artifacts['receipt.json'];
|
|
175
|
+
for (const [file, hash] of Object.entries(sources))
|
|
176
|
+
if (await fileHash(join(root, file)) !== hash) throw new Error(`SDK source changed during build: ${file}`);
|
|
177
|
+
const receipt = { schemaVersion: 1, platform, sourceManifestSha256: sha256(manifestBytes), sources,
|
|
178
|
+
dependencies: Object.fromEntries(Object.entries(dependencies).map(([name, dependency]) =>
|
|
179
|
+
[name, { ...dependency, sourceTreeSha256: prepared[name].sha256 }])),
|
|
180
|
+
configure, jobs, elapsedSeconds: (performance.now() - start) / 1000,
|
|
181
|
+
cmake: run(cmake, ['--version'], root, true), artifacts };
|
|
182
|
+
await writeFile(join(output, 'receipt.json'), JSON.stringify(receipt, null, 2) + '\n');
|
|
183
|
+
return output;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url) {
|
|
187
|
+
const options = {};
|
|
188
|
+
for (let index = 2; index < process.argv.length; ++index) {
|
|
189
|
+
const flag = process.argv[index];
|
|
190
|
+
if (flag === '--prepare-only') { options.prepareOnly = true; continue; }
|
|
191
|
+
const key = { '--root': 'root', '--output': 'output', '--cache': 'cache', '--arch': 'arch', '--jobs': 'jobs', '--source': 'source' }[flag];
|
|
192
|
+
if (!key || !process.argv[index + 1] || process.argv[index + 1].startsWith('--')) throw new Error(`Invalid build argument: ${flag}`);
|
|
193
|
+
options[key] = key === 'jobs' ? Number(process.argv[++index]) : process.argv[++index];
|
|
194
|
+
}
|
|
195
|
+
const result = await buildWebGPU(options);
|
|
196
|
+
console.log(JSON.stringify(options.prepareOnly ? { source: result.source, output: result.output } : { output: result }));
|
|
197
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Build precompiled receiver and producer SDK with the host C++ toolchain. */
|
|
2
|
+
import { mkdirSync, existsSync, writeFileSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { dirname, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { updateSdkMetadata, hashFile } from './metadata.mjs';
|
|
8
|
+
import { nativeRenderSourceIdentity } from './source-identity.mjs';
|
|
9
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
10
|
+
const sdk = updateSdkMetadata(root);
|
|
11
|
+
const { sourceCommit, sourceDirty } = nativeRenderSourceIdentity(root);
|
|
12
|
+
const archIndex = process.argv.indexOf('--arch');
|
|
13
|
+
const arch = archIndex < 0 ? process.arch : process.argv[archIndex + 1];
|
|
14
|
+
if (!['arm64', 'x64'].includes(arch) || !['darwin', 'win32'].includes(process.platform)) throw new Error('Unsupported native render build architecture');
|
|
15
|
+
if (process.platform === 'win32' && arch !== process.arch && process.env.VSCMD_ARG_TGT_ARCH !== arch) throw new Error('Windows cross-build requires the matching MSVC developer environment');
|
|
16
|
+
const platform = `${process.platform}-${arch}`;
|
|
17
|
+
const output = resolve(root, 'prebuilds', platform);
|
|
18
|
+
mkdirSync(output, { recursive: true });
|
|
19
|
+
const nodeInclude = process.env.DSH_NODE_INCLUDE ?? ['/opt/homebrew/include/node', '/usr/local/include/node', '/usr/include/node'].find(path => existsSync(resolve(path, 'node_api.h')) && existsSync(resolve(path, 'uv.h')));
|
|
20
|
+
if (!nodeInclude || !existsSync(resolve(nodeInclude, 'node_api.h')) || !existsSync(resolve(nodeInclude, 'uv.h'))) throw new Error('Set DSH_NODE_INCLUDE to matching complete Node headers containing node_api.h and uv.h');
|
|
21
|
+
const run = (command, args) => {
|
|
22
|
+
const result = spawnSync(command, args, { cwd: root, stdio: 'inherit' });
|
|
23
|
+
if (result.error) throw result.error;
|
|
24
|
+
if (result.status !== 0) throw new Error(`${command} failed (${result.status})`);
|
|
25
|
+
};
|
|
26
|
+
if (process.platform === 'darwin') {
|
|
27
|
+
const common = ['-arch', arch === 'x64' ? 'x86_64' : 'arm64', '-mmacosx-version-min=11.0', '-std=c++17', '-O2', '-fPIC', '-Iinclude', '-Isrc', '-Wall', '-Wextra'];
|
|
28
|
+
const libs = ['-framework', 'IOSurface', '-framework', 'CoreFoundation', '-lbsm'];
|
|
29
|
+
run('clang++', [...common, '-I' + nodeInclude, '-DNAPI_VERSION=8', '-DNODE_GYP_MODULE_NAME=dsh_render', '-shared', '-undefined', 'dynamic_lookup', 'src/receiver.cc', 'src/node-producer.cc', 'src/producer.cc', 'src/transport.cc', ...libs, '-o', resolve(output, 'render.node')]);
|
|
30
|
+
for (const source of ['producer', 'transport']) run('clang++', [...common, '-c', `src/${source}.cc`, '-o', resolve(output, `${source}.o`)]);
|
|
31
|
+
run('ar', ['rcs', resolve(output, 'libdsh_render_sdk.a'), resolve(output, 'producer.o'), resolve(output, 'transport.o')]);
|
|
32
|
+
} else if (process.platform === 'win32') {
|
|
33
|
+
const nodeLib = process.env.DSH_NODE_LIB;
|
|
34
|
+
if (!nodeLib) throw new Error('Set DSH_NODE_LIB to the matching Node node.lib');
|
|
35
|
+
const common = ['/nologo', '/std:c++17', '/O2', '/EHsc', '/MD', '/D_WIN32_WINNT=0x0602', '/Iinclude', '/Isrc'];
|
|
36
|
+
run('cl', [...common, '/I' + nodeInclude, '/DNAPI_VERSION=8', '/DNODE_GYP_MODULE_NAME=dsh_render', '/LD', '/Fo' + output + '/', 'src/receiver.cc', 'src/node-producer.cc', 'src/producer.cc', 'src/transport.cc', 'src/win-delay-load.cc', '/link', '/DELAYLOAD:node.exe', 'delayimp.lib', '/OUT:' + resolve(output, 'render.node'), nodeLib, 'd3d11.lib', 'dxgi.lib', 'advapi32.lib', 'bcrypt.lib']);
|
|
37
|
+
for (const source of ['producer', 'transport']) run('cl', [...common, '/c', `src/${source}.cc`, '/Fo' + resolve(output, `${source}.obj`)]);
|
|
38
|
+
run('lib', ['/nologo', '/OUT:' + resolve(output, 'dsh_render_sdk.lib'), resolve(output, 'producer.obj'), resolve(output, 'transport.obj')]);
|
|
39
|
+
} else throw new Error(`Unsupported native render platform ${platform}`);
|
|
40
|
+
const files = process.platform === 'darwin' ? ['render.node', 'libdsh_render_sdk.a'] : ['render.node', 'dsh_render_sdk.lib'];
|
|
41
|
+
const hashes = Object.fromEntries(files.map(file => [file, createHash('sha256').update(readFileSync(resolve(output, file))).digest('hex')]));
|
|
42
|
+
const sources = Object.fromEntries(sdk.buildSources.map(file => [file, hashFile(resolve(root, file))]));
|
|
43
|
+
writeFileSync(resolve(output, 'manifest.json'), JSON.stringify({ sources, sourceCommit, sourceDirty, version: sdk.version, protocolVersion: sdk.protocolVersion, platform, files: hashes }, null, 2) + '\n');
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Shared source inventory and metadata for the native-render payload in LibreOffice Kit. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
export const sdkRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
8
|
+
export const targets = ['darwin-arm64', 'darwin-x64', 'win32-x64', 'win32-arm64'];
|
|
9
|
+
export const buildSources = [
|
|
10
|
+
'include/dsh_render.h', 'include/dsh_render_engine.h', 'include/dsh_render_node.h', 'include/dsh_webgpu.h',
|
|
11
|
+
'src/node-producer.cc', 'src/producer-internal.h', 'src/transport.h', 'src/transport.cc', 'src/relay-transport.inc',
|
|
12
|
+
'src/producer.cc', 'src/receiver.cc', 'src/win-delay-load.cc', 'src/win-delay-load.LICENSE', 'src/webgpu.cc',
|
|
13
|
+
'CMakeLists.txt', 'sdk.json', 'scripts/build.mjs', 'scripts/metadata.mjs', 'scripts/source-identity.mjs', 'scripts/build-webgpu.mjs', 'webgpu-dependencies.json',
|
|
14
|
+
];
|
|
15
|
+
export const webgpuSources = ['CMakeLists.txt', 'sdk.json', 'scripts/metadata.mjs', 'webgpu-dependencies.json',
|
|
16
|
+
'scripts/build-webgpu.mjs', 'include/dsh_render.h', 'include/dsh_render_engine.h', 'include/dsh_render_node.h',
|
|
17
|
+
'include/dsh_webgpu.h', 'src/producer.cc', 'src/producer-internal.h', 'src/transport.cc', 'src/transport.h',
|
|
18
|
+
'src/relay-transport.inc', 'src/webgpu.cc'];
|
|
19
|
+
export const presentationFiles = ['browser/index', 'browser/types', 'browser/painters', 'browser/display',
|
|
20
|
+
'electron/index', 'electron/adapter', 'electron/transfer', 'electron/preload']
|
|
21
|
+
.flatMap(file => [`lib/${file}.js`, `lib/${file}.d.ts`]);
|
|
22
|
+
export const payloadFiles = [
|
|
23
|
+
...presentationFiles,
|
|
24
|
+
'index.mjs', 'index.d.ts', 'verify.mjs', 'verify.d.mts', 'receipt.json',
|
|
25
|
+
'LICENSE', 'README.md', 'README.zh.md', ...buildSources,
|
|
26
|
+
'scripts/verify-prebuilds.mjs',
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
export function hashFile(file) {
|
|
30
|
+
return createHash('sha256').update(readFileSync(file)).digest('hex');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Generate source metadata from the single version owned by the public Kit package. */
|
|
34
|
+
export function updateSdkMetadata(root = sdkRoot) {
|
|
35
|
+
const kitFile = existsSync(join(root, '../package.json')) ? join(root, '../package.json') : join(root, '../entry/package.json');
|
|
36
|
+
const kit = JSON.parse(readFileSync(kitFile, 'utf8'));
|
|
37
|
+
const sdk = { version: kit.version, protocolVersion: 1, header: 'include/dsh_render.h',
|
|
38
|
+
sources: ['src/transport.cc', 'src/producer.cc'], cxxStandard: 17, platforms: targets,
|
|
39
|
+
staticLibraries: Object.fromEntries(targets.map(target => [target,
|
|
40
|
+
`prebuilds/${target}/${target.startsWith('win32-') ? 'dsh_render_sdk.lib' : 'libdsh_render_sdk.a'}`])),
|
|
41
|
+
buildSources };
|
|
42
|
+
writeFileSync(join(root, 'sdk.json'), JSON.stringify(sdk, null, 2) + '\n');
|
|
43
|
+
writeFileSync(join(root, 'receipt.json'), JSON.stringify({ package: '@deepseek-ai/libreoffice-kit',
|
|
44
|
+
version: kit.version, protocolVersion: 1,
|
|
45
|
+
files: Object.fromEntries(['LICENSE', ...webgpuSources].map(file => [file, hashFile(join(root, file))])) }, null, 2) + '\n');
|
|
46
|
+
return sdk;
|
|
47
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Source identity for native-render inputs; generated engine receipts are not SDK sources. */
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
|
|
4
|
+
/** Read the selected commit and whether the SDK or owning package metadata has local changes. */
|
|
5
|
+
export function nativeRenderSourceIdentity(directory, { expectedCommit, environment = process.env, requireClean = false } = {}) {
|
|
6
|
+
const git = args => execFileSync('git', args, { cwd: directory, encoding: 'utf8' }).trim();
|
|
7
|
+
const sourceCommit = git(['rev-parse', 'HEAD']);
|
|
8
|
+
if (!/^[a-f0-9]{40}$/.test(sourceCommit)) throw new Error('Native render requires a complete source commit');
|
|
9
|
+
if ((expectedCommit !== undefined && expectedCommit !== sourceCommit)
|
|
10
|
+
|| (environment.GITHUB_SHA && environment.GITHUB_SHA !== sourceCommit))
|
|
11
|
+
throw new Error('Native render selected source commit differs from HEAD');
|
|
12
|
+
const sourceDirty = git(['status', '--porcelain', '--untracked-files=normal', '--', '.', '../entry/package.json']) !== '';
|
|
13
|
+
if (requireClean && sourceDirty) throw new Error('Native render release staging requires clean SDK sources and Kit metadata');
|
|
14
|
+
return { sourceCommit, sourceDirty };
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Validate all four native-render payloads against their public Kit package version. */
|
|
2
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { sdkRoot } from './metadata.mjs';
|
|
6
|
+
import { verifyNativeRenderPrebuilds } from '../verify.mjs';
|
|
7
|
+
|
|
8
|
+
export async function verifyPrebuilds(directory = sdkRoot, sourceCommit) {
|
|
9
|
+
const kitFile = existsSync(join(directory, '../package.json')) ? join(directory, '../package.json') : join(directory, '../entry/package.json');
|
|
10
|
+
const kit = JSON.parse(readFileSync(kitFile, 'utf8'));
|
|
11
|
+
return verifyNativeRenderPrebuilds(directory, { version: kit.version, sourceCommit });
|
|
12
|
+
}
|
|
13
|
+
if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url)
|
|
14
|
+
console.log(JSON.stringify(await verifyPrebuilds(process.argv[2] && resolve(process.argv[2]), process.argv[3])));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2.0-alpha5",
|
|
3
|
+
"protocolVersion": 1,
|
|
4
|
+
"header": "include/dsh_render.h",
|
|
5
|
+
"sources": [
|
|
6
|
+
"src/transport.cc",
|
|
7
|
+
"src/producer.cc"
|
|
8
|
+
],
|
|
9
|
+
"cxxStandard": 17,
|
|
10
|
+
"platforms": [
|
|
11
|
+
"darwin-arm64",
|
|
12
|
+
"darwin-x64",
|
|
13
|
+
"win32-x64",
|
|
14
|
+
"win32-arm64"
|
|
15
|
+
],
|
|
16
|
+
"staticLibraries": {
|
|
17
|
+
"darwin-arm64": "prebuilds/darwin-arm64/libdsh_render_sdk.a",
|
|
18
|
+
"darwin-x64": "prebuilds/darwin-x64/libdsh_render_sdk.a",
|
|
19
|
+
"win32-x64": "prebuilds/win32-x64/dsh_render_sdk.lib",
|
|
20
|
+
"win32-arm64": "prebuilds/win32-arm64/dsh_render_sdk.lib"
|
|
21
|
+
},
|
|
22
|
+
"buildSources": [
|
|
23
|
+
"include/dsh_render.h",
|
|
24
|
+
"include/dsh_render_engine.h",
|
|
25
|
+
"include/dsh_render_node.h",
|
|
26
|
+
"include/dsh_webgpu.h",
|
|
27
|
+
"src/node-producer.cc",
|
|
28
|
+
"src/producer-internal.h",
|
|
29
|
+
"src/transport.h",
|
|
30
|
+
"src/transport.cc",
|
|
31
|
+
"src/relay-transport.inc",
|
|
32
|
+
"src/producer.cc",
|
|
33
|
+
"src/receiver.cc",
|
|
34
|
+
"src/win-delay-load.cc",
|
|
35
|
+
"src/win-delay-load.LICENSE",
|
|
36
|
+
"src/webgpu.cc",
|
|
37
|
+
"CMakeLists.txt",
|
|
38
|
+
"sdk.json",
|
|
39
|
+
"scripts/build.mjs",
|
|
40
|
+
"scripts/metadata.mjs",
|
|
41
|
+
"scripts/source-identity.mjs",
|
|
42
|
+
"scripts/build-webgpu.mjs",
|
|
43
|
+
"webgpu-dependencies.json"
|
|
44
|
+
]
|
|
45
|
+
}
|