diff options
author | lateralusX <lateralusx.github@gmail.com> | 2018-11-06 18:23:56 +0300 |
---|---|---|
committer | lateralusX <lateralusx.github@gmail.com> | 2018-11-12 17:16:14 +0300 |
commit | 269d02cf5b3c906954bbba944fc9d5918fa1ad75 (patch) | |
tree | b0d789dcf9579773bbbf5929272f1d590f41b6a9 /msvc/mono.external.targets | |
parent | f038e7cd8a4edcfc9ebbfb8dfd0b595fdcaada15 (diff) |
Add support for LLVM integrated build as part of Visual Studio solution
build. LLVM build follows similar pattern as BTLS build and will be build
as part of regular Visual Studio build Mono runtime if LLVM has been enabled
through the autogen.sh, --enable-llvm or –with-llvm argument. It is also
supports msbuild properties MONO_ENABLE_LLVM, MONO_EXTERNAL_LLVM_CONFIG,
if Visual Studio Mono runtime has been built without using autogen.sh.
When just using –enable-llvm, LLVM build will try to build internal LLVM
branch under external/llvm or if override has been set in props file
(using MONO_INTERNAL_LLVM_SOURCE_DIR), an alternative LLVM source
directory path. If –with-llvm has been used pointing to an llvm-config.exe,
no internal LLVM will be build, but the external LLVM build will be used.
Needed LLVM executables (opt.exe, llc.exe) will be installed into regular
Visual Studio Mono runtime build output directory.
The internal Mono LLVM 6.0 release will build as part of changes to this
commit, but it has not yet been fixed to work as expected during runtime.
That work will be done in different commit. The Mono LLVM 3.6 branch will
however work as expected for Windows x64 and can be setup and used using
–with-llvm argument or build as part of Visual Studio build Mono runtime
by enabling msbuild properties, MONO_ENABLE_LLVM and
MONO_INTERNAL_LLVM_SOURCE_DIR.
Diffstat (limited to 'msvc/mono.external.targets')
-rw-r--r-- | msvc/mono.external.targets | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/msvc/mono.external.targets b/msvc/mono.external.targets new file mode 100644 index 00000000000..9551a71e9b0 --- /dev/null +++ b/msvc/mono.external.targets @@ -0,0 +1,220 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + + <UsingTask TaskName="_CheckConfigurationProperty" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> + <ParameterGroup> + <ConfFile ParameterType="System.String" Required="true" /> + <ConfRegEx ParameterType="System.String" Required="true" /> + <ConfPropertyName ParameterType="System.String" Output="true" /> + <ConfPropertyValue ParameterType="System.String" Output="true" /> + <ConfPropertyFoundMatch ParameterType="System.String" Output="true" /> + </ParameterGroup> + <Task> + <Code Type="Fragment" Language="cs"> + <![CDATA[ + + ConfPropertyName = ""; + ConfPropertyValue = ""; + ConfPropertyFoundMatch = "false"; + + var regex = new System.Text.RegularExpressions.Regex (ConfRegEx); + using (StreamReader reader = new StreamReader(ConfFile)) + { + string line; + while ((line = reader.ReadLine ()) != null) + { + var match = regex.Match (line); + if (match != null && match.Success) + { + if (match.Groups != null && match.Groups.Count == 1) + { + var propertyLine = match.Groups[0].ToString (); + if (!String.IsNullOrEmpty (propertyLine)) + { + var propertyLineItems = propertyLine.Split ('='); + if (propertyLineItems != null && propertyLineItems.Length == 2) + { + ConfPropertyName = propertyLineItems[0].Trim (); + ConfPropertyValue = propertyLineItems[1].Trim (); + } + } + } + ConfPropertyFoundMatch = "true"; + break; + } + } + } + ]]> + </Code> + </Task> + </UsingTask> + + <UsingTask TaskName="_GetLLVMConfiguration" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> + <ParameterGroup> + <LLVMConfTool ParameterType="System.String" Required="true" /> + <LLVMConfToolArg ParameterType="System.String" Required="true" /> + <LLVMConfToolOut ParameterType="System.String" Output="true" /> + </ParameterGroup> + <Task> + <Using Namespace="System" /> + <Using Namespace="System.Text" /> + <Using Namespace="System.Diagnostics" /> + <Code Type="Fragment" Language="cs"> + <![CDATA[ + var process = new Process (); + + process.StartInfo.FileName = LLVMConfTool; + process.StartInfo.Arguments = LLVMConfToolArg; + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.Start (); + + LLVMConfToolOut = process.StandardOutput.ReadToEnd ().Trim (); + process.WaitForExit (); + + if (LLVMConfToolArg.StartsWith ("--libnames")) + { + var libs = LLVMConfToolOut.Split (' '); + StringBuilder libNames = new StringBuilder (); + foreach (var lib in libs) + { + var libPrefixEnd = lib.StartsWith ("lib") ? 3 : 0; + var libExtensionStart = lib.LastIndexOf ("."); + + if (libNames.Length != 0) + libNames.Append (" "); + + libNames.Append (lib.Substring (libPrefixEnd, libExtensionStart - libPrefixEnd) + ".lib"); + } + + LLVMConfToolOut = libNames.ToString (); + } + + if (process.ExitCode != 0) + LLVMConfToolOut = ""; + ]]> + </Code> + </Task> + </UsingTask> + + <PropertyGroup> + <_MonoSourceDir>$([System.IO.Path]::GetFullPath('$(MONO_DIR)').TrimEnd('\'))</_MonoSourceDir> + <_MonoOutputDir>$([System.IO.Path]::GetFullPath('$(OutDir)'))</_MonoOutputDir> + </PropertyGroup> + + <PropertyGroup> + <_LLVMSourceDir>$(MONO_INTERNAL_LLVM_SOURCE_DIR)</_LLVMSourceDir> + <_LLVMSourceDir Condition="'$(_LLVMSourceDir)' == ''">$(_MonoSourceDir)\external\llvm</_LLVMSourceDir> + <_LLVMBuildDir>$([System.IO.Path]::GetFullPath('$(MONO_BUILD_DIR_PREFIX)$(Platform)\obj\external\llvm-build\$(Configuration)'))</_LLVMBuildDir> + <_LLVMInstallDir>$(_LLVMBuildDir)\install</_LLVMInstallDir> + </PropertyGroup> + + <PropertyGroup> + <_BtlsBuildDir>$([System.IO.Path]::GetFullPath('$(MONO_BUILD_DIR_PREFIX)$(Platform)\obj\external\btls-build-shared\$(Configuration)'))</_BtlsBuildDir> + </PropertyGroup> + + <Target Name="_CheckEnableBtls" Condition="'$(MONO_ENABLE_BTLS)' != 'true'"> + <_CheckConfigurationProperty ConfFile="$(MONO_DIR)/cygconfig.h" ConfRegEx=".*#define.*HAVE_BTLS.*1"> + <Output TaskParameter="ConfPropertyFoundMatch" PropertyName="MONO_ENABLE_BTLS" /> + </_CheckConfigurationProperty> + </Target> + + <Target Name="_CheckEnableLLVM" Condition="'$(MONO_ENABLE_LLVM)' != 'true'"> + <_CheckConfigurationProperty ConfFile="$(MONO_DIR)/cygconfig.h" ConfRegEx=".*#define.*ENABLE_LLVM.*1"> + <Output TaskParameter="ConfPropertyFoundMatch" PropertyName="MONO_ENABLE_LLVM" /> + </_CheckConfigurationProperty> + </Target> + + <Target Name="_CheckInternalLLVM" Condition="'$(_MonoEnableInternalLLVM)' != 'true' and '$(_MonoEnableExternalLLVM)' != 'true' and '$(MONO_ENABLE_LLVM)' == 'true'" DependsOnTargets="_CheckEnableLLVM"> + <_CheckConfigurationProperty ConfFile="$(MONO_DIR)/cygconfig.h" ConfRegEx=".*#define.*INTERNAL_LLVM.*1"> + <Output TaskParameter="ConfPropertyFoundMatch" PropertyName="_MonoEnableInternalLLVM" /> + </_CheckConfigurationProperty> + </Target> + + <Target Name="_CheckExternalLLVM" Condition="'$(_MonoEnableExternalLLVM)' != 'true' and '$(_MonoEnableInternalLLVM)' != 'true' and '$(MONO_ENABLE_LLVM)' == 'true'" DependsOnTargets="_CheckEnableLLVM"> + <_CheckConfigurationProperty ConfFile="$(MONO_DIR)\Makefile" ConfRegEx=".*EXTERNAL_LLVM_CONFIG_WIN32.*llvm-config.exe"> + <Output TaskParameter="ConfPropertyFoundMatch" PropertyName="_MonoEnableExternalLLVM" /> + <Output TaskParameter="ConfPropertyValue" PropertyName="_CheckExternalLLVMOutput" /> + </_CheckConfigurationProperty> + <PropertyGroup> + <_MonoLLVMConfig Condition="'$(_MonoEnableExternalLLVM)' == 'true'">$(_CheckExternalLLVMOutput)</_MonoLLVMConfig> + </PropertyGroup> + </Target> + + <Target Name="_SetDefaultLLVMProperties" Condition="'$(MONO_ENABLE_LLVM)' == 'true'"> + <PropertyGroup Condition="'$(MONO_EXTERNAL_LLVM_CONFIG)' != ''"> + <_MonoEnableExternalLLVM>true</_MonoEnableExternalLLVM> + <_MonoEnableInternalLLVM>false</_MonoEnableInternalLLVM> + <_MonoLLVMConfig>$(MONO_EXTERNAL_LLVM_CONFIG)</_MonoLLVMConfig> + </PropertyGroup> + + <PropertyGroup Condition="'$(MONO_EXTERNAL_LLVM_CONFIG)' == ''"> + <_MonoEnableExternalLLVM>false</_MonoEnableExternalLLVM> + <_MonoEnableInternalLLVM>true</_MonoEnableInternalLLVM> + <_MonoLLVMConfig>$(_LLVMInstallDir)\bin\llvm-config.exe</_MonoLLVMConfig> + </PropertyGroup> + </Target> + + <Target Name="_SetupMonoLLVMBuildProperties" Condition="$(MONO_ENABLE_LLVM)=='true'"> + + <Error Text="LLVM config executable $(_MonoLLVMConfig) not found." Condition="!Exists($(_MonoLLVMConfig))" /> + + <_GetLLVMConfiguration LLVMConfTool="$(_MonoLLVMConfig)" LLVMConfToolArg="--version"> + <Output TaskParameter="LLVMConfToolOut" PropertyName="MONO_LLVM_VERSION" /> + </_GetLLVMConfiguration> + + <Error Text="Compiling with stock LLVM is not supported, please use the Mono LLVM repo at https://github.com/mono/llvm." Condition="!$(MONO_LLVM_VERSION.Contains('mono'))" /> + <Error Text="Expected llvm version 3.6 or 6.0, but llvm-config --version returned $(MONO_LLVM_VERSION)." Condition="!$(MONO_LLVM_VERSION.StartsWith('3.6')) and !$(MONO_LLVM_VERSION.StartsWith('6.0'))" /> + + <_GetLLVMConfiguration LLVMConfTool="$(_MonoLLVMConfig)" LLVMConfToolArg="--mono-api-version"> + <Output TaskParameter="LLVMConfToolOut" PropertyName="MONO_LLVM_API_VERSION" /> + </_GetLLVMConfiguration> + + <PropertyGroup> + <_MonoLLVMConfigComponents>analysis core bitwriter mcjit x86codegen</_MonoLLVMConfigComponents> + <_MonoLLVMConfigComponents Condition="$(MONO_LLVM_API_VERSION) < 600">$(_MonoLLVMConfigComponents) jit</_MonoLLVMConfigComponents> + <_MonoLLVMConfigComponents Condition="$(MONO_LLVM_API_VERSION) >= 600">$(_MonoLLVMConfigComponents) orcjit</_MonoLLVMConfigComponents> + </PropertyGroup> + + <_GetLLVMConfiguration LLVMConfTool="$(_MonoLLVMConfig)" LLVMConfToolArg="--libnames $(_MonoLLVMConfigComponents)"> + <Output TaskParameter="LLVMConfToolOut" PropertyName="MONO_LLVM_LIBS" /> + </_GetLLVMConfiguration> + + <PropertyGroup> + <MONO_LLVM_LIBS>$(MONO_LLVM_LIBS.Split(' '))</MONO_LLVM_LIBS> + </PropertyGroup> + + <_GetLLVMConfiguration LLVMConfTool="$(_MonoLLVMConfig)" LLVMConfToolArg="--includedir"> + <Output TaskParameter="LLVMConfToolOut" PropertyName="MONO_LLVM_INCLUDE_DIR" /> + </_GetLLVMConfiguration> + + <_GetLLVMConfiguration LLVMConfTool="$(_MonoLLVMConfig)" LLVMConfToolArg="--bindir"> + <Output TaskParameter="LLVMConfToolOut" PropertyName="MONO_LLVM_BIN_DIR" /> + </_GetLLVMConfiguration> + + <_GetLLVMConfiguration LLVMConfTool="$(_MonoLLVMConfig)" LLVMConfToolArg="--libdir"> + <Output TaskParameter="LLVMConfToolOut" PropertyName="MONO_LLVM_LIB_DIR" /> + </_GetLLVMConfiguration> + + <Message Importance="normal" Text="LLVM build properties:" /> + <Message Importance="normal" Text="MONO_LLVM_VERSION = $(MONO_LLVM_VERSION)" /> + <Message Importance="normal" Text="MONO_LLVM_API_VERSION = $(MONO_LLVM_API_VERSION)" /> + <Message Importance="normal" Text="MONO_LLVM_LIBS = $(MONO_LLVM_LIBS)" /> + <Message Importance="normal" Text="MONO_LLVM_INCLUDE_DIR = $(MONO_LLVM_INCLUDE_DIR)" /> + <Message Importance="normal" Text="MONO_LLVM_BIN_DIR = $(MONO_LLVM_BIN_DIR)" /> + <Message Importance="normal" Text="MONO_LLVM_LIB_DIR = $(MONO_LLVM_LIB_DIR)" /> + + </Target> + + <Target Name="_ConfigureExternalMonoLLVMBuildEnvironment" DependsOnTargets="_SetDefaultLLVMProperties;_CheckEnableLLVM;_CheckInternalLLVM;_CheckExternalLLVM" /> + <Target Name="_ConfigureExternalMonoBTLSBuildEnvironment" DependsOnTargets="_CheckEnableBtls" /> + <Target Name="_ConfigureExternalMonoBuildEnvironment" DependsOnTargets="_ConfigureExternalMonoLLVMBuildEnvironment;_ConfigureExternalMonoBTLSBuildEnvironment" /> + + <PropertyGroup> + <PrepareForBuildDependsOn> + _ConfigureExternalMonoBuildEnvironment; + $(PrepareForBuildDependsOn); + </PrepareForBuildDependsOn> + </PropertyGroup> + +</Project>
\ No newline at end of file |