Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c7096de

Browse files
committedMay 8, 2025
Merge branch 'main' of https://github.com/nanoframework/nf-interpreter into test-ti-build
2 parents 6b2dd49 + 9f60398 commit c7096de

File tree

9 files changed

+1814
-1805
lines changed

9 files changed

+1814
-1805
lines changed
 

‎.typo-ci.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎azure-pipelines-nightly.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,7 @@ jobs:
301301
steps:
302302
- template: azure-pipelines-templates/build-preparations.yml
303303
- template: azure-pipelines-templates/nb-gitversioning.yml
304-
- template: azure-pipelines-templates/download-install-cmake.yml
305304
- template: azure-pipelines-templates/download-install-arm-gcc-toolchain.yml
306-
- template: azure-pipelines-templates/download-install-ninja.yml
307305
- template: azure-pipelines-templates/download-srecord.yml
308306
- template: azure-pipelines-templates/download-hexdfu.yml
309307
- template: azure-pipelines-templates/build-chibios-stm32-targets.yml
@@ -724,9 +722,7 @@ jobs:
724722
steps:
725723
- template: azure-pipelines-templates/build-preparations.yml
726724
- template: azure-pipelines-templates/nb-gitversioning.yml
727-
- template: azure-pipelines-templates/download-install-cmake.yml
728725
- template: azure-pipelines-templates/download-install-arm-gcc-toolchain.yml
729-
- template: azure-pipelines-templates/download-install-ninja.yml
730726
- template: azure-pipelines-templates/download-hexdfu.yml
731727
- template: azure-pipelines-templates/download-srecord.yml
732728
- template: azure-pipelines-templates/build-azurertos-targets.yml

‎azure-pipelines.yml

Lines changed: 1490 additions & 1469 deletions
Large diffs are not rendered by default.

‎install-scripts/install-cmake.ps1

Lines changed: 242 additions & 189 deletions
Large diffs are not rendered by default.

‎nfcore.vssettings

Lines changed: 0 additions & 74 deletions
This file was deleted.

‎src/CLR/CorLib/corlib_native_System_Guid.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,31 @@
33
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
44
// See LICENSE file in the project root for full license information.
55
//
6-
#include "CorLib.h"
7-
8-
//
9-
// Generate a new GUID
10-
//
11-
// Based on the version 4 GUID (random)
12-
// http://guid.one/guid/make
136

7+
#include "CorLib.h"
148

15-
HRESULT Library_corlib_native_System_Guid::GenerateNewGuid___STATIC__SZARRAY_U1( CLR_RT_StackFrame& stack )
9+
HRESULT Library_corlib_native_System_Guid::GenerateNewGuid___STATIC__SZARRAY_U1(CLR_RT_StackFrame &stack)
1610
{
1711
NANOCLR_HEADER();
1812

19-
CLR_RT_Random rand;
20-
CLR_UINT8* buf;
21-
CLR_RT_HeapBlock& top = stack.PushValueAndClear();
22-
13+
CLR_RT_Random rand;
14+
CLR_UINT8 *buf;
15+
CLR_RT_HeapBlock &top = stack.PushValueAndClear();
16+
2317
// Create a array of 16 bytes on top of stack to return
24-
NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance( top, 16, g_CLR_RT_WellKnownTypes.m_UInt8 ));
18+
NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(top, 16, g_CLR_RT_WellKnownTypes.m_UInt8));
2519
buf = top.DereferenceArray()->GetFirstElement();
2620

2721
rand.Initialize();
28-
rand.NextBytes(buf, 16); // fill with random numbers
2922

30-
buf[7] = (buf[7] & 0x0f) | 0x40; // Set verion
31-
buf[9] = (buf[7] & 0x3f) | 0x80; // Set variant
32-
23+
// Generate 16 random bytes for the GUID
24+
rand.NextBytes(buf, 16);
25+
26+
// Set the version (version 4, bits 12-15 of time_hi_and_version)
27+
buf[7] = (buf[7] & 0x0F) | 0x40;
28+
29+
// Set the variant (the two most significant bits of clock_seq_hi_and_reserved must be 10)
30+
buf[8] = (buf[8] & 0x3F) | 0x80;
31+
3332
NANOCLR_NOCLEANUP();
3433
}

‎src/CLR/Debugger/Debugger.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) .NET Foundation and Contributors
33
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
44
// See LICENSE file in the project root for full license information.
@@ -1000,9 +1000,15 @@ bool CLR_DBG_Debugger::Monitor_WriteMemory(WP_Message *msg)
10001000

10011001
CLR_DBG_Commands_Monitor_WriteMemory *cmd = (CLR_DBG_Commands_Monitor_WriteMemory *)msg->m_payload;
10021002
CLR_DBG_Commands_Monitor_WriteMemory_Reply cmdReply;
1003+
uint32_t errorCode;
1004+
1005+
// command reply is to be loaded with the error code and sent back to the caller
1006+
g_CLR_DBG_Debugger->AccessMemory(cmd->address, cmd->length, cmd->data, AccessMemory_Write, &errorCode);
10031007

1004-
g_CLR_DBG_Debugger->AccessMemory(cmd->address, cmd->length, cmd->data, AccessMemory_Write, &cmdReply);
1008+
// copy over the error code to the command reply
1009+
cmdReply = errorCode;
10051010

1011+
// the execution of this command is always successful, and the reply carries the error code
10061012
WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply));
10071013

10081014
return true;
@@ -1016,9 +1022,12 @@ bool CLR_DBG_Debugger::Monitor_CheckMemory(WP_Message *msg)
10161022
CLR_DBG_Commands_Monitor_CheckMemory_Reply cmdReply;
10171023
uint32_t errorCode;
10181024

1025+
// access memory execution will load the command reply with the error code
10191026
g_CLR_DBG_Debugger
10201027
->AccessMemory(cmd->address, cmd->length, (unsigned char *)&cmdReply, AccessMemory_Check, &errorCode);
10211028

1029+
// the execution of this command will fail if there is an error code, never the less, the error code is returned to
1030+
// the caller
10221031
WP_ReplyToCommand(msg, errorCode == AccessMemoryErrorCode_NoError, false, &cmdReply, sizeof(cmdReply));
10231032

10241033
return true;
@@ -1030,9 +1039,15 @@ bool CLR_DBG_Debugger::Monitor_EraseMemory(WP_Message *msg)
10301039

10311040
CLR_DBG_Commands_Monitor_EraseMemory *cmd = (CLR_DBG_Commands_Monitor_EraseMemory *)msg->m_payload;
10321041
CLR_DBG_Commands_Monitor_EraseMemory_Reply cmdReply;
1042+
uint32_t errorCode;
1043+
1044+
// command reply is to be loaded with the error code and sent back to the caller
1045+
g_CLR_DBG_Debugger->AccessMemory(cmd->address, cmd->length, NULL, AccessMemory_Erase, &errorCode);
10331046

1034-
g_CLR_DBG_Debugger->AccessMemory(cmd->address, cmd->length, NULL, AccessMemory_Erase, &cmdReply);
1047+
// copy over the error code to the command reply
1048+
cmdReply = errorCode;
10351049

1050+
// the execution of this command is always successful, and the reply carries the error code
10361051
WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply));
10371052

10381053
return true;

‎targets/netcore/nanoFramework.nanoCLR.CLI/ClrInstanceOperationsProcessor.cs

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
@@ -16,6 +16,9 @@ namespace nanoFramework.nanoCLR.CLI
1616
public static class ClrInstanceOperationsProcessor
1717
{
1818
private const string _cloudSmithApiUrl = "https://api.cloudsmith.io/v1/packages/net-nanoframework/";
19+
private const string _refTargetsDevRepo = "nanoframework-images-dev";
20+
private const string _refTargetsStableRepo = "nanoframework-images";
21+
1922
private static HttpClient _httpClient = new HttpClient();
2023

2124
public static int ProcessVerb(ClrInstanceOperationsOptions options)
@@ -52,6 +55,7 @@ public static int ProcessVerb(ClrInstanceOperationsOptions options)
5255
return (int)UpdateNanoCLRAsync(
5356
options.TargetVersion,
5457
hostBuilder.GetCLRVersion(),
58+
options.CheckPreviewVersions,
5559
hostBuilder).Result;
5660
}
5761
else if (options.GetCLRVersion || options.GetNativeAssemblies)
@@ -110,12 +114,13 @@ orderby na.Name
110114
private static async Task<ExitCode> UpdateNanoCLRAsync(
111115
string targetVersion,
112116
string currentVersion,
117+
bool usePreview,
113118
nanoCLRHostBuilder hostBuilder)
114119
{
115120
try
116121
{
117122
// compose current version
118-
// need to get rid of git hub has, in case it has one
123+
// need to get rid of GitHub hash, in case it has one
119124
if (string.IsNullOrEmpty(currentVersion))
120125
{
121126
currentVersion = "0.0.0.0";
@@ -127,7 +132,7 @@ private static async Task<ExitCode> UpdateNanoCLRAsync(
127132
currentVersion.IndexOf("+") < 0 ? currentVersion.Length : currentVersion.IndexOf("+"));
128133
}
129134

130-
Version version = Version.Parse(currentVersion);
135+
Version installedVersion = Version.Parse(currentVersion);
131136

132137
string nanoClrDllLocation = Path.Combine(
133138
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
@@ -137,43 +142,62 @@ private static async Task<ExitCode> UpdateNanoCLRAsync(
137142
_httpClient.BaseAddress = new Uri(_cloudSmithApiUrl);
138143
_httpClient.DefaultRequestHeaders.Add("Accept", "*/*");
139144

140-
// get latest version available for download
141-
HttpResponseMessage response = await _httpClient.GetAsync($"nanoframework-images/?query=name:^WIN_DLL_nanoCLR version:^latest$");
142-
string responseBody = await response.Content.ReadAsStringAsync();
145+
string repoName = usePreview ? _refTargetsDevRepo : _refTargetsStableRepo;
146+
List<CloudsmithPackageInfo> packageInfo;
147+
string responseBody;
143148

144-
if (responseBody == "[]")
149+
if (string.IsNullOrEmpty(targetVersion))
145150
{
146-
Console.WriteLine($"Error getting latest nanoCLR version.");
147-
return ExitCode.E9005;
151+
// no specific version requested, get latest version available for download
152+
HttpResponseMessage response = await _httpClient.GetAsync($"{repoName}/?query=name:^WIN_DLL_nanoCLR version:^latest$");
153+
154+
responseBody = await response.Content.ReadAsStringAsync();
155+
156+
if (responseBody == "[]")
157+
{
158+
Console.WriteLine($"Error getting latest available nanoCLR package.");
159+
return ExitCode.E9005;
160+
}
148161
}
162+
else
163+
{
164+
// specific version requested, get details for that version
165+
HttpResponseMessage response = await _httpClient.GetAsync($"{repoName}/?query=name:^WIN_DLL_nanoCLR version:{targetVersion}");
149166

150-
var packageInfo = JsonSerializer.Deserialize<List<CloudsmithPackageInfo>>(responseBody);
167+
responseBody = await response.Content.ReadAsStringAsync();
168+
169+
if (responseBody == "[]")
170+
{
171+
Console.WriteLine($"Error getting package details for v{targetVersion}.");
172+
return ExitCode.E9005;
173+
}
174+
}
175+
176+
// parse the response
177+
packageInfo = JsonSerializer.Deserialize<List<CloudsmithPackageInfo>>(responseBody);
151178

152179
if (packageInfo.Count != 1)
153180
{
154-
Console.WriteLine($"Error parsing latest nanoCLR version.");
181+
Console.WriteLine($"Error parsing nanoCLR version from package details.");
155182
return ExitCode.E9005;
156183
}
157184
else
158185
{
159-
Version latestFwVersion = Version.Parse(packageInfo[0].Version);
186+
Version availableFwVersion = Version.Parse(packageInfo[0].Version);
160187

161-
if (latestFwVersion < version)
162-
{
163-
Console.WriteLine($"Current version {version} lower than available version {packageInfo[0].Version}");
164-
}
165-
else if (latestFwVersion > version
166-
|| (!string.IsNullOrEmpty(targetVersion)
167-
&& (Version.Parse(targetVersion) > Version.Parse(currentVersion))))
188+
// update if the version is different from the installed one (either the requested target version or the latest available in the repo)
189+
if ((!string.IsNullOrEmpty(targetVersion)
190+
&& (Version.Parse(targetVersion) != installedVersion))
191+
|| (availableFwVersion > installedVersion))
168192
{
169-
response = await _httpClient.GetAsync(packageInfo[0].DownloadUrl);
193+
HttpResponseMessage response = await _httpClient.GetAsync(packageInfo[0].DownloadUrl);
170194
response.EnsureSuccessStatusCode();
171195

172196
// need to unload the DLL before updating it
173197
hostBuilder.UnloadNanoClrDll();
174198

175-
await using var ms = await response.Content.ReadAsStreamAsync();
176-
await using var fs = File.OpenWrite(nanoClrDllLocation);
199+
await using Stream ms = await response.Content.ReadAsStreamAsync();
200+
await using FileStream fs = File.OpenWrite(nanoClrDllLocation);
177201

178202
ms.Seek(0, SeekOrigin.Begin);
179203
await ms.CopyToAsync(fs);
@@ -184,7 +208,7 @@ private static async Task<ExitCode> UpdateNanoCLRAsync(
184208
}
185209
else
186210
{
187-
Console.WriteLine($"Already at v{packageInfo[0].Version}");
211+
Console.WriteLine($"At v{packageInfo[0].Version}, skipping update");
188212
}
189213

190214
return ExitCode.OK;

‎targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ const char *nanoCLR_GetVersion()
182182

183183
const std::string_view str{buffer, result.out};
184184

185-
std::memcpy(pszVersion, buffer, result.size);
185+
std::memcpy(pszVersion, buffer, result.size + 1);
186186
}
187187

188188
return pszVersion;

0 commit comments

Comments
 (0)
Please sign in to comment.