@unieai/libreoffice-kit-wasm 0.0.0-stage → 0.2.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.
Files changed (51) hide show
  1. package/README.md +7 -2
  2. package/assets/dsoffice.cjs +26 -0
  3. package/assets/dsoffice.data +0 -0
  4. package/assets/dsoffice.data.js.metadata +1 -0
  5. package/assets/dsoffice.wasm +4 -0
  6. package/assets/manifest.json +1888 -0
  7. package/licenses/LICENSE +4666 -0
  8. package/licenses/NOTICE +63 -0
  9. package/licenses/Rabi-Harness-MIT.txt +28 -0
  10. package/package.json +22 -4
  11. package/prebuilds.json +128 -0
  12. package/sources/build-autogen.input +35 -0
  13. package/sources/core-source.json +4 -0
  14. package/sources/docs/ui-resources.md +123 -0
  15. package/sources/engine/build-identity.mjs +49 -0
  16. package/sources/engine/core-source.mjs +27 -0
  17. package/sources/engine/document-operations.hxx +51 -0
  18. package/sources/engine/ui-resource-policy.mjs +33 -0
  19. package/sources/engine/wasm-source/autogen.input +33 -0
  20. package/sources/engine/wasm-source/build.mjs +300 -0
  21. package/sources/engine/wasm-source/lok.cxx +428 -0
  22. package/sources/engine/wasm-source/patches/0001-macos-build-tools.patch +87 -0
  23. package/sources/engine/wasm-source/patches/0002-system-font-demand.patch +322 -0
  24. package/sources/engine/wasm-source/patches/0003-node-runtime.patch +99 -0
  25. package/sources/engine/wasm-source/patches/0004-system-fonts-only.patch +10 -0
  26. package/sources/engine/wasm-source/patches/0005-cross-build-rules.patch +46 -0
  27. package/sources/engine/wasm-source/patches/0006-wasm-external-platforms.patch +55 -0
  28. package/sources/engine/wasm-source/patches/0008-disable-link-updates.patch +30 -0
  29. package/sources/engine/wasm-source/patches/0009-disable-optional-curl.patch +11 -0
  30. package/sources/engine/wasm-source/patches/0010-refresh-component-registry.patch +11 -0
  31. package/sources/engine/wasm-source/patches/0011-preserve-optimization-with-prefix-maps.patch +21 -0
  32. package/sources/engine/wasm-source/patches/0012-anonymize-explicit-source-paths.patch +39 -0
  33. package/sources/engine/wasm-source/patches/0023-pdfium-for-embedded-graphics.patch +14 -0
  34. package/sources/engine/wasm-source/patches/0024-pdfium-emscripten-platform.patch +11 -0
  35. package/sources/engine/wasm-source/patches/0025-browser-editing.patch +18 -0
  36. package/sources/engine/wasm-source/patches/0028-synchronous-workbook-calculation.patch +64 -0
  37. package/sources/engine/wasm-source/patches/0029-unloaded-external-blip.patch +21 -0
  38. package/sources/engine/wasm-source/patches/0030-no-password-strength-ui.patch +117 -0
  39. package/sources/engine/wasm-source/patches/0031-size-optimization-lto.patch +26 -0
  40. package/sources/engine/wasm-source/patches/0047-defer-offscreen-canvas-output.patch +59 -0
  41. package/sources/engine/wasm-source/slim.mjs +74 -0
  42. package/sources/engine/wasm-source/source.json +16 -0
  43. package/sources/engine/wasm-source/source.mjs +12 -0
  44. package/sources/engine/wasm-source/stage.mjs +91 -0
  45. package/sources/scripts/checkout-wasm.mjs +24 -0
  46. package/sources/scripts/core-checkout.mjs +39 -0
  47. package/sources/scripts/minimize-ui-resources.py +198 -0
  48. package/sources/scripts/pack-utils.mjs +69 -0
  49. package/sources/scripts/platform-matrix.mjs +122 -0
  50. package/sources/scripts/verify-artifacts.mjs +261 -0
  51. package/sources/source-changes.patch +1081 -0
@@ -0,0 +1,11 @@
1
+ --- a/external/pdfium/Library_pdfium.mk
2
+ +++ b/external/pdfium/Library_pdfium.mk
3
+ @@ -713,7 +713,7 @@
4
+ ))
5
+ endif
6
+
7
+ -ifneq (,$(filter LINUX FREEBSD OPENBSD,$(OS)))
8
+ +ifneq (,$(filter LINUX FREEBSD OPENBSD EMSCRIPTEN,$(OS)))
9
+ # fxge
10
+ $(eval $(call gb_Library_add_generated_exception_objects,pdfium,\
11
+ UnpackedTarball/pdfium/core/fxge/linux/fx_linux_impl \
@@ -0,0 +1,18 @@
1
+ --- a/vcl/headless/svpinst.cxx
2
+ +++ b/vcl/headless/svpinst.cxx
3
+ @@ -299,6 +299,15 @@
4
+ }
5
+
6
+ #if defined __EMSCRIPTEN__
7
+ +
8
+ +// A browser-owned LibreOfficeKit instance yields between messages instead of
9
+ +// entering the application's Emscripten main loop. Never wait on the Worker.
10
+ +extern "C" bool rabi_lok_yield()
11
+ +{
12
+ + SolarMutexGuard guard;
13
+ + auto* instance = SvpSalInstance::s_pDefaultInstance;
14
+ + return instance && instance->ImplYield(false, true);
15
+ +}
16
+
17
+ static void loop(void * arg) {
18
+ SolarMutexGuard g;
@@ -0,0 +1,64 @@
1
+ --- a/include/LibreOfficeKit/LibreOfficeKit.h
2
+ +++ b/include/LibreOfficeKit/LibreOfficeKit.h
3
+ @@ -570,6 +570,9 @@
4
+ /// @see lok::Document::setColorPreviewState().
5
+ void (*setColorPreviewState) (LibreOfficeKitDocument* pThis, int nId, bool nEnabled);
6
+
7
+ + // DeepSeek Kit: synchronously calculate every formula; return zero on failure.
8
+ + int (*calculateAll)(LibreOfficeKitDocument* pThis);
9
+ +
10
+ #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
11
+ };
12
+
13
+ --- a/desktop/source/lib/init.cxx
14
+ +++ b/desktop/source/lib/init.cxx
15
+ @@ -107,6 +107,7 @@
16
+ #include <com/sun/star/frame/DispatchResultState.hpp>
17
+ #include <com/sun/star/frame/XDispatchProvider.hpp>
18
+ #include <com/sun/star/frame/XDispatchResultListener.hpp>
19
+ +#include <com/sun/star/sheet/XCalculatable.hpp>
20
+ #include <com/sun/star/frame/XSynchronousDispatch.hpp>
21
+ #include <com/sun/star/frame/XStorable.hpp>
22
+ #include <com/sun/star/lang/Locale.hpp>
23
+ @@ -1216,6 +1217,7 @@
24
+ int nX,
25
+ int nY);
26
+ static void doc_resetSelection (LibreOfficeKitDocument* pThis);
27
+ +static int doc_calculateAll(LibreOfficeKitDocument* pThis);
28
+ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand);
29
+ static void doc_setClientZoom(LibreOfficeKitDocument* pThis,
30
+ int nTilePixelWidth,
31
+ @@ -1536,6 +1538,7 @@
32
+ m_pDocumentClass->renderNextSlideLayer = doc_renderNextSlideLayer;
33
+ m_pDocumentClass->setViewOption = doc_setViewOption;
34
+ m_pDocumentClass->setColorPreviewState = doc_setColorPreviewState;
35
+ + m_pDocumentClass->calculateAll = doc_calculateAll;
36
+
37
+ gDocumentClass = m_pDocumentClass;
38
+ }
39
+ @@ -5290,6 +5293,25 @@
40
+ return std::find(std::begin(denyList), std::end(denyList), command) == std::end(denyList);
41
+ }
42
+
43
+ +// Calculation through the model does not require an interactive dispatcher or event loop.
44
+ +static int doc_calculateAll(LibreOfficeKitDocument* pThis)
45
+ +{
46
+ + SolarMutexGuard aGuard;
47
+ + SetLastExceptionMsg();
48
+ + try
49
+ + {
50
+ + auto* pDocument = static_cast<LibLODocument_Impl*>(pThis);
51
+ + uno::Reference<sheet::XCalculatable> xCalculatable(pDocument->mxComponent, uno::UNO_QUERY_THROW);
52
+ + xCalculatable->calculateAll();
53
+ + return 1;
54
+ + }
55
+ + catch (const uno::Exception& exception)
56
+ + {
57
+ + SetLastExceptionMsg("exception: " + exception.Message);
58
+ + }
59
+ + return 0;
60
+ +}
61
+ +
62
+ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pCommand, const char* pArguments, bool bNotifyWhenFinished)
63
+ {
64
+ comphelper::ProfileZone aZone("doc_postUnoCommand");
@@ -0,0 +1,21 @@
1
+ diff --git a/oox/source/drawingml/misccontexts.cxx b/oox/source/drawingml/misccontexts.cxx
2
+ --- a/oox/source/drawingml/misccontexts.cxx
3
+ +++ b/oox/source/drawingml/misccontexts.cxx
4
+ @@ -18,6 +18,7 @@
5
+ */
6
+
7
+ #include <drawingml/misccontexts.hxx>
8
+ +#include <comphelper/lok.hxx>
9
+ #include <oox/helper/attributelist.hxx>
10
+ #include <oox/helper/graphichelper.hxx>
11
+ #include <oox/core/xmlfilterbase.hxx>
12
+ @@ -313,6 +314,9 @@
13
+ }
14
+ else if( rAttribs.hasAttribute( R_TOKEN( link ) ) )
15
+ {
16
+ + // Kit imports use cached embedded graphics and never load external picture data.
17
+ + if (comphelper::LibreOfficeKit::isActive())
18
+ + return;
19
+ // external URL
20
+
21
+ // we will embed this link, this is better than just doing nothing...
@@ -0,0 +1,117 @@
1
+ --- a/svl/Library_svl.mk
2
+ +++ b/svl/Library_svl.mk
3
+ @@ -29,7 +29,7 @@
4
+ icuuc \
5
+ mdds_headers \
6
+ libxml2 \
7
+ - zxcvbn-c \
8
+ + $(if $(DISABLE_DYNLOADING),,zxcvbn-c) \
9
+ ))
10
+
11
+ $(eval $(call gb_Library_set_componentfile,svl,svl/util/svl,services))
12
+ --- a/svl/source/misc/PasswordHelper.cxx
13
+ +++ b/svl/source/misc/PasswordHelper.cxx
14
+ @@ -25,7 +25,9 @@
15
+ #include <unicode/regex.h>
16
+ #include <unicode/unistr.h>
17
+ #include <unicode/errorcode.h>
18
+ +#if !defined(DISABLE_DYNLOADING)
19
+ #include <zxcvbn.h>
20
+ +#endif
21
+ #include <sal/log.hxx>
22
+
23
+ #include <com/sun/star/uno/Sequence.hxx>
24
+ @@ -136,6 +138,7 @@
25
+ return bResult;
26
+ }
27
+
28
+ +#if !defined(DISABLE_DYNLOADING)
29
+ double SvPasswordHelper::GetPasswordStrengthPercentage(const char* pPassword)
30
+ {
31
+ // Entropy bits ≥ 112 are mapped to 100% password strength.
32
+ @@ -152,6 +155,8 @@
33
+ OString aPasswordUtf8 = aPassword.toUtf8();
34
+ return GetPasswordStrengthPercentage(aPasswordUtf8.getStr());
35
+ }
36
+ +
37
+ +#endif
38
+
39
+ bool SvPasswordHelper::PasswordMeetsPolicy(const char* pPassword,
40
+ const std::optional<OUString>& oPasswordPolicy)
41
+ --- a/sfx2/source/dialog/passwd.cxx
42
+ +++ b/sfx2/source/dialog/passwd.cxx
43
+ @@ -47,8 +47,12 @@
44
+ // if there's a confirm entry, the dialog is being used for setting a password
45
+ if (m_xConfirm1ED->get_visible())
46
+ {
47
+ +#if defined(DISABLE_DYNLOADING)
48
+ + m_xPassword1StrengthBar->set_visible(false);
49
+ +#else
50
+ m_xPassword1StrengthBar->set_percentage(
51
+ SvPasswordHelper::GetPasswordStrengthPercentage(aPassword1Text));
52
+ +#endif
53
+ bool bPasswordMeetsPolicy = SvPasswordHelper::PasswordMeetsPolicy(
54
+ aPassword1Text, moPasswordPolicy);
55
+ m_xPassword1ED->set_message_type(bPasswordMeetsPolicy ? weld::EntryMessageType::Normal
56
+ @@ -61,8 +65,12 @@
57
+ {
58
+ OUString aPassword2Text = m_xPassword2ED->get_text();
59
+
60
+ +#if defined(DISABLE_DYNLOADING)
61
+ + m_xPassword2StrengthBar->set_visible(false);
62
+ +#else
63
+ m_xPassword2StrengthBar->set_percentage(
64
+ SvPasswordHelper::GetPasswordStrengthPercentage(m_xPassword2ED->get_text()));
65
+ +#endif
66
+
67
+ // second password is optional, ignore policy if it is empty
68
+ bool bPasswordMeetsPolicy
69
+ --- a/cui/source/dialogs/passwdomdlg.cxx
70
+ +++ b/cui/source/dialogs/passwdomdlg.cxx
71
+ @@ -131,10 +131,15 @@
72
+ }
73
+
74
+ // if password doesn't meet policy cap the percentage at 70%
75
+ +#if defined(DISABLE_DYNLOADING)
76
+ + if (pLevelBar)
77
+ + pLevelBar->set_visible(false);
78
+ +#else
79
+ if (pLevelBar)
80
+ pLevelBar->set_percentage(
81
+ std::min(SvPasswordHelper::GetPasswordStrengthPercentage(aPasswordText),
82
+ bPasswordMeetsPolicy ? std::numeric_limits<double>::max() : 70.0));
83
+ +#endif
84
+
85
+ if (m_nMaxPasswdLen)
86
+ {
87
+ --- a/uui/source/masterpasscrtdlg.cxx
88
+ +++ b/uui/source/masterpasscrtdlg.cxx
89
+ @@ -35,8 +35,12 @@
90
+ {
91
+ OUString aPasswordText = m_xEDMasterPasswordCrt->get_text();
92
+ m_xOKBtn->set_sensitive(aPasswordText.getLength() >= 1);
93
+ +#if defined(DISABLE_DYNLOADING)
94
+ + m_xPasswdStrengthBar->set_visible(false);
95
+ +#else
96
+ m_xPasswdStrengthBar->set_percentage(
97
+ SvPasswordHelper::GetPasswordStrengthPercentage(aPasswordText));
98
+ +#endif
99
+
100
+ if(m_oPasswordPolicy)
101
+ {
102
+ --- a/sc/source/ui/miscdlgs/protectiondlg.cxx
103
+ +++ b/sc/source/ui/miscdlgs/protectiondlg.cxx
104
+ @@ -162,8 +162,12 @@
105
+ OUString aPass1 = m_xPassword1Edit->get_text();
106
+ if (&rEntry == m_xPassword1Edit.get())
107
+ {
108
+ - m_xPasswordStrengthBar->set_percentage(
109
+ +#if defined(DISABLE_DYNLOADING)
110
+ + m_xPasswordStrengthBar->set_visible(false);
111
+ +#else
112
+ + m_xPasswordStrengthBar->set_percentage(
113
+ SvPasswordHelper::GetPasswordStrengthPercentage(aPass1));
114
+ +#endif
115
+ }
116
+ OUString aPass2 = m_xPassword2Edit->get_text();
117
+ m_xBtnOk->set_sensitive(aPass1 == aPass2);
@@ -0,0 +1,26 @@
1
+ --- a/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk
2
+ +++ b/solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk
3
+ @@ -70,7 +70,7 @@
4
+ endif
5
+
6
+ # Linker and compiler optimize + debug flags are handled in LinkTarget.mk
7
+ -gb_LINKEROPTFLAGS :=
8
+ +gb_LINKEROPTFLAGS := -Oz
9
+ gb_LINKERSTRIPDEBUGFLAGS :=
10
+ # This maps to g3, no source maps, but DWARF with current emscripten!
11
+ # https://developer.chrome.com/blog/wasm-debugging-2020/
12
+ @@ -80,7 +80,13 @@
13
+ gb_DEBUGINFO_FLAGS += -gseparate-dwarf -gsplit-dwarf -gpubnames
14
+ endif
15
+
16
+ -gb_COMPILEROPTFLAGS := -O3
17
+ +gb_COMPILEROPTFLAGS := -Oz
18
+ +
19
+ +ifeq ($(ENABLE_LTO),TRUE)
20
+ +# Emscripten's LLVM tools consume bitcode directly, without a native gold plugin.
21
+ +gb_LTOFLAGS := -flto
22
+ +gb_LTOPLUGINFLAGS :=
23
+ +endif
24
+
25
+ # We need at least code elimination, otherwise linking OOMs even with 64GB.
26
+ # So we "fake" -Og support to mean -O1 for Emscripten and always enable it for debug in configure.
@@ -0,0 +1,59 @@
1
+ diff --git a/canvas/source/vcl/spritecanvas.cxx b/canvas/source/vcl/spritecanvas.cxx
2
+ index bbef9a909b6ad986618aeb363a6334cade325066..050d721541743e5cb3e9ee032c13af60b6effed0 100644
3
+ --- a/canvas/source/vcl/spritecanvas.cxx
4
+ +++ b/canvas/source/vcl/spritecanvas.cxx
5
+ @@ -58,7 +58,16 @@ namespace vclcanvas
6
+ [this](css::uno::Any const& aAny) mutable { this->maCanvasHelper.enableUnsafeScrolling(aAny); } )
7
+ ("SpriteBounds",
8
+ [this]() { return this->maCanvasHelper.isSpriteBounds(); },
9
+ - [this](css::uno::Any const& aAny) mutable { this->maCanvasHelper.enableSpriteBounds(aAny); } ));
10
+ + [this](css::uno::Any const& aAny) mutable { this->maCanvasHelper.enableSpriteBounds(aAny); } )
11
+ + ("LOKDeferredUpdate",
12
+ + [this]() { return uno::Any(mbLOKDeferredUpdate); },
13
+ + [this](const uno::Any& value) {
14
+ + ENSURE_ARG_OR_THROW(value >>= mbLOKDeferredUpdate,
15
+ + "LOKDeferredUpdate requires a boolean");
16
+ + })
17
+ + ("LOKUpdatePending",
18
+ + [this]() { return uno::Any(mbLOKUpdatePending); },
19
+ + {}));
20
+
21
+ SAL_INFO("canvas.vcl", "VCLSpriteCanvas::initialize called" );
22
+
23
+ @@ -140,11 +149,20 @@ namespace vclcanvas
24
+ {
25
+ SolarMutexGuard aGuard;
26
+
27
+ + if (mbLOKDeferredUpdate)
28
+ + {
29
+ + mbLOKUpdatePending = true;
30
+ + return true;
31
+ + }
32
+ +
33
+ // avoid repaints on hidden window (hidden: not mapped to
34
+ // screen). Return failure, since the screen really has _not_
35
+ // been updated (caller should try again later)
36
+ - return mbIsVisible && maCanvasHelper.updateScreen(bUpdateAll,
37
+ - mbSurfaceDirty);
38
+ + const bool updated = mbIsVisible && maCanvasHelper.updateScreen(bUpdateAll,
39
+ + mbSurfaceDirty);
40
+ + if (updated)
41
+ + mbLOKUpdatePending = false;
42
+ + return updated;
43
+ }
44
+
45
+ OUString SAL_CALL SpriteCanvas::getServiceName( )
46
+ diff --git a/canvas/source/vcl/spritecanvas.hxx b/canvas/source/vcl/spritecanvas.hxx
47
+ index a5942c569a9d84ef524273fb29ede49b407581bc..5685b6d4b7164304d61bcdfe1e5509b27b5bf919 100644
48
+ --- a/canvas/source/vcl/spritecanvas.hxx
49
+ +++ b/canvas/source/vcl/spritecanvas.hxx
50
+ @@ -153,6 +153,9 @@ namespace vclcanvas
51
+
52
+ private:
53
+ css::uno::Sequence< css::uno::Any > maArguments;
54
+ + // Offscreen owners defer output until a shared target is available.
55
+ + bool mbLOKDeferredUpdate = false;
56
+ + bool mbLOKUpdatePending = false;
57
+ };
58
+
59
+ typedef ::rtl::Reference< SpriteCanvas > SpriteCanvasRef;
@@ -0,0 +1,74 @@
1
+ /** Deterministic removal of desktop resources from the Node WASM filesystem image. */
2
+
3
+ import { assertRequiredUiResources } from '../ui-resource-policy.mjs';
4
+
5
+ const ui = '/instdir/share/config/soffice.cfg/';
6
+ // These dialogs belong to the desktop shell, not the embedded document editor.
7
+ const desktopLayouts = new Set([
8
+ 'sfx/ui/startcenter.ui', 'sfx/ui/safemodequerydialog.ui',
9
+ 'cui/ui/aboutdialog.ui', 'cui/ui/tipofthedaydialog.ui',
10
+ ]);
11
+
12
+ function desktopResource(filename) {
13
+ if (filename.startsWith(ui)) {
14
+ const relative = filename.slice(ui.length);
15
+ // The shared WASM engine runs persistent editors: VCL idle work and editing
16
+ // commands instantiate layouts beyond the native conversion allowlist.
17
+ return desktopLayouts.has(relative) || relative.split('/').at(-1).startsWith('notebookbar') || /(?:^|\/)(?:toolbar|menubar)\//.test(relative);
18
+ }
19
+ return /^\/instdir\/share\/(?:autocorr|autotext|wordbook|gallery|template|wizards|tipoftheday|shell)\//.test(filename)
20
+ || filename === '/instdir/share/palette/standard.sob'
21
+ || /^\/instdir\/share\/config\/images(?:_[a-z0-9_]+)?\.zip$/.test(filename)
22
+ || /^\/(?:core\/)?android\/default-document\//.test(filename)
23
+ || /^\/instdir\/program\/intro(?:-highres)?\.png$/.test(filename)
24
+ || filename.startsWith('/instdir/program/shell/');
25
+ }
26
+
27
+ /**
28
+ * Repack a complete Emscripten filesystem image without changing retained bytes.
29
+ * Reject malformed inventories before returning any output. The loader reads its
30
+ * preload size from the returned metadata's remote_package_size field.
31
+ * @param data - Original filesystem image bytes.
32
+ * @param metadata - Parsed Emscripten filesystem inventory.
33
+ * @returns Repacked bytes, contiguous inventory, and removed resource sizes.
34
+ */
35
+ export function slimWasmData(data, metadata) {
36
+ if (!Buffer.isBuffer(data) || !metadata || !Array.isArray(metadata.files)
37
+ || metadata.remote_package_size !== data.length) throw new Error('WASM data size differs from its metadata');
38
+ const names = new Set();
39
+ let cursor = 0;
40
+ for (const file of metadata.files) {
41
+ if (!file || typeof file.filename !== 'string' || !file.filename.startsWith('/')
42
+ || file.filename.slice(1).split('/').some(part => !part || part === '.' || part === '..' || /[\\\0]/.test(part))
43
+ || names.has(file.filename)) throw new Error('Invalid or duplicate WASM resource path');
44
+ names.add(file.filename);
45
+ if (!Number.isSafeInteger(file.start) || !Number.isSafeInteger(file.end)
46
+ || file.start !== cursor || file.end < file.start || file.end > data.length) {
47
+ throw new Error(`WASM resource ranges do not continuously cover the data: ${file.filename}`);
48
+ }
49
+ cursor = file.end;
50
+ }
51
+ if (cursor !== data.length) throw new Error('WASM resource inventory does not cover the complete data');
52
+ assertRequiredUiResources([...names].filter(name => name.startsWith(ui)).map(name => name.slice(ui.length)));
53
+ const chunks = [];
54
+ const files = [];
55
+ const removed = [];
56
+ let offset = 0;
57
+ for (const file of metadata.files) {
58
+ const bytes = file.end - file.start;
59
+ if (desktopResource(file.filename)) {
60
+ removed.push({ filename: file.filename, bytes });
61
+ } else {
62
+ chunks.push(data.subarray(file.start, file.end));
63
+ files.push({ ...file, start: offset, end: offset + bytes });
64
+ offset += bytes;
65
+ }
66
+ }
67
+ if (offset === 0) throw new Error('WASM slimming would remove the complete filesystem image');
68
+ return {
69
+ data: Buffer.concat(chunks, offset),
70
+ metadata: { ...metadata, files, remote_package_size: offset },
71
+ removed,
72
+ removedBytes: data.length - offset,
73
+ };
74
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "libreoffice": {
4
+ "tag": "libreoffice-26.8.0.3",
5
+ "version": "26.8.0.3",
6
+ "sourceArchive": "https://download.documentfoundation.org/libreoffice/src/26.8.0/libreoffice-26.8.0.3.tar.xz"
7
+ },
8
+ "emsdk": {
9
+ "repository": "https://github.com/emscripten-core/emsdk.git",
10
+ "commit": "5eb0bde7585670252e8ba05e9d361627bffd08b5",
11
+ "version": "4.0.10",
12
+ "releaseCommit": "8103ffedfb0c42d231c6af6859a5a1a832260b43"
13
+ },
14
+ "patches": "patches",
15
+ "shim": "lok.cxx"
16
+ }
@@ -0,0 +1,12 @@
1
+ /** Resolve Core from the submodule while keeping the WASM toolchain recipe separate. */
2
+ import { readFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { readCoreSource } from '../core-source.mjs';
6
+
7
+ const root = fileURLToPath(new URL('../../', import.meta.url));
8
+ export function readWasmSource(repo = root) {
9
+ const recipe = JSON.parse(readFileSync(join(repo, 'engine/wasm-source/source.json'), 'utf8'));
10
+ const { repository, revision } = readCoreSource(repo);
11
+ return { ...recipe, libreoffice: { ...recipe.libreoffice, repository, commit: revision } };
12
+ }
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+ /** Stage only a receipted Node WASM build, including its corresponding source and notices. */
3
+ import { spawnSync } from 'node:child_process';
4
+ import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
5
+ import { dirname, join, resolve } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { parseArgs } from 'node:util';
8
+ import { sha256, verifyEnginePackage } from '../../scripts/verify-artifacts.mjs';
9
+ import { publicBuildValue } from '../build-identity.mjs';
10
+ import { readCoreSource } from '../core-source.mjs';
11
+ import { readWasmSource } from './source.mjs';
12
+
13
+ const owner = dirname(fileURLToPath(import.meta.url));
14
+ const root = resolve(owner, '../..');
15
+ const { values } = parseArgs({ options: {
16
+ source: { type: 'string' }, emsdk: { type: 'string' }, build: { type: 'string' }, bundle: { type: 'string' },
17
+ } });
18
+ for (const name of ['source', 'emsdk', 'build', 'bundle']) {
19
+ if (!values[name]) throw new Error(`Missing --${name} directory.`);
20
+ }
21
+ const environment = Object.fromEntries(Object.entries(process.env).filter(([key]) => !/KEY|SECRET|TOKEN|PASSWORD/i.test(key)));
22
+ const run = (command, args, options = {}) => {
23
+ const result = spawnSync(command, args, { cwd: root, env: environment, stdio: 'inherit', ...options });
24
+ if (result.error) throw result.error;
25
+ if (result.status !== 0) throw new Error(`${command} exited with ${result.signal ?? result.status}.`);
26
+ return result.stdout;
27
+ };
28
+ const paths = Object.fromEntries(Object.entries(values).map(([name, value]) => [name, resolve(value)]));
29
+ const autogen = readFileSync(join(paths.build, 'autogen.input'), 'utf8');
30
+ const tarballs = autogen.match(/^--with-external-tar=(.+)$/m)?.[1];
31
+ if (!tarballs) throw new Error('The WASM build configuration does not record its external tarball directory.');
32
+ run(process.execPath, [join(owner, 'build.mjs'), '--stage', 'package', '--source', paths.source,
33
+ '--emsdk', paths.emsdk, '--build', paths.build, '--tarballs', tarballs, '--output', paths.bundle]);
34
+ const published = join(root, 'packages/wasm');
35
+ const destination = mkdtempSync(join(dirname(published), '.wasm-stage-'));
36
+ try {
37
+ for (const file of readdirSync(published, { withFileTypes: true })) {
38
+ if (file.isFile() && file.name !== 'prebuilds.json') copyFileSync(join(published, file.name), join(destination, file.name));
39
+ }
40
+ for (const name of ['assets', 'sources', 'licenses']) mkdirSync(join(destination, name), { recursive: true });
41
+ for (const name of readdirSync(paths.bundle)) copyFileSync(join(paths.bundle, name), join(destination, 'assets', name));
42
+ for (const name of ['LICENSE', 'NOTICE']) copyFileSync(join(paths.build, 'instdir', name), join(destination, 'licenses', name));
43
+ copyFileSync(join(root, 'NOTICE'), join(destination, 'licenses/Rabi-Harness-MIT.txt'));
44
+ // Preserve repository-relative imports in the corresponding-source recipe.
45
+ const sourceFiles = ['engine/document-operations.hxx', 'engine/build-identity.mjs', 'engine/ui-resource-policy.mjs', 'scripts/minimize-ui-resources.py', 'docs/ui-resources.md', 'engine/core-source.mjs',
46
+ ...['source.json', 'source.mjs', 'autogen.input', 'lok.cxx', 'build.mjs', 'stage.mjs', 'slim.mjs',
47
+ ...readdirSync(join(owner, 'patches')).map(name => `patches/${name}`)].map(name => `engine/wasm-source/${name}`),
48
+ 'scripts/checkout-wasm.mjs', 'scripts/core-checkout.mjs', 'scripts/pack-utils.mjs', 'scripts/platform-matrix.mjs', 'scripts/verify-artifacts.mjs'];
49
+ for (const file of sourceFiles) {
50
+ const target = join(destination, 'sources', file);
51
+ mkdirSync(dirname(target), { recursive: true });
52
+ copyFileSync(join(root, file), target);
53
+ }
54
+ writeFileSync(join(destination, 'sources/core-source.json'), `${JSON.stringify(readCoreSource(), null, 2)}\n`);
55
+ const diff = run('git', ['diff', '--binary', 'HEAD', '--'], { cwd: paths.source, stdio: ['ignore', 'pipe', 'pipe'] });
56
+ writeFileSync(join(destination, 'sources/source-changes.patch'), diff);
57
+ writeFileSync(join(destination, 'sources/build-autogen.input'), publicBuildValue(autogen, { workspace: root, ...paths, tarballs }));
58
+ const files = {};
59
+ const visit = prefix => {
60
+ for (const entry of readdirSync(join(destination, prefix), { withFileTypes: true })) {
61
+ const name = `${prefix}/${entry.name}`;
62
+ if (entry.isDirectory()) visit(name);
63
+ else if (entry.isFile()) files[name] = sha256(join(destination, name));
64
+ else throw new Error(`Unexpected package file: ${name}`);
65
+ }
66
+ };
67
+ for (const name of ['assets', 'sources', 'licenses']) visit(name);
68
+ const pinned = readWasmSource().libreoffice;
69
+ const prior = JSON.parse(readFileSync(join(published, 'prebuilds.json'), 'utf8'));
70
+ const manifest = { ...prior, status: 'built', files,
71
+ source: { repository: pinned.repository, revision: pinned.commit, version: pinned.version,
72
+ files: Object.keys(files).filter(name => name.startsWith('sources/')) },
73
+ licenses: [
74
+ { component: 'LibreOffice', spdx: 'MPL-2.0', path: 'licenses/LICENSE' },
75
+ { component: 'Rabi Harness portions', spdx: 'MIT', path: 'licenses/Rabi-Harness-MIT.txt' },
76
+ { component: 'LibreOffice third-party notices', spdx: 'LicenseRef-LibreOffice-Notices', path: 'licenses/NOTICE' },
77
+ ],
78
+ };
79
+ writeFileSync(join(destination, 'prebuilds.json'), `${JSON.stringify(manifest, null, 2)}\n`);
80
+ verifyEnginePackage(destination);
81
+ const backup = `${destination}-previous`;
82
+ renameSync(published, backup);
83
+ try { renameSync(destination, published); }
84
+ catch (error) {
85
+ try { renameSync(backup, published); }
86
+ catch (restoreError) { throw new AggregateError([error, restoreError], `Restore the previous package from ${backup}.`); }
87
+ throw error;
88
+ }
89
+ rmSync(backup, { recursive: true });
90
+ console.log(`Verified Node WASM package: ${published}`);
91
+ } finally { rmSync(destination, { recursive: true, force: true }); }
@@ -0,0 +1,24 @@
1
+ /** Fetch the pinned Core/emsdk sources and install the recorded WASM toolchain. */
2
+ import { existsSync, mkdirSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { root } from './platform-matrix.mjs';
5
+ import { run } from './pack-utils.mjs';
6
+ import { checkoutCore } from './core-checkout.mjs';
7
+ import { readWasmSource } from '../engine/wasm-source/source.mjs';
8
+
9
+ const pinned = readWasmSource();
10
+ checkoutCore(join(root, '.build/wasm/core'));
11
+ for (const [name, spec] of [['emsdk', pinned.emsdk]]) {
12
+ const directory = join(root, '.build/wasm', name);
13
+ if (!existsSync(join(directory, '.git'))) {
14
+ mkdirSync(directory, { recursive: true });
15
+ run('git', ['init'], { cwd: directory });
16
+ run('git', ['remote', 'add', 'origin', spec.repository], { cwd: directory });
17
+ run('git', ['fetch', '--depth=1', 'origin', spec.commit], { cwd: directory, timeout: 900_000 });
18
+ run('git', ['checkout', '--detach', 'FETCH_HEAD'], { cwd: directory });
19
+ }
20
+ if (run('git', ['rev-parse', 'HEAD'], { cwd: directory }).trim() !== spec.commit) throw new Error(`Existing ${name} checkout has a different revision`);
21
+ }
22
+ const sdk = join(root, '.build/wasm/emsdk');
23
+ run('python3', [join(sdk, 'emsdk.py'), 'install', pinned.emsdk.version], { cwd: sdk, timeout: 900_000 });
24
+ run('python3', [join(sdk, 'emsdk.py'), 'activate', pinned.emsdk.version], { cwd: sdk });
@@ -0,0 +1,39 @@
1
+ /** Keep patchable build trees separate from the pristine upstream submodule. */
2
+ import { existsSync, mkdirSync } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+ import { coreSubmodule, readCoreSource } from '../engine/core-source.mjs';
5
+ import { root } from './platform-matrix.mjs';
6
+ import { run } from './pack-utils.mjs';
7
+
8
+ export function checkoutCore(directory, repo = root) {
9
+ const source = readCoreSource(repo);
10
+ const verify = cwd => {
11
+ if (run('git', ['rev-parse', 'HEAD'], { cwd }).trim() !== source.revision)
12
+ throw new Error(`Existing Core checkout has a different revision: ${cwd}`);
13
+ };
14
+ if (existsSync(join(directory, '.git'))) {
15
+ verify(directory);
16
+ return;
17
+ }
18
+ mkdirSync(dirname(directory), { recursive: true });
19
+ if (existsSync(join(repo, '.git'))) {
20
+ const upstream = join(repo, coreSubmodule);
21
+ if (!existsSync(join(upstream, '.git')))
22
+ run('git', ['submodule', 'update', '--init', '--checkout', '--depth=1', '--', coreSubmodule], { cwd: repo, timeout: 900_000 });
23
+ verify(upstream);
24
+ if (run('git', ['status', '--porcelain', '--untracked-files=normal'], { cwd: upstream }).trim())
25
+ throw new Error('Core submodule must be clean; apply patches only in disposable build checkouts');
26
+ run('git', ['clone', '--no-checkout', '--', upstream, directory], { timeout: 900_000 });
27
+ run('git', ['remote', 'set-url', 'origin', source.repository], { cwd: directory });
28
+ } else {
29
+ // Corresponding-source receipts can also prepare a build without a superproject.
30
+ mkdirSync(directory, { recursive: true });
31
+ run('git', ['init'], { cwd: directory });
32
+ run('git', ['remote', 'add', 'origin', source.repository], { cwd: directory });
33
+ run('git', ['fetch', '--depth=1', 'origin', source.revision], { cwd: directory, timeout: 900_000 });
34
+ }
35
+ run('git', ['config', 'core.autocrlf', 'false'], { cwd: directory });
36
+ run('git', ['config', 'core.eol', 'lf'], { cwd: directory });
37
+ run('git', ['checkout', '--detach', source.revision], { cwd: directory });
38
+ verify(directory);
39
+ }