From c7664f12a99b6e08eb334d63646c3d2a6aa75e18 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 27 Feb 2024 16:30:24 +0100 Subject: [PATCH] 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 --- desktop/Library_sofficeapp.mk | 6 +++++ desktop/source/app/appinit.cxx | 7 ++++++ static/CustomTarget_unoembind.mk | 8 +++--- static/source/embindmaker/embindmaker.cxx | 30 +++++++++++++++++------ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk index 641efda7eda2..cc39ccd12f92 100644 --- a/desktop/Library_sofficeapp.mk +++ b/desktop/Library_sofficeapp.mk @@ -37,6 +37,12 @@ $(eval $(call gb_Library_use_custom_headers,sofficeapp,\ officecfg/registry \ )) +ifeq ($(OS),EMSCRIPTEN) +$(eval $(call gb_Library_use_custom_headers,sofficeapp, \ + static/unoembind \ +)) +endif + $(eval $(call gb_Library_use_api,sofficeapp,\ udkapi \ offapi \ diff --git a/desktop/source/app/appinit.cxx b/desktop/source/app/appinit.cxx index 51b466c6b980..1a0681f0d163 100644 --- a/desktop/source/app/appinit.cxx +++ b/desktop/source/app/appinit.cxx @@ -45,6 +45,10 @@ #include #include +#if defined EMSCRIPTEN +#include +#endif + using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::beans; @@ -83,6 +87,9 @@ void Desktop::InitApplicationServiceManager() UNO_QUERY_THROW); #endif comphelper::setProcessServiceFactory(sm); +#if defined EMSCRIPTEN + init_unoembind_uno(); +#endif } void Desktop::RegisterServices() diff --git a/static/CustomTarget_unoembind.mk b/static/CustomTarget_unoembind.mk index 045e0fea511c..d1bc294e0b9f 100644 --- a/static/CustomTarget_unoembind.mk +++ b/static/CustomTarget_unoembind.mk @@ -15,14 +15,14 @@ $(eval $(call gb_CustomTarget_register_targets,static/unoembind, \ )) $(call gb_CustomTarget_get_workdir,static/unoembind)/bindings_uno.cxx \ +$(call gb_CustomTarget_get_workdir,static/unoembind)/bindings_uno.hxx \ $(call gb_CustomTarget_get_workdir,static/unoembind)/bindings_uno.js: \ $(call gb_Executable_get_target_for_build,embindmaker) $(call gb_UnoApi_get_target,udkapi) \ - $(call gb_UnoApi_get_target,offapi) \ - $(if $(ENABLE_DBGUTIL),$(call gb_UnoApiTarget_get_target,embindtest)) + $(call gb_UnoApi_get_target,offapi) $(call gb_Executable_get_command,embindmaker) uno \ $(call gb_CustomTarget_get_workdir,static/unoembind)/bindings_uno.cxx \ + $(call gb_CustomTarget_get_workdir,static/unoembind)/bindings_uno.hxx \ $(call gb_CustomTarget_get_workdir,static/unoembind)/bindings_uno.js \ - +$(call gb_UnoApi_get_target,udkapi) +$(call gb_UnoApi_get_target,offapi) \ - +$(if $(ENABLE_DBGUTIL),$(call gb_UnoApiTarget_get_target,embindtest)) + +$(call gb_UnoApi_get_target,udkapi) +$(call gb_UnoApi_get_target,offapi) # vim: set noet sw=4 ts=4: diff --git a/static/source/embindmaker/embindmaker.cxx b/static/source/embindmaker/embindmaker.cxx index bff11e99b16d..335b7983503c 100644 --- a/static/source/embindmaker/embindmaker.cxx +++ b/static/source/embindmaker/embindmaker.cxx @@ -46,13 +46,13 @@ void badUsage() { std::cerr << "Usage:\n\n" - " embindmaker \n\n" + " embindmaker \n\n" "where each is '+' (primary) or ':' (secondary), followed by: either a\n" "new- or legacy-format .rdb file, a single .idl file, or a root directory of an\n" ".idl file tree. For all primary registries, Embind code is written to\n" - " and corresponding JavaScript scaffolding code is written to\n" - ". The is used as part of some of the identifiers in those\n" - "generated files.\n"; + "/ and corresponding JavaScript scaffolding code is\n" + "written to . The is used as part of some of the identifiers\n" + "in those generated files.\n"; std::exit(EXIT_FAILURE); } @@ -708,16 +708,17 @@ SAL_IMPLEMENT_MAIN() try { auto const args = rtl_getAppCommandArgCount(); - if (args < 3) + if (args < 4) { badUsage(); } OUString name; rtl_getAppCommandArg(0, &name.pData); auto const cppPathname = getPathnameArgument(1); - auto const jsPathname = getPathnameArgument(2); + auto const hppPathname = getPathnameArgument(2); + auto const jsPathname = getPathnameArgument(3); rtl::Reference mgr(new TypeManager); - for (sal_uInt32 i = 3; i != args; ++i) + for (sal_uInt32 i = 4; i != args; ++i) { auto const & [ uri, primary ] = parseRegistryArgument(i); try @@ -906,7 +907,7 @@ SAL_IMPLEMENT_MAIN() << "::get);\n"; dumpRegisterFunctionEpilog(cppOut, n); } - cppOut << "EMSCRIPTEN_BINDINGS(unoembind_" << name << ") {\n"; + cppOut << "void init_unoembind_" << name << "() {\n"; for (unsigned long long i = 0; i != n; ++i) { cppOut << " register" << i << "();\n"; @@ -933,6 +934,19 @@ SAL_IMPLEMENT_MAIN() std::cerr << "Failed to write \"" << cppPathname << "\"\n"; std::exit(EXIT_FAILURE); } + std::ofstream hppOut(hppPathname, std::ios_base::out | std::ios_base::trunc); + if (!hppOut) + { + std::cerr << "Cannot open \"" << hppPathname << "\" for writing\n"; + std::exit(EXIT_FAILURE); + } + hppOut << "void init_unoembind_" << name << "();\n"; + hppOut.close(); + if (!hppOut) + { + std::cerr << "Failed to write \"" << hppPathname << "\"\n"; + std::exit(EXIT_FAILURE); + } std::ofstream jsOut(jsPathname, std::ios_base::out | std::ios_base::trunc); if (!jsOut) {