.NET Bindings: Add DotnetLibrary class to gbuild

This commit adds the DotnetLibrary gbuild class to build a .NET assembly
using the .NET SDK.

Also adds an option to enable or disable building .NET components with
--enable-dotnet (default) and --disable-dotnet to the autogen script.

Also adds a net_ure/ directory for the updated .NET bindings, currently
consisting of the net_basetypes library.

Change-Id: I9256387a2463ff8476deee85d886c6b3dce8257b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166380
Tested-by: Jenkins
Reviewed-by: Hossein <hossein@libreoffice.org>
This commit is contained in:
RMZeroFour
2024-05-30 14:28:57 +05:30
committed by Hossein
parent 5ad1104993
commit 6538b3b09c
19 changed files with 426 additions and 1 deletions

View File

@ -137,6 +137,7 @@ gbuild_TARGETS := AllLangHelp \
CppunitTest \
CustomTarget \
Dictionary \
DotnetLibrary \
Executable \
Extension \
ExtensionPackage \

View File

@ -30,6 +30,7 @@ $(eval $(call gb_Module_add_moduledirs,cross_toolset,\
jvmaccess \
jvmfwk \
l10ntools \
net_ure \
o3tl \
offapi \
officecfg \

View File

@ -107,6 +107,7 @@ $(eval $(call gb_Module_add_moduledirs,libreoffice,\
linguistic \
lotuswordpro \
$(call gb_Helper_optional,DESKTOP,l10ntools) \
net_ure \
$(call gb_Helper_optional,NLPSOLVER,nlpsolver) \
o3tl \
$(call gb_Helper_optional,ODK,odk) \

View File

@ -165,6 +165,7 @@ export ENABLE_DBGUTIL=@ENABLE_DBGUTIL@
export ENABLE_DBUS=@ENABLE_DBUS@
export ENABLE_DCONF=@ENABLE_DCONF@
export ENABLE_DEBUG=@ENABLE_DEBUG@
export ENABLE_DOTNET=@ENABLE_DOTNET@
SYSTEM_DRAGONBOX=@SYSTEM_DRAGONBOX@
SYSTEM_FROZEN=@SYSTEM_FROZEN@
export ENABLE_EPOXY=@ENABLE_EPOXY@

View File

@ -1532,7 +1532,7 @@ libo_FUZZ_ARG_ENABLE(extensions,
AC_ARG_ENABLE(scripting,
AS_HELP_STRING([--disable-scripting],
[Disable BASIC, Java and Python. Work in progress, use only if you are hacking on it.]),
[Disable BASIC, Java, Python and .NET. Work in progress, use only if you are hacking on it.]),
,test "${enable_scripting+set}" = set || enable_scripting=yes)
# This is mainly for Android and iOS, but could potentially be used in some
@ -2158,6 +2158,10 @@ AC_ARG_ENABLE(customtarget-components,
AS_HELP_STRING([--enable-customtarget-components],
[Generates the static UNO object constructor mapping from the build.]))
AC_ARG_ENABLE(dotnet,
AS_HELP_STRING([--enable-dotnet],
[Enables or disables .NET 8.0 support and bindings generation.]))
dnl ===================================================================
dnl Optional Packages (--with/without-)
dnl ===================================================================
@ -3561,6 +3565,46 @@ if test "$COMPATH" = "."; then
fi
COMPATH=`echo $COMPATH | $SED "s@/[[Bb]][[Ii]][[Nn]]\\\$@@"`
dnl ===================================================================
dnl .NET support
dnl ===================================================================
AC_MSG_CHECKING([whether to build with .NET support])
if test "$enable_dotnet" != "no"; then
if test "$DISABLE_SCRIPTING" = TRUE; then
AC_MSG_RESULT([no, overridden by --disable-scripting])
ENABLE_DOTNET=""
enable_dotnet=no
else
AC_MSG_RESULT([yes])
ENABLE_DOTNET="TRUE"
fi
else
AC_MSG_RESULT([no])
ENABLE_DOTNET=""
fi
if test "$ENABLE_DOTNET" = TRUE; then
AC_PATH_PROG(DOTNET, dotnet)
if test "$DOTNET" != ""; then
AC_MSG_CHECKING([whether .NET SDK is installed])
DOTNET_SDK_VERION=`dotnet --list-sdks`
if test "$DOTNET_SDK_VERION" != ""; then
AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_FEATURE_DOTNET)
else
AC_MSG_RESULT([no])
ENABLE_DOTNET=""
fi
else
ENABLE_DOTNET=""
fi
fi
AC_SUBST(ENABLE_DOTNET)
dnl set ENABLE_DOTNET="TRUE" for build-time and run-time .NET support
dnl set ENABLE_DOTNET="" for no .NET support at all
dnl ===================================================================
dnl Java support
dnl ===================================================================

View File

@ -0,0 +1,27 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
$(eval $(call gb_DotnetLibrary_CsLibrary,net_basetypes))
$(eval $(call gb_DotnetLibrary_add_sources,net_basetypes,\
net_ure/source/basetypes/Any.cs \
net_ure/source/basetypes/BoundAttribute.cs \
net_ure/source/basetypes/Exception.cs \
net_ure/source/basetypes/IQueryInterface.cs \
net_ure/source/basetypes/RaisesAttribute.cs \
net_ure/source/basetypes/UnoGeneratedAttribute.cs \
))
$(eval $(call gb_DotnetLibrary_add_properties,net_basetypes,\
<AssemblyName>net_basetypes</AssemblyName> \
<Version>0.1.0</Version> \
<Company>LibreOffice</Company> \
<Description>Base datatypes for the .NET language UNO binding.</Description> \
))
# vim: set noet sw=4 ts=4:

13
net_ure/Makefile Normal file
View File

@ -0,0 +1,13 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
include $(module_directory)/../solenv/gbuild/partial_build.mk
# vim: set noet sw=4 ts=4:

17
net_ure/Module_net_ure.mk Normal file
View File

@ -0,0 +1,17 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
$(eval $(call gb_Module_Module,net_ure))
ifeq ($(ENABLE_DOTNET),TRUE)
$(eval $(call gb_Module_add_targets,net_ure,\
DotnetLibrary_net_basetypes \
))
endif
# vim: set noet sw=4 ts=4:

5
net_ure/README.md Normal file
View File

@ -0,0 +1,5 @@
# .NET UNO Runtime Environment
Support assemblies and tools for the newer cross-platform .NET UNO binding.
Currently only contains code for the net_basetypes assembly in the source/basetypes subdirectory.

View File

@ -0,0 +1,47 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
namespace com.sun.star.uno
{
public class Any
{
public static readonly Any VOID = new Any(typeof(void), null);
public Type Type { get; private set; }
public Object Value { get; private set; }
public Any(Type type, object value) => setValue(type, value);
public static Any with<T>(T value) => new Any(typeof(T), value);
public bool hasValue() => Type != typeof(void);
public void setValue(Type type, object value)
{
if (type is null)
throw new ArgumentNullException(nameof(type), "Type of Any cannot be null.");
if (type == typeof(Any))
throw new ArgumentException("Any object cannot be nested inside another Any.");
if (value is null && type != typeof(void))
throw new ArgumentException("Value of Any can only be null if Type is void." +
" Perhaps you want Any.VOID?");
Type = type;
Value = value;
}
public bool equals(Any obj) => Type == obj.Type && Value == obj.Value;
public override bool Equals(object obj) => (obj is Any other) && equals(other);
public override int GetHashCode() => (Type, Value).GetHashCode();
public override string ToString() => $"uno.Any {{ Type = {Type}, Value = {Value ?? "Null"} }}";
}
}

View File

@ -0,0 +1,15 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
namespace com.sun.star.uno
{
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
public sealed class BoundAttribute : Attribute { }
}

View File

@ -0,0 +1,25 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
namespace com.sun.star.uno
{
public class Exception : System.Exception
{
public new string Message { get; set; }
public IQueryInterface Context { get; set; }
public Exception() { }
public Exception(string Message, IQueryInterface Context)
{
this.Message = Message;
this.Context = Context;
}
}
}

View File

@ -0,0 +1,17 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
namespace com.sun.star.uno
{
public interface IQueryInterface
{
// Kept empty for now, until the .NET bridge is in place
}
}

View File

@ -0,0 +1,19 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
namespace com.sun.star.uno
{
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
public sealed class RaisesAttribute : Attribute
{
public Type[] Raises { get; }
public RaisesAttribute(params Type[] raises) => Raises = raises;
}
}

View File

@ -0,0 +1,16 @@
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
namespace com.sun.star.uno
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
| AttributeTargets.Interface | AttributeTargets.Enum, Inherited = false)]
public sealed class UnoGeneratedAttribute : Attribute { }
}

View File

@ -0,0 +1,171 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
##############################
# DotnetLibrary Target Class #
##############################
####### Constant Strings #########
gb_DotnetLibrary__CONFIG_RELEASE := -c Release
gb_DotnetLibrary__CONFIG_DEBUG := -c Debug
####### Helper Functions #########
define gb_DotnetLibrary__get_build_config
$(if $(or \
$(filter TRUE,$(strip $(debug))), \
$(filter TRUE,$(strip $(ENABLE_DBGUTIL))) \
), \
$(gb_DotnetLibrary__CONFIG_DEBUG), \
$(gb_DotnetLibrary__CONFIG_RELEASE))
endef
define gb_DotnetLibrary__escape_quotes
$(strip $(subst ",\",$(1)))
endef
####### Build and Clean Targets #########
.PHONY : $(call gb_DotnetLibrary_get_clean_target,%)
$(call gb_DotnetLibrary_get_clean_target,%) :
$(call gb_Output_announce,$*,$(false),NET,4)
$(call gb_Helper_abbreviate_dirs,\
rm -rf $(call gb_DotnetLibrary_get_target,$*))
$(call gb_DotnetLibrary_get_target,%) :
$(call gb_Output_announce,$*,$(true),NET,4)
$(call gb_Trace_StartRange,$*,NET)
$(call gb_Helper_abbreviate_dirs,\
mkdir -p $(call gb_DotnetLibrary_get_workdir,$*) && \
P=$(DOTNET_PROJECT_FILE) && \
echo "<Project Sdk=\"Microsoft.NET.Sdk\">" > $$P && \
echo "<PropertyGroup>" >> $$P && \
echo "$(DOTNET_PROPERTY_ELEMENTS)" >> $$P && \
echo "</PropertyGroup>" >> $$P && \
echo "<ItemGroup>" >> $$P && \
echo "$(DOTNET_ITEM_ELEMENTS)" >> $$P && \
echo "</ItemGroup>" >> $$P && \
echo "</Project>" >> $$P && \
dotnet build $$P $(DOTNET_BUILD_FLAGS) \
-o $(call gb_DotnetLibrary_get_workdir,$*) \
> $@.log 2>&1 || \
(cat $@.log \
&& echo \
&& echo "A library failed to build. To retry the build, use:" \
&& echo " make DotnetLibrary_$*" \
&& echo "cd into the module directory to run the build faster" \
&& echo \
&& false) && \
touch $@)
$(call gb_Trace_EndRange,$*,NET)
####### Library Target Constructors #########
define gb_DotnetLibrary__common_ctor
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_BUILD_FLAGS := $(strip $(call gb_DotnetLibrary__get_build_config))
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_PROPERTY_ELEMENTS := <TargetFramework>netstandard20</TargetFramework>
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_ITEM_ELEMENTS :=
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_PROJECT_FILE := $(call gb_DotnetLibrary_get_workdir,$(1))/$(1).$(2)
$(eval $(call gb_Module_register_target, \
$(call gb_DotnetLibrary_get_target,$(1)), \
$(call gb_DotnetLibrary_get_clean_target,$(1))))
$(call gb_Helper_make_userfriendly_targets,$(1),DotnetLibrary)
endef
# Generates one csproj file from given inputs and builds it
# call gb_DotnetLibrary_CsLibrary,targetname
define gb_DotnetLibrary_CsLibrary
$(call gb_DotnetLibrary__common_ctor,$(1),csproj)
endef
# Generates one fsproj file from given inputs and builds it
# call gb_DotnetLibrary_FsLibrary,targetname
define gb_DotnetLibrary_FsLibrary
$(call gb_DotnetLibrary__common_ctor,$(1),fsproj)
endef
# Generates one vbproj file from given inputs and builds it
# call gb_DotnetLibrary_VbLibrary,targetname
define gb_DotnetLibrary_VbLibrary
$(call gb_DotnetLibrary__common_ctor,$(1),vbproj)
endef
####### Target Property Setters #########
# Add flags used for compilation
# call gb_DotnetLibrary_add_build_flags,target,flags
define gb_DotnetLibrary_add_build_flags
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_BUILD_FLAGS += $(2)
endef
# Add <PropertyGroup> elements to the project file
# call gb_DotnetLibrary_add_properties,target,properties
define gb_DotnetLibrary_add_properties
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_PROPERTY_ELEMENTS += $(strip $(call gb_DotnetLibrary__escape_quotes,$(2)))
endef
# Add <ItemGroup> elements to the project file
# call gb_DotnetLibrary_add_items,target,items
define gb_DotnetLibrary_add_items
$(call gb_DotnetLibrary_get_target,$(1)) : DOTNET_ITEM_ELEMENTS += $(strip $(call gb_DotnetLibrary__escape_quotes,$(2)))
endef
# Add one source file to the project file
# This add it to the project, and makes it a build dependency
# so the library is rebuilt if the source changes
# call gb_DotnetLibrary_add_source,target,source
define gb_DotnetLibrary_add_source
$(call gb_DotnetLibrary_get_target,$(1)) : $(SRCDIR)/$(strip $(2))
$(call gb_DotnetLibrary_add_items,$(1),<Compile Include="$(SRCDIR)/$(strip $(2))"/>)
endef
# Add source files to the project file
# call gb_DotnetLibrary_add_sources,target,sources
define gb_DotnetLibrary_add_sources
$(foreach source,$(2),$(call gb_DotnetLibrary_add_source,$(1),$(source)))
endef
# Link to a DotnetLibrary_CsLibrary target
# call gb_DotnetLibrary_link_cs_project,target,project
define gb_DotnetLibrary_link_cs_project
$(call gb_DotnetLibrary_get_target,$(1)) : $(call gb_DotnetLibrary_get_target,$(strip $(2)))
$(call gb_DotnetLibrary_add_items,$(1),<ProjectReference Include="$(call gb_DotnetLibrary_get_workdir,$(strip $(2)))/$(strip $(2)).csproj"/>)
endef
# Link to a DotnetLibrary_FsLibrary target
# call gb_DotnetLibrary_link_fs_project,target,project
define gb_DotnetLibrary_link_fs_project
$(call gb_DotnetLibrary_get_target,$(1)) : $(call gb_DotnetLibrary_get_target,$(strip $(2)))
$(call gb_DotnetLibrary_add_items,$(1),<ProjectReference Include="$(call gb_DotnetLibrary_get_workdir,$(strip $(2)))/$(strip $(2)).fsproj"/>)
endef
# Link to a DotnetLibrary_VbLibrary target
# call gb_DotnetLibrary_link_vb_project,target,project
define gb_DotnetLibrary_link_vb_project
$(call gb_DotnetLibrary_get_target,$(1)) : $(call gb_DotnetLibrary_get_target,$(strip $(2)))
$(call gb_DotnetLibrary_add_items,$(1),<ProjectReference Include="$(call gb_DotnetLibrary_get_workdir,$(strip $(2)))/$(strip $(2)).vbproj"/>)
endef
# vim: set noet sw=4 ts=4:

View File

@ -62,6 +62,8 @@ gb_DescriptionTranslateTarget_get_target = $(WORKDIR)/DescriptionTranslateTarget
gb_Dictionary_get_target = $(WORKDIR)/Dictionary/$(1).done
gb_CxxObject_get_target = $(WORKDIR)/CxxObject/$(1).o
gb_CxxObject_get_dwo_target = $(WORKDIR)/CxxObject/$(1).dwo
gb_DotnetLibrary_get_target = $(WORKDIR)/DotnetLibrary/$(1).done
gb_DotnetLibrary_get_workdir = $(WORKDIR)/DotnetLibrary/$(1)
gb_GenCxxObject_get_target = $(WORKDIR)/GenCxxObject/$(1).o
gb_GenCxxObject_get_dwo_target = $(WORKDIR)/GenCxxObject/$(1).dwo
gb_GenAsmObject_get_target = $(WORKDIR)/GenAsmObject/$(1).o
@ -272,6 +274,7 @@ $(eval $(call gb_Helper_make_clean_targets,\
CustomPackage \
DescriptionTranslateTarget \
Dictionary \
DotnetLibrary \
Executable \
ExternalPackage \
Extension \

View File

@ -82,6 +82,7 @@ AVAILABLE TARGETS
o CppunitTest
o CustomTarget
o Dictionary
o DotnetLibrary
o Executable
o Extension
o ExternalPackage

View File

@ -331,6 +331,7 @@ include $(foreach class, \
CliLibrary \
CliNativeLibrary \
CliUnoApi \
DotnetLibrary \
Zip \
AllLangPackage \
Configuration \