Commit Graph
26 Commits
Author SHA1 Message Date
Stephan Bergmann da49e5edb2 Add Embind'ing of UNO Any getter for interfaces
Change-Id: Ia56439e0e99c193c7cc56676677df2c671278e24
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164554
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-03-07 23:13:31 +01:00
Stephan Bergmann 2364e6d62d Add $equals to Embind'ing of UNO interfaces
...so one can write foo.$equals(bar.$query) to check for UNO object equality

Change-Id: I727386e833507c86573cf033a1364ff145ed31ee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164544
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-03-07 21:21:24 +01:00
Stephan Bergmann 567a10caef Add Embind'ing of UNO Any getter for exceptions
Change-Id: Ief3cdebc1ee7c7b9f012741c9db8637dba9bbd07
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164433
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-03-06 00:02:36 +01:00
Stephan Bergmann 893af92ae9 Add Embind'ing of UNO Any getter for sequences
Change-Id: I5b81ad3d5f1351062aef43105ea7ec4678045a90
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164360
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-03-04 21:43:18 +01:00
Stephan Bergmann 0bab5cda21 Add Embing'ing of UNO Any getter for enums
...which taps into the internals of emscripten::val, which is based on
std::type_info identifiers, so we need an additional statically-built mapping
between UNO (enum, for now) types and std::type_info

Change-Id: I9fc1ff33fe31a1e1052504905de446ed2193e014
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164359
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-03-04 21:43:09 +01:00
Stephan Bergmann 6064939d40 Embind support for constant groups
The constants are only reflected directly as JS values in the generated *.js
file.  Reflecting them via emscripten::constant in the generated *.cxx did not
work well:  Most importantly, emscripten::constant (and its underlying
_embind_register_constant) coerce all values to double, so UNO (unsigned) hyper
would not survive as JS BigInt, which would then cause e.g.

>     console.assert(test.isHyper(uno.org.libreoffice.embindtest.Constants.Hyper));

passing such a (JS number, not BigInt) value into the
org.libreoffice.embindtest.XTest::isHyper method (which expects a UNO hyper) to
fail.  (Also, constants of UNO boolean type would be represented as numbers 0/1
rather than as false/true.)

Change-Id: I056db0ccce0bf40eb53728fd439cc74964eb6951
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164097
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-02-29 07:53:54 +01:00
Stephan Bergmann 621322b6ac Generate slightly more flexible JS init_unoembind_* functions
...that return the "hierarchical object", rather than setting it as a member of
the passed-in instance

Change-Id: I17ad7dd426114c7979f1ba6edaebe83b43eedfed
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164064
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-02-28 07:53:41 +01:00
Stephan Bergmann c7664f12a9 Init Embind-ings manually, once UNO is set up
Upcoming code that changes the Embind'ing of UNO sequences will require
availability of the UNO type manager during that Embind init code, so only call
that after UNO has been bootstrapped (rather than as part of the initialization
of global static data, which is what EMSCRIPTEN_BINDINGS does).

Change-Id: Iba19851ffb82c055dcab10a28a8c1fafa9d2a414
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164065
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-02-28 07:53:21 +01:00
Stephan Bergmann 578d9be504 Embind: Map UNO structs to emscripten::value_object
...so that it has a nicer integration into JS, at the expense of copying data
between C++ and JS

Change-Id: I19af55e8db0c374dd7b0f58f74d1af19214175b4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163098
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-02-08 08:36:06 +01:00
Stephan Bergmann 8869994d5e embindmaker: Add support for sequence types
Ideally, JS code would have a way to create instances of arbitrary UNO sequence
types (to e.g. put them into Anys), but that goes against the static nature of
Embind.  So at least register JS support for all those UNO sequence types that
are actually used in the UNO API.  (This would cause duplicate failures, though,
if we generated multiple separate .cxx files from embindmaker invocations, with
registration code for the same UNO sequence types.)

(Even more ideally, UNO sequence types could map to JS arrays, and/oror be
garbage-collected on the JS side rather than needing explicit delete().  The
resize/size/get/set interface in unoembindhelpers::registerSequence is modelled
after Embind's emscripten::register_vector.)

Change-Id: Icd38b2e03db442dd613b9222b9bd092f947f7bec
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162849
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-02-01 08:46:47 +01:00
Stephan Bergmann efaf6218a2 embindmaker: Consistently spell out "::com::sun::star::"
Change-Id: I253236c908b1827479c1824cf01c707e48ef58c9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162832
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-31 21:52:48 +01:00
Stephan Bergmann 5a521daa68 embindmaker: Handle (plain) structs
Change-Id: I16ac3a6a2f42cf3054104a5ba90f4b75238e2ec4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162843
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-31 20:46:48 +01:00
Stephan Bergmann 702f420ab3 embindmaker: Handle enums
Change-Id: I07e068e52df2a838e76f32e691d23a47d7fcfdda
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162809
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-31 15:56:39 +01:00
Stephan Bergmann 7938c1e88d embindmaker: Handle new-style singletons
Change-Id: Icb3b179c95e1af8b12772401f58d4f4cf181e585
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162795
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-31 12:20:45 +01:00
Stephan Bergmann e4cf6c324c Embind in-out/out params of primitive type apparently need a wrapper
> let translit = css.i18n.Transliteration.create(Module.getUnoComponentContext());
> let match1;
> let match2;
> let eq = translit.equals(new Module.OUString("test1"), 0, 5, match1, new Module.OUString("test2"), 0, 5, match2);
> console.log('match ' + eq + ', ' + match1 + ', ' + match2);

caused an uncaught UnboundTypeError with message "Cannot call
uno_Type_com$sun$star$i18n$XTransliteration.equals due to unbound types: Pl", so
use

> let translit = css.i18n.Transliteration.create(Module.getUnoComponentContext());
> let match1 = new Module.UnoInOutParamLong;
> let match2 = new Module.UnoInOutParamLong;
> let eq = translit.equals(new Module.OUString("test1"), 0, 5, match1, new Module.OUString("test2"), 0, 5, match2);
> console.log('match ' + eq + ', ' + match1.val + ', ' + match2.val);
> delete match1;
> delete match2;

instead

Change-Id: Ic5a0a9e37e884817158069702510eab0d29adefa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162784
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-31 09:33:11 +01:00
Stephan Bergmann 9c416f6704 Embind clean up, only pass in-out/out params by raw pointer
Change-Id: I141d3aace7b76182fe464626bbb8a336c8ec6a3d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162783
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-31 08:04:28 +01:00
Stephan Bergmann 9f236a078c Pass the_self by const ref in Embind wrapper functions
Change-Id: Ie8bfec2a9fdd5f126fd2879d2ba06f1fa5c1019e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162781
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-30 23:57:16 +01:00
Stephan Bergmann 1b371a4e1f embindmaker: Handle new-style services
Change-Id: I41309a20666c17f0c8c8d456943b3c78d0273905
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162772
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-30 22:38:14 +01:00
Stephan Bergmann 7e0a432214 embindmaker: Handle interface inheritance
Change-Id: I81e66666f8a60bd34a9a3807adfb15c341303b9a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162771
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-30 22:18:15 +01:00
Stephan Bergmann 27ceca1996 Rework the Embind mapping of UNO interfaces
...to make use of the automatic finalization clean-up of smart pointers
available with recent versions of Embind (so that explicitly calling delete() on
them should largely be optional now).  See the changes to static/README.wasm.md
for how code should look like now.  (The Module.uno_Reference.FromAny dummy
argument for the interface constructor converting from an Any is only necessary
to distinguish it from the other constructor, as otherwise Embind complains
because:  "Overload resolution is currently only performed using the parameter
count, not actual type info!")

Change-Id: Ia8a8c12e38af1093948bf8a20ecd31aa6591e912
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162697
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-30 07:40:02 +01:00
Stephan Bergmann 2df1dcc324 Some renaming of generated identifiers
uno_Type_com$sun$star$... and uno_Reference_com$sun$star$...

Change-Id: Ibc19f423a60c521c376172807b4d5a34cf0179a5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162696
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-30 07:39:06 +01:00
Stephan Bergmann b476dccd11 Experimental support for latest Emscripten (and Qt6)
What I'm after in the context of our Embind-related code is the claim at
<https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#memory-management>:
"JavaScript only gained support for finalizers in ECMAScript 2021, or ECMA-262
Edition 12.  The new API is called FinalizationRegistry and it still does not
offer any guarantees that the provided finalization callback will be called.
Embind uses this for cleanup if available, but only for smart pointers, and only
as a last resort."  However, with the recommended emsdk 2.0.31 my tests did not
show any use of that finalization support.  So I wanted to try with the latest
emsdk 3.1.51 instead.  But then, linking vcldemo failed with

> wasm-ld: error: ~/allotropia-qt5/lib/libQt5Core.a(qlogging.o): undefined symbol: std::__2::__vector_base_common<true>::__throw_length_error() const

etc., so I gave it a try to rather build against latest Qt6.7, with

> --with-distro=LibreOfficeWASM32
> --disable-qt5
> --enable-qt6
> QT6DIR=...

TODO: The result is highly experimental, and it uses ENABLE_QT5 (i.e., the
recommended setup with emsdk 2.0.31 and the
<https://github.com/allotropia/qt5.git> v5.15.2+wasm branch) vs. ENABLE_QT6
(i.e., my experimental setup with emsdk 3.1.51 and the
<https://github.com/qt/qt5.git> 6.7 branch) not only to distinguish between Qt5-
vs. Qt6-specific behavior, but also to distinguish between old- vs.
new-Emscripten-specific behavior.  Of note:

* The startup code appears to have changed substantially (and required setting
  -s MODULARIZE=1 and -s EXPORT_NAME=soffice_entry now, and telling emcc to
  build just soffice.js and not the wrapper soffice.html.  TODO: This also
  required hacking into qt_soffice.html:  (1) The command-line arguments
  (--norestore, --nologo, --writer, and the exammple.odt; all of which we should
  eventually get rid of, anyway).  (2) Saving the generated instance as
  window.Module (and adapting the embindmaker-generated code, cf. the changes to
  static/README.wasm.md).

* There were some symbol clashes between external/argon2 and
  libQt6Core.a(qcryptographichash.cpp.o, so renamed the problematic symbols in
  external/argon2.

Change-Id: I5420ab566d560b11954ac6613249bfc53d8acb31
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162695
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-29 19:51:57 +01:00
Stephan Bergmann 8dc4a2e40b Hack to speed up compilation of generated UNO Embind source
...workdir/CustomTarget/static/unoembind/bindings_uno.cxx, reducing an otherwise
no-op build for me (against emcc 3.1.51) from multiple hours to "just" 3 min
wall-clock time.

Change-Id: Ic6477134b72f9d28cc3193fb514ceaa32b84209c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162666
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-28 21:30:21 +01:00
Andrea Gelmini 45763a761b Fix typo
Change-Id: Ic038388a812e510fdb963f8f271d6377a71759c1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162599
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Tested-by: Jenkins
2024-01-26 15:25:24 +01:00
Stephan Bergmann cbae6e581a Let embindmaker also generate a .js file with more natural names
(i.e., Module.unoembind_uno.com.sun.star... vs. Module.com$sun$star$..., and see
the updated examples in static/README.wasm.md for further shortening that to
just css...)

Change-Id: I6dc079caa8c93a4042a6a8aa2d8fcc8f76bf80f3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162580
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-25 18:31:42 +01:00
Stephan Bergmann b2ade3e63e Extract embindmaker from cppumaker into its own tool
...that directly generates one large .cxx

Change-Id: I046539b83f8fde5eda7168c93a8b819137399665
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162343
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
2024-01-21 15:51:39 +01:00