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
22 changes: 22 additions & 0 deletions .github/workflows/build_nuget.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
name: Build Nuget

on:
push:
paths:
- unity/upms/**
- unity/test/**
- unity/native/**
- unity/cli/**
- unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.cpp
- unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.h
- unreal/Puerts/Source/JsEnv/Private/WebSocketImpl.cpp
- unreal/Puerts/Source/JsEnv/Private/PromiseRejectCallback.hpp
- .github/workflows/build_nuget.yml
pull_request:
paths:
- unity/upms/**
- unity/test/**
- unity/native/**
- unity/cli/**
- unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.cpp
- unreal/Puerts/Source/JsEnv/Private/V8InspectorImpl.h
- unreal/Puerts/Source/JsEnv/Private/WebSocketImpl.cpp
- unreal/Puerts/Source/JsEnv/Private/PromiseRejectCallback.hpp
- .github/workflows/build_nuget.yml
workflow_dispatch:
inputs:
publish:
Expand Down
2 changes: 1 addition & 1 deletion unity/nuget/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<DefineConstants>PUERTS_GENERAL;DISABLE_AUTO_REGISTER;PUERTS_REFLECT_ALL_EXTENSION</DefineConstants>
<DefineConstants>PUERTS_GENERAL;DISABLE_AUTO_REGISTER;PUERTS_REFLECT_ALL_EXTENSION;PUERTS_NUGET</DefineConstants>

<NoWarn>NU5128</NoWarn>

Expand Down
62 changes: 61 additions & 1 deletion unity/upms/python/Runtime/Src/Backends/BackendPython.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

using System;

#if PUERTS_NUGET
using System.Runtime.InteropServices;
#endif

namespace Puerts
{
public class BackendPython : Backend
Expand All @@ -28,7 +32,11 @@ public override int GetApiVersion()

public override IntPtr CreateEnvRef()
{
envRef = PapiPythonNative.CreatePythonPapiEnvRef();
#if PUERTS_NUGET
var pythonPrefix = System.IO.Path.Combine(AppContext.BaseDirectory, "runtimes", GetRuntimeIdentifier(), "native");
PapiPythonNative.InitPythonByHome(pythonPrefix);
#endif
envRef = PapiPythonNative.CreatePythonPapiEnvRef();
return envRef;
}

Expand Down Expand Up @@ -238,5 +246,57 @@ def generic(cs_type, *args):
sys.meta_path.append(PesapiFinder())
''')");
}
#if PUERTS_NUGET
private static string GetRuntimeIdentifier()
{

string os;
#if NET5_0_OR_GREATER
os = OperatingSystem.IsWindows() ? "win" :
OperatingSystem.IsLinux() ? "linux" :
OperatingSystem.IsMacOS() ? "osx" :
throw new PlatformNotSupportedException("Unsupported OS platform");
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
os = "win";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
os = "linux";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
os = "osx";
}
else
{
throw new PlatformNotSupportedException("Unsupported OS platform");
}
#endif

var arch = RuntimeInformation.OSArchitecture switch
{
Architecture.X64 => "x64",
Architecture.X86 => "x86",
Architecture.Arm => throw new PlatformNotSupportedException("Unsupported architecture"),
Architecture.Arm64 => "arm64",
#if NET5_0_OR_GREATER
Architecture.Wasm => throw new PlatformNotSupportedException("Unsupported architecture"),
#endif
#if NET6_0_OR_GREATER
Architecture.S390x => throw new PlatformNotSupportedException("Unsupported architecture"),
#endif
#if NET7_0_OR_GREATER
Architecture.LoongArch64 => throw new PlatformNotSupportedException("Unsupported architecture"),
Architecture.Armv6 =>throw new PlatformNotSupportedException("Unsupported architecture"),
Architecture.Ppc64le => throw new PlatformNotSupportedException("Unsupported architecture"),
#endif
_ => throw new PlatformNotSupportedException("Unsupported architecture")
};

return $"{os}-{arch}";
}
#endif
}
}
Loading