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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ TestResult.xml

## macOS
.DS_Store
test/SmokeTest/Stubs
270 changes: 119 additions & 151 deletions src/nanoFramework.NET.Sdk/Sdk/nanoFramework.Mdp.targets

Large diffs are not rendered by default.

96 changes: 66 additions & 30 deletions src/nanoFramework.NET.Sdk/Sdk/nanoFramework.Output.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@
Incorrect changes will break .NET nanoFramework project builds.
********************************************************************************

Produces the deployable binary (GenerateBinaryOutputTask), copies the .pe /
.pdbx artifacts between the intermediate and output directories, and cleans
the generated nanoFramework files. These run after the MetadataProcessor has
emitted the .pe.
Produces the deployable binary (GenerateBinaryOutputTask), surfaces the native
methods checksum, copies the .pe / .pdbx artifacts to the output directory, and
cleans the generated nanoFramework files.

Ordering (hooked via AfterTargets, see nanoFramework.Mdp.targets):
GenerateNanoPeFile (.pe / .pdbx in intermediate dir)
-> NanoGenerateBinaryOutput (deployable .bin; runs BEFORE the
standard copy so a library's OutDir
.dll is left intact afterwards)
-> NanoReportChecksum (surface $(NanoNativeMethodsChecksum))
CopyFilesToOutputDirectory (Microsoft.NET.Sdk)
-> NanoCopyOutputFiles (.pe / .pdbx -> OutDir)
-> _NanoCopyReferencesToIntermediate

Imported by Sdk.targets AFTER nanoFramework.Mdp.targets, which defines the
shared $(_NanoBuildTasksDir) and $(_Nano*) properties used below and
wires these targets into the build pipeline (PrepareForRunDependsOn,
CleanDependsOn) and the NanoMetadataProcessor* targets (via CallTarget).
shared $(_NanoBuildTasksDir) and $(_Nano*) properties used below.
-->

<!-- nanoFramework binary-output task (bundled in SDK) -->
Expand All @@ -31,25 +38,57 @@
AssemblyFile="$(NF_MSBUILDTASK_PATH)\nanoFramework.Tools.BuildTasks.dll" />

<!-- ============================================================ -->
<!-- Clean targets -->
<!-- Binary output -->
<!-- Runs after the PE is emitted and BEFORE -->
<!-- CopyFilesToOutputDirectory: for executables it produces the -->
<!-- deployable .bin; for libraries it writes a transient blob -->
<!-- over OutDir\<name>.dll which the standard copy then -->
<!-- overwrites with the real managed assembly. -->
<!-- ============================================================ -->
<Target Name="NanoClean">
<Delete Condition="EXISTS('$(OutDir)$(TargetName).pe')" Files="$(OutDir)$(TargetName).pe" />
<Delete Condition="EXISTS('$(OutDir)$(TargetName).pdbx')" Files="$(OutDir)$(TargetName).pdbx" />
<Target Name="NanoGenerateBinaryOutput"
AfterTargets="GenerateNanoPeFile"
Condition="'$(DisableNanoMdp)' != 'true' and '$(NanoIsCoreLibrary)' != 'True'"
DependsOnTargets="ResolveReferences">
<GenerateBinaryOutputTask
AssemblyPE="$(_NanoMdpCompileOutput)"
Assembly="$(_NanoOutputAssembly)$(TargetExt)"
AssemblyReferences="@(ReferencePath);@(ReferenceDependencyPaths)">
<Output TaskParameter="FileWritten" ItemName="FileWrites" />
</GenerateBinaryOutputTask>
</Target>

<!-- ============================================================ -->
<!-- Copy targets -->
<!-- Surface the native methods checksum -->
<!-- Reads from the sidecar .checksum file written by -->
<!-- GenerateNanoPeFile so it works on incremental builds where -->
<!-- the PE step is skipped and NanoNativeMethodsChecksum is not -->
<!-- re-populated. Importance="High" ensures the ##vso logging -->
<!-- command reaches the Azure Pipelines agent even when MSBuild -->
<!-- runs at minimal verbosity (/v:m). -->
<!-- NF_NATIVE_ASSEMBLY_CHECKSUM is a fixed external contract. -->
<!-- ============================================================ -->
<Target Name="_NanoCopyAssemblyToOutDir">
<Copy Condition="Exists('$(IntermediateOutputPath)$(TargetFileName)')"
SourceFiles="$(IntermediateOutputPath)$(TargetFileName)"
DestinationFolder="$(OutDir)">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
</Copy>
<Target Name="NanoReportChecksum"
AfterTargets="GenerateNanoPeFile"
Condition="Exists('$(_NanoMdpCompileOutputNoExt).checksum')">
<ReadLinesFromFile File="$(_NanoMdpCompileOutputNoExt).checksum">
<Output TaskParameter="Lines" ItemName="_NanoChecksumLines" />
</ReadLinesFromFile>
<PropertyGroup>
<_NanoNativeMethodsChecksumPersisted>@(_NanoChecksumLines)</_NanoNativeMethodsChecksumPersisted>
</PropertyGroup>
<Message Text="##vso[task.setvariable variable=NF_NATIVE_ASSEMBLY_CHECKSUM;]$(_NanoNativeMethodsChecksumPersisted)"
Importance="High"
Condition="'$(TF_BUILD)' == 'True'" />
<WriteLinesToFile File="$(GITHUB_ENV)" Lines="NF_NATIVE_ASSEMBLY_CHECKSUM=$(_NanoNativeMethodsChecksumPersisted)"
Condition="'$(GITHUB_ACTIONS)' == 'True'" />
</Target>

<Target Name="NanoCopyOutputFiles">
<!-- ============================================================ -->
<!-- Copy targets (run after the standard output copy) -->
<!-- ============================================================ -->
<Target Name="NanoCopyOutputFiles"
AfterTargets="CopyFilesToOutputDirectory"
Condition="'$(DisableNanoMdp)' != 'true'">
<Copy Condition="Exists('$(_NanoIntermediateAssembly).pe')"
SourceFiles="$(_NanoIntermediateAssembly).pe"
DestinationFiles="$(_NanoOutputAssembly).pe" SkipUnchangedFiles="true">
Expand All @@ -72,7 +111,9 @@
</Copy>
</Target>

<Target Name="_NanoCopyReferencesToIntermediate">
<Target Name="_NanoCopyReferencesToIntermediate"
AfterTargets="CopyFilesToOutputDirectory"
Condition="'$(DisableNanoMdp)' != 'true'">
<Copy SourceFiles="@(ReferenceCopyLocalPaths)"
DestinationFiles="@(ReferenceCopyLocalPaths->'$(IntermediateOutputPath)%(Filename)%(Extension)')"
SkipUnchangedFiles="false">
Expand All @@ -81,21 +122,16 @@
</Target>

<!-- ============================================================ -->
<!-- Binary output -->
<!-- Clean targets -->
<!-- ============================================================ -->
<Target Name="NanoGenerateBinaryOutput"
DependsOnTargets="ResolveReferences">
<GenerateBinaryOutputTask
AssemblyPE="$(_NanoIntermediateAssembly).pe"
Assembly="$(_NanoOutputAssembly)$(TargetExt)"
AssemblyReferences="@(ReferencePath);@(ReferenceDependencyPaths)">
<Output TaskParameter="FileWritten" ItemName="FileWrites" />
</GenerateBinaryOutputTask>
<Target Name="NanoClean">
<Delete Condition="EXISTS('$(OutDir)$(TargetName).pe')" Files="$(OutDir)$(TargetName).pe" />
<Delete Condition="EXISTS('$(OutDir)$(TargetName).pdbx')" Files="$(OutDir)$(TargetName).pdbx" />
</Target>

<!-- Clean extra files for core assembly builds -->
<Target Name="_NanoCleanExtraFiles" Condition="'$(NanoIsCoreLibrary)' == 'True'">
<Delete Files="$(_NanoMdpCompileOutput);$(_NanoMdpCompileOutputNoExt).pdbx;$(_NanoMdpDumpExportsFile);$(_NanoMdpDependencyMapFile)"
<Delete Files="$(_NanoMdpCompileOutput);$(_NanoMdpCompileOutputNoExt).pdbx;$(_NanoMdpDumpExportsFile);$(_NanoMdpDependencyMapFile);$(_NanoMdpSaveStringsFile)"
TreatErrorsAsWarnings="true" />
</Target>

Expand Down
6 changes: 6 additions & 0 deletions test/SmokeTest/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Reflection;

[assembly: AssemblyNativeVersion("1.0.0.0")]
5 changes: 4 additions & 1 deletion test/SmokeTest/HelloNano.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace SmokeTest
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace SmokeTest
{
public class HelloNano
{
Expand Down
34 changes: 34 additions & 0 deletions test/SmokeTest/NativeLibrary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

namespace SmokeTest
{
internal class NativeLibrary
{
public void Method()
{
NativeMethod();

byte a = 0;
ushort b = 0;
NativeMethodWithReferenceParameters(ref a, ref b);
}

[MethodImpl(MethodImplOptions.InternalCall)]
private extern void NativeMethod();

[MethodImpl(MethodImplOptions.InternalCall)]
private extern void NativeMethodWithReferenceParameters(ref byte refByteParam, ref ushort refUshortParam);

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void NativeStaticMethod();

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern byte NativeStaticMethodReturningByte(char charParam);

[MethodImpl(MethodImplOptions.InternalCall)]
public extern unsafe void MethodWithPointerParm(void* pointer, int length);
}
}
5 changes: 5 additions & 0 deletions test/SmokeTest/SmokeTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<OutputType>Library</OutputType>
<RootNamespace>SmokeTest</RootNamespace>
<AssemblyName>SmokeTest</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<PropertyGroup>
<_NanoMdpGenerateStubs>true</_NanoMdpGenerateStubs>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading