Skip to content

Commit

Permalink
Merge pull request #488 from defold/dotnet-rc-fixes
Browse files Browse the repository at this point in the history
Updated dotnet support for DotNet 9 rc1
  • Loading branch information
JCash authored Sep 30, 2024
2 parents 0a35102 + 1492457 commit 3143811
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/debugsdk
/defoldsdk
/localserver
/platformsdk
*.class
!server/test-data/sdk/
server/test-data/sdk/*
Expand Down
1 change: 1 addition & 0 deletions server/docker/Dockerfile.base-env
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ RUN \

ENV NUGET_PACKAGES=/tmp/.nuget
ENV DOTNET_ROOT=/opt/dotnet
ENV DOTNET_CLI_HOME=${DOTNET_ROOT}
ENV DOTNET_VERSION_FILE=${DOTNET_ROOT}/dotnet_version
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1

Expand Down
4 changes: 3 additions & 1 deletion server/envs/generate_user_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ERROR_LOG=${LOG_DIRECTORY}/error.log
EXTENDER_SDK_LOCATION=${ENV_DIR}/../app/sdk

DOTNET_ROOT=${ENV_DIR}/../app/dotnet
DOTNET_CLI_HOME=${DOTNET_ROOT}
DOTNET_VERSION_FILE=${DOTNET_ROOT}/dotnet_version
NUGET_PACKAGES=${ENV_DIR}/../app/.nuget

Expand Down Expand Up @@ -49,11 +50,12 @@ echo "STDOUT_LOG=${STDOUT_LOG}" >> $ENV_DIR/user.env
echo "ERROR_LOG=${ERROR_LOG}" >> $ENV_DIR/user.env
echo "EXTENDER_SDK_LOCATION=${EXTENDER_SDK_LOCATION}" >> $ENV_DIR/user.env
echo "DOTNET_ROOT=${DOTNET_ROOT}" >> $ENV_DIR/user.env
echo "DOTNET_CLI_HOME=${DOTNET_CLI_HOME}" >> $ENV_DIR/user.env
echo "DOTNET_VERSION_FILE=${DOTNET_VERSION_FILE}" >> $ENV_DIR/user.env
echo "NUGET_PACKAGES=${NUGET_PACKAGES}" >> $ENV_DIR/user.env
# Added 1.4.9
echo "ZIG_PATH_0_11=${ZIG_PATH_0_11}" >> $ENV_DIR/user.env

echo "PATH=${APPENDED_PATH}" >> $ENV_DIR/user.env

echo "Generation completed."
echo "Generation completed."
6 changes: 1 addition & 5 deletions server/src/main/java/com/defold/extender/Extender.java
Original file line number Diff line number Diff line change
Expand Up @@ -1377,11 +1377,7 @@ private List<File> linkEngine(List<String> symbols, Map<String, Object> linkCont
context.put("engineLibs", patchLibs((List<String>) context.get("engineLibs")));

if (this.needsCSLibraries) {
List<String> linkFlags = (List<String>)context.getOrDefault("linkFlags", new ArrayList<String>());
for (File dependency : CSharpBuilder.getStaticDependencies(platform)) {
linkFlags.add(dependency.getAbsolutePath());
}
context.put("linkFlags", linkFlags);
CSharpBuilder.updateContext(platform, context);
}

List<String> commands = platformConfig.linkCmds; // Used by e.g. the Switch platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class CSharpBuilder {
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpBuilder.class);

private static final String DOTNET_ROOT = System.getenv("DOTNET_ROOT");
private static final String DOTNET_CLI_HOME = System.getenv("DOTNET_CLI_HOME");
private static final String DOTNET_VERSION_FILE = System.getenv("DOTNET_VERSION_FILE");
private static final String NUGET_PACKAGES = System.getenv("NUGET_PACKAGES");

Expand Down Expand Up @@ -57,7 +58,7 @@ public CSharpBuilder(ProcessExecutor processExecutor, TemplateExecutor templateE
this.template = ExtenderUtil.readContentFromResource(csProjectResource);
this.context = context;

LOGGER.info(String.format("DOTNET_ROOT: %s", DOTNET_ROOT));
LOGGER.info(String.format("DOTNET_CLI_HOME: %s", DOTNET_CLI_HOME));
LOGGER.info(String.format("NUGET_PACKAGES: %s", NUGET_PACKAGES));
}

Expand Down Expand Up @@ -132,8 +133,12 @@ private boolean isWindows(String platform) {

private File runDotnet(File project, String platform) throws IOException, InterruptedException, ExtenderException {

if (DOTNET_CLI_HOME == null) {
throw new ExtenderException("DOTNET_CLI_HOME is not setup correctly! Cannot build C#.");
}

String csplatform = convertPlatform(this.platform);
String cmd = String.format("%s/dotnet publish --nologo -c Release -r %s ", DOTNET_ROOT, csplatform);
String cmd = String.format("%s/dotnet publish --nologo -c Release -r %s ", DOTNET_CLI_HOME, csplatform);
cmd += project.getAbsolutePath();

List<String> commands = new ArrayList<>();
Expand Down Expand Up @@ -166,38 +171,53 @@ public List<File> build() throws IOException, InterruptedException, ExtenderExce
return out;
}

public static List<File> getStaticDependencies(String platform) throws IOException {
private static Path getNativePath(String platform) throws IOException {
String csplatform = convertPlatform(platform);
String dotnetVersion = readFile(DOTNET_VERSION_FILE).trim();
return Paths.get(NUGET_PACKAGES, String.format("microsoft.netcore.app.runtime.nativeaot.%s/%s/runtimes/%s/native", csplatform, dotnetVersion, csplatform));
}

Path aotBase = Paths.get(NUGET_PACKAGES, String.format("microsoft.netcore.app.runtime.nativeaot.%s/%s/runtimes/%s/native", csplatform, dotnetVersion, csplatform));
private static void addLibFlags(String platform, List<String> linkFlags) throws IOException {
Path aotBase = getNativePath(platform);

linkFlags.add(Paths.get(aotBase.toString(), "libbootstrapperdll.o").toString());

// Note: These libraries are specified with full paths, or the linker will link against the dynamic libraries.
// We want to avoid that hassle for now. Let's do that in a step two.

// TODO: Do we need a way to toggle these behaviors on/off?
linkFlags.add(Paths.get(aotBase.toString(), "libRuntime.WorkstationGC.a").toString());
linkFlags.add(Paths.get(aotBase.toString(), "libeventpipe-enabled.a").toString());
linkFlags.add(Paths.get(aotBase.toString(), "libstandalonegc-enabled.a").toString());

linkFlags.add(Paths.get(aotBase.toString(), "libSystem.Native.a").toString());
linkFlags.add(Paths.get(aotBase.toString(), "libSystem.IO.Compression.Native.a").toString());
linkFlags.add(Paths.get(aotBase.toString(), "libSystem.Globalization.Native.a").toString());

List<File> out = new ArrayList<>();
if (platform.equals("arm64-osx") || platform.equals("x86_64-osx"))
{
out.add(Paths.get(aotBase.toString(), "libbootstrapperdll.o").toFile());
out.add(Paths.get(aotBase.toString(), "libRuntime.WorkstationGC.a").toFile());
out.add(Paths.get(aotBase.toString(), "libeventpipe-enabled.a").toFile());
out.add(Paths.get(aotBase.toString(), "libstandalonegc-enabled.a").toFile());
out.add(Paths.get(aotBase.toString(), "libSystem.Native.a").toFile());
out.add(Paths.get(aotBase.toString(), "libSystem.IO.Compression.Native.a").toFile());
out.add(Paths.get(aotBase.toString(), "libSystem.Globalization.Native.a").toFile());
linkFlags.add(Paths.get(aotBase.toString(), "libRuntime.VxsortEnabled.a").toString());

}
else if (platform.equals("arm64-ios") || platform.equals("x86_64-ios"))
{
out.add(Paths.get(aotBase.toString(), "libbootstrapperdll.o").toFile());
out.add(Paths.get(aotBase.toString(), "libRuntime.WorkstationGC.a").toFile());
out.add(Paths.get(aotBase.toString(), "libeventpipe-disabled.a").toFile());
out.add(Paths.get(aotBase.toString(), "libstandalonegc-disabled.a").toFile());
out.add(Paths.get(aotBase.toString(), "libstdc++compat.a").toFile());
out.add(Paths.get(aotBase.toString(), "libSystem.Native.a").toFile());
out.add(Paths.get(aotBase.toString(), "libSystem.Globalization.Native.a").toFile());
out.add(Paths.get(aotBase.toString(), "libSystem.IO.Compression.Native.a").toFile());
out.add(Paths.get(aotBase.toString(), "libSystem.Net.Security.Native.a").toFile());
out.add(Paths.get(aotBase.toString(), "libSystem.Security.Cryptography.Native.Apple.a").toFile());
out.add(Paths.get(aotBase.toString(), "libicucore.a").toFile());
linkFlags.add(Paths.get(aotBase.toString(), "libstdc++compat.a").toString());
linkFlags.add(Paths.get(aotBase.toString(), "libSystem.Net.Security.Native.a").toString());
linkFlags.add(Paths.get(aotBase.toString(), "libSystem.Security.Cryptography.Native.Apple.a").toString());
linkFlags.add("-licucore");
}
}

return out;
public static void updateContext(String platform, Map<String, Object> context) throws IOException {
Path aotBase = getNativePath(platform);

List<String> libPaths = (List<String>)context.getOrDefault("libPaths", new ArrayList<String>());
libPaths.add(aotBase.toString()); // -L/path/to/aot
context.put("libPaths", libPaths);

List<String> linkFlags = (List<String>)context.getOrDefault("linkFlags", new ArrayList<String>());
CSharpBuilder.addLibFlags(platform, linkFlags);
context.put("linkFlags", linkFlags);
}

}

0 comments on commit 3143811

Please sign in to comment.