Skip to content

Commit 85ecba3

Browse files
committed
Solve all issues in cs loader.
1 parent 9c063c8 commit 85ecba3

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

source/loaders/cs_loader/netcore/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,28 @@ if(OPTION_BUILD_GUIX)
6363

6464
# Build without internet access
6565
add_custom_target(${target} ALL
66+
COMMAND ${CMAKE_COMMAND} -E $<IF:$<VERSION_LESS:CMAKE_VERSION,3.17>,remove,rm> ${PROJECT_OUTPUT_DIR}/CSLoader.dll
6667
COMMAND ${DOTNET_COMMAND} restore ${DOTNET_CORE_PATH_SOURCE} ${DOTNET_ADDITIONAL_PACKAGES_SOURCE} ${DOTNET_SOURCE} ${CMAKE_CURRENT_SOURCE_DIR}/source/project.csproj
6768
COMMAND ${DOTNET_COMMAND} publish ${DOTNET_CORE_PATH_SOURCE} ${DOTNET_ADDITIONAL_PACKAGES_SOURCE} ${DOTNET_SOURCE} ${CMAKE_CURRENT_SOURCE_DIR}/source/project.csproj -o ${CMAKE_BINARY_DIR}
6869
)
6970
else()
7071
if(DOTNET_VERSION VERSION_EQUAL "2.0" OR DOTNET_VERSION VERSION_GREATER "2.0")
7172
add_custom_target(${target} ALL
73+
COMMAND ${CMAKE_COMMAND} -E $<IF:$<VERSION_LESS:CMAKE_VERSION,3.17>,remove,rm> ${PROJECT_OUTPUT_DIR}/CSLoader.dll
7274
COMMAND ${DOTNET_ENV_VAR} ${DOTNET_COMMAND} restore ${CMAKE_CURRENT_SOURCE_DIR}/source/project.csproj
7375
COMMAND ${DOTNET_ENV_VAR} ${DOTNET_COMMAND} publish ${CMAKE_CURRENT_SOURCE_DIR}/source/project.csproj -o ${PROJECT_OUTPUT_DIR}
7476
)
7577
else()
7678
if(DOTNET_MIGRATE)
7779
add_custom_target(${target} ALL
80+
COMMAND ${CMAKE_COMMAND} -E $<IF:$<VERSION_LESS:CMAKE_VERSION,3.17>,remove,rm> ${PROJECT_OUTPUT_DIR}/CSLoader.dll
7881
COMMAND ${DOTNET_ENV_VAR} ${DOTNET_COMMAND} migrate ${CMAKE_CURRENT_SOURCE_DIR}/source/project.json
7982
COMMAND ${DOTNET_ENV_VAR} ${DOTNET_COMMAND} restore ${CMAKE_CURRENT_SOURCE_DIR}/source/project.json
8083
COMMAND ${DOTNET_ENV_VAR} ${DOTNET_COMMAND} publish ${CMAKE_CURRENT_SOURCE_DIR}/source/project.json -o ${PROJECT_OUTPUT_DIR}
8184
)
8285
else()
8386
add_custom_target(${target} ALL
87+
COMMAND ${CMAKE_COMMAND} -E $<IF:$<VERSION_LESS:CMAKE_VERSION,3.17>,remove,rm> ${PROJECT_OUTPUT_DIR}/CSLoader.dll
8488
COMMAND ${DOTNET_ENV_VAR} ${DOTNET_COMMAND} restore ${CMAKE_CURRENT_SOURCE_DIR}/source/project.json
8589
COMMAND ${DOTNET_ENV_VAR} ${DOTNET_COMMAND} publish ${CMAKE_CURRENT_SOURCE_DIR}/source/project.json -o ${PROJECT_OUTPUT_DIR}
8690
)

source/loaders/cs_loader/netcore/source/MetacallEntryPoint.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.CodeAnalysis.CSharp;
88
using System.IO;
99
using Microsoft.CodeAnalysis.Emit;
10-
using System.Runtime.Loader;
1110
using System.Runtime.InteropServices;
1211
using static CSLoader.MetacallDef;
1312
using System.Collections.Immutable;

source/loaders/cs_loader/netcore/source/Providers/LoaderBase.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,24 @@ public bool LoadFromFileFunctions(string[] files)
133133
return LoadFromSourceFunctions(sources.ToArray());
134134
}
135135

136-
private void PrintDiagnostics(ImmutableArray<Diagnostic> diagnostics)
136+
private int PrintDiagnostics(ImmutableArray<Diagnostic> diagnostics)
137137
{
138-
IEnumerable<Diagnostic> failures = diagnostics.Where(diagnostic =>
139-
diagnostic.IsWarningAsError ||
140-
diagnostic.Severity == DiagnosticSeverity.Error);
138+
int errorCount = 0;
141139

142-
foreach (Diagnostic diagnostic in failures)
140+
foreach (Diagnostic diagnostic in diagnostics)
143141
{
144-
this.log.Error("CSLoader compilation error: " + diagnostic.GetMessage());
142+
if (diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error)
143+
{
144+
this.log.Error("CSLoader compilation error: " + diagnostic.ToString());
145+
++errorCount;
146+
}
147+
else
148+
{
149+
this.log.Error("CSLoader compilation warning: " + diagnostic.ToString());
150+
}
145151
}
152+
153+
return errorCount;
146154
}
147155

148156
public bool LoadFromSourceFunctions(string[] source)
@@ -185,21 +193,13 @@ public bool LoadFromSourceFunctions(string[] source)
185193
)
186194
);
187195

188-
ImmutableArray<Diagnostic> compilationErrors = compilation.GetDiagnostics();
189-
190-
if (compilationErrors.Count() > 0)
196+
if (PrintDiagnostics(compilation.GetDiagnostics()) > 0)
191197
{
192-
PrintDiagnostics(compilationErrors);
193-
194198
return false;
195199
}
196200

197-
ImmutableArray<Diagnostic> declarationErrors = compilation.GetDeclarationDiagnostics();
198-
199-
if (compilationErrors.Count() > 0)
201+
if (PrintDiagnostics(compilation.GetDeclarationDiagnostics()) > 0)
200202
{
201-
PrintDiagnostics(declarationErrors);
202-
203203
return false;
204204
}
205205

source/tests/metacall_cs_test/source/metacall_cs_test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ TEST_F(metacall_cs_test, Concat)
8686
metacall_value_destroy(ret);
8787
}
8888

89-
#if !defined(__ADDRESS_SANITIZER__) /* TODO: C# Loader leaks when fails to load a script */
9089
TEST_F(metacall_cs_test, Fail)
9190
{
9291
/* This is a Python script on purpose, in order to test C# when it fails */
@@ -99,7 +98,6 @@ TEST_F(metacall_cs_test, Fail)
9998

10099
EXPECT_EQ((int)1, (int)metacall_load_from_memory("cs", buffer, sizeof(buffer), NULL));
101100
}
102-
#endif
103101

104102
TEST_F(metacall_cs_test, FailRelativePath)
105103
{

source/tests/sanitizer/lsan.supp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ leak:libruby*
3434
#
3535
leak:libcoreclr*
3636
leak:libicuuc*
37+
# TODO: Implement assembly unloading with loader context
38+
leak:System.Private.CoreLib.dll
3739
#
3840
# Rust
3941
#

0 commit comments

Comments
 (0)