Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project InitialTargets="VerifyProjectSettings;ShowBuildParameters">
<Project InitialTargets="VerifyProjectSettings;ShowBuildParameters;EnsureBuildOutputPaths">
<!--
Since Nuget.config is configured to include the build output location this
will ensure the folder exists during restore so that it won't fail.
-->
<Target Name="EnsureBuildOutputPaths" BeforeTargets="Restore;Build;Rebuild">
<Target Name="EnsureBuildOutputPaths" Condition="!Exists($(PackageOutputPath))">
<MakeDir Directories="$(PackageOutputPath)"/>
</Target>

Expand Down
6 changes: 5 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<ItemGroup>
<GlobalPackageReference Include="Ubiquity.NET.Versioning.Build.Tasks" Version="5.0.7-alpha.0.1" />
<GlobalPackageReference Include="IDisposableAnalyzers" Version="4.0.8" Condition="'$(NoCommonAnalyzers)' !=' true'" />
<GlobalPackageReference Include="MustUseRetVal" Version="0.0.2" />
<GlobalPackageReference Include="MustUseRetVal" Version="0.0.2" Condition="'$(NoCommonAnalyzers)' !=' true'" />

<!--
NOTE: This analyzer is sadly, perpetually in "pre-release mode". There have been many issues/discussion on the point
and it has all fallen on deaf ears. So policies regarding "NO-Prerelease" components need to be overruled on this one
Expand Down Expand Up @@ -34,10 +35,13 @@

<!-- Common packages for solution -->
<PackageVersion Include="System.Linq.Async" Version="6.0.3" />
<PackageVersion Include="Ubiquity.NET.LibLLVM" Version="20.1.8" />
<PackageVersion Include="Ubiquity.NET.Versioning" Version="6.0.2-beta" />
<PackageVersion Include="Antlr4BuildTasks" Version="12.10.0" />
<PackageVersion Include="Antlr4.Runtime.Standard" Version="4.13.1" />
<PackageVersion Include="OpenSoftware.DgmlBuilder" Version="2.1.0" />
<PackageVersion Include="CppSharp" Version="1.1.5.3168" />
<PackageVersion Include="System.CodeDom" Version="9.0.7" />

<!-- Tests all use the same framework versions -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
Expand Down
51 changes: 51 additions & 0 deletions Generate-HandleWrappers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<#
.SYNOPSIS
Generates the wrappers for handles from the headers in the Ubiquity.NET.LibLLVM NuGet Package

.DESCRIPTION
This is used 'off-line' (by a developer) to generate the source for the handle wrappers. It is
NOT run during an automated build as the generator itself is dependent on the CppSharp library
that only supports the X64 architecture. Automated builds may (at some point in the future)
run on any architecture supported by .NET so cannot generate the sources at build time. A developer
machine generating the wrappers is assumed X64 (Windows, Linux, or Mac)

.PARAMETER SkipRun
This parameter is used for inner loop testing to generate the response file so the paths
match the actual version of the package used. It skips actually building/running the
generator so that a developer can debug the run of that stage.
#>
Param(
[switch]$SkipRun
)

Push-Location $PSScriptRoot
$oldPath = $env:Path
try
{
$ErrorActionPreference = 'stop'
$generatorProj = '.\src\Interop\LlvmBindingsGenerator\LlvmBindingsGenerator.csproj'
$rspPath = Join-Path $PSScriptRoot 'generator.rsp'

Write-Information "Generating response file: $rspPath via GenerateResponseFile target in $generatorProj"
dotnet msbuild -restore -target:GenerateResponseFile -property:HandleGeneratorResponeFilePath=`""$rspPath"`" $generatorProj

if(!$SkipRun)
{
Write-Information 'Generating Handle wrapper source...'
dotnet run --no-restore --project $generatorProj -- @$rspPath
}
}
catch
{
# Everything from the official docs to the various articles in the blog-sphere say this isn't needed
# and in fact it is redundant - They're all WRONG! By re-throwing the exception the original location
# information is retained and the error reported will include the correct source file and line number
# data for the error. Without this, only the error message is retained and the location information is
# Line 1, Column 1, of the outer most script file, which is, of course, completely useless.
throw
}
finally
{
Pop-Location
$env:Path = $oldPath
}
12 changes: 12 additions & 0 deletions IgnoredWords.dic
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ attrib
Attribs
AttributeSet
Attrs
automatable
baz
binaryop
binlogs
Expand All @@ -32,6 +33,7 @@ buildtransitive
builtinop
byref
byval
canonicalization
castable
cibuild
Cmp
Expand Down Expand Up @@ -67,11 +69,13 @@ foo
fullsrc
func
getelementptr
getters
gh
github
Globalization
Hashtable
Identifier
ifunc
Impl
initializer
inline
Expand All @@ -86,12 +90,15 @@ LibLLVM
Llilum
llvm
llvmversion
lookups
LValue
malloc
marshallers
marshalling
materializer
memcopy
memcpy
memset
metadata
Mips
msbuild
Expand All @@ -106,6 +113,7 @@ Nullable
Nvidia
online
optimizenone
outdent
pages
paren
perf
Expand All @@ -119,6 +127,7 @@ readonly
refactor
refcount
referenceable
Relocations
repl
repo
RMW
Expand All @@ -136,10 +145,12 @@ structs
Subrange
Sym
telliam
templated
tl
trx
typdef
Typedef
typedefs
typelib
typeof
uid
Expand All @@ -151,6 +162,7 @@ Unhandled
uniqued
uniqueing
unmarshal
unreferenced
Unshipped
userdefinedop
Users
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "9.0.201",
"version": "9.0.305",
"rollForward": "latestMinor",
"allowPrerelease": false
},
Expand Down
14 changes: 10 additions & 4 deletions src/Interop/InteropTests/ABI/libllvm-c/DataLayoutBindingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Ubiquity.NET.InteropHelpers;
using Ubiquity.NET.Llvm.Interop.ABI.StringMarshaling;

using static Ubiquity.NET.Llvm.Interop.ABI.libllvm_c.DataLayoutBindings;
using static Ubiquity.NET.Llvm.Interop.ABI.llvm_c.Error;

namespace Ubiquity.NET.Llvm.Interop.ABI.libllvm_c.UT
{
Expand All @@ -15,11 +17,15 @@ public class DataLayoutBindingsTests
[TestMethod]
public void LibLLVMParseDataLayoutTest( )
{
using(var errorRef = LibLLVMParseDataLayout( "badlayout"u8, out LLVMTargetDataRef retVal ))
using(retVal)
using(LLVMErrorRef errorRef = LibLLVMParseDataLayout( "badlayout"u8, out LLVMTargetDataRef retVal ))
{
Assert.IsTrue( retVal.IsInvalid );
Assert.IsTrue( retVal.IsNull );
Assert.IsTrue( errorRef.Failed );
Assert.IsFalse( errorRef.Success);
Assert.IsFalse( errorRef.IsNull );
Assert.IsTrue( errorRef.IsString );
Assert.AreEqual(LLVMGetStringErrorTypeId(), errorRef.TypeId);
Assert.AreNotEqual( 0, errorRef.DangerousGetHandle() );
string errMsg = errorRef.ToString();
Assert.IsFalse( string.IsNullOrWhiteSpace( errMsg ), "Failure should have an error message" );
}
Expand All @@ -31,7 +37,7 @@ public void LibLLVMParseDataLayoutTest( )
{
Assert.IsFalse( errorRef.Failed );
Assert.IsTrue( errorRef.Success );
Assert.IsFalse( retVal.IsInvalid );
Assert.IsFalse( retVal.IsNull );
string errMsg = errorRef.ToString();
Assert.IsTrue( string.IsNullOrWhiteSpace( errMsg ), "Valid layout should NOT have an error message" );
}
Expand Down
4 changes: 2 additions & 2 deletions src/Interop/InteropTests/ContextHandleMarshallerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ContextHandleMarshallerTests
[TestMethod]
public void ConvertToManagedTest( )
{
var handle = ContextHandleMarshaller<LibLLVMMDOperandRef>.ConvertToManaged(NativeABIValue);
var handle = WrappedHandleMarshaller<LibLLVMMDOperandRef>.ConvertToManaged(NativeABIValue);
Assert.IsFalse( handle.IsNull );
Assert.AreEqual( NativeABIValue, handle.DangerousGetHandle() );
Assert.AreEqual( NativeABIValue, (nint)handle );
Expand All @@ -24,7 +24,7 @@ public void ConvertToUnmanagedTest( )

// Validate FromABI() method AND verify assumptions made in subsequent asserts...
Assert.AreEqual( NativeABIValue, handle.DangerousGetHandle() );
nint abiHandleVal = ContextHandleMarshaller<LibLLVMMDOperandRef>.ConvertToUnmanaged(handle);
nint abiHandleVal = WrappedHandleMarshaller<LibLLVMMDOperandRef>.ConvertToUnmanaged(handle);
Assert.AreEqual( NativeABIValue, abiHandleVal );
}

Expand Down
36 changes: 34 additions & 2 deletions src/Interop/InteropTests/DebugRecordTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Ubiquity.NET Contributors. All rights reserved.
// Licensed under the Apache-2.0 WITH LLVM-exception license. See the LICENSE.md file in the project root for full license information.

using System;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Ubiquity.NET.Llvm.Interop.ABI.libllvm_c;
Expand Down Expand Up @@ -60,6 +62,24 @@ public void DebugRecordEnumerationSucceeds( )
// Now attach debug records to the malloc.
// first create the information to attach (It's a lot...)
using LLVMDIBuilderRef diBuilder = LLVMCreateDIBuilder(module);
LLVMMetadataRef diFile = LLVMDIBuilderCreateFile(diBuilder, "testfile.cs"u8, Environment.CurrentDirectory);
LLVMMetadataRef diCU = LLVMDIBuilderCreateCompileUnit(
diBuilder,
LLVMDWARFSourceLanguage.LLVMDWARFSourceLanguageC_sharp,
diFile,
Producer: null,
isOptimized: false,
Flags: null,
RuntimeVer: 0,
SplitName: null,
LLVMDWARFEmissionKind.LLVMDWARFEmissionFull,
DWOId: 0,
SplitDebugInlining: false,
DebugInfoForProfiling: false,
SysRoot: null,
SDK: null
);

LLVMMetadataRef int32DiType = LLVMDIBuilderCreateBasicType(
diBuilder,
"int32_t"u8,
Expand All @@ -76,7 +96,7 @@ public void DebugRecordEnumerationSucceeds( )
Scope: default,
Name: "TestFunc"u8,
LinkageName: "_TestFunc"u8,
File: default,
File: diFile,
LineNo: 0,
Ty: diFuncType,
IsLocalToUnit: true,
Expand All @@ -85,11 +105,23 @@ public void DebugRecordEnumerationSucceeds( )
LLVMDIFlags.LLVMDIFlagPrivate,
IsOptimized: false
);

var diLocalVar = LLVMDIBuilderCreateAutoVariable(
diBuilder,
scope,
Name: string.Empty,
File: diFile,
LineNo: 0,
int32PtrDiType,
AlwaysPreserve: false,
LLVMDIFlags.LLVMDIFlagArtificial,
4);

LLVMMetadataRef diLocation = LLVMDIBuilderCreateDebugLocation(ctx, 123,4, scope, default);

// Now attach the record to the result of the malloc call
// and retest the status as it should be different now
LLVMDbgRecordRef dbgRecord = LLVMDIBuilderInsertDbgValueRecordBefore(diBuilder, mallocInst, int32PtrDiType, emptyExpression, diLocation, mallocInst);
LLVMDbgRecordRef dbgRecord = LLVMDIBuilderInsertDbgValueRecordBefore(diBuilder, mallocInst, diLocalVar, emptyExpression, diLocation, mallocInst);
Assert.IsTrue( LibLLVMHasDbgRecords( mallocInst ) );

// this should not crash now... [It shouldn't ever but that's another story...]
Expand Down
93 changes: 0 additions & 93 deletions src/Interop/InteropTests/GlobalHandleBaseTests.cs

This file was deleted.

Loading
Loading