Skip to content

Commit df1c224

Browse files
dmitriysefilmor
authored andcommitted
Added CoreCLR 2.0 build target. Compile issues fixed. (#519)
* Full featured xplat build. * NetCoreApp 2.0 target added, compile issues fixed, CI system improved. * .Net 45 TargetingPack System.XML.dll naming fix. (For xplat linux build). * Setup.py --xplat option refactored. Travis-ci build matrix extended. * AppVeyor matrix extended, xplat build added. * appveyor.yml yaml syntax fix. * NUnit dependency upgraded to 3.7. Changelog improved. * EmbeddingTest fixes, and stubs. * Fix for importing numpy and other python modules with native parts. * Changelog improved. * Build order improvement. * NetCoreApp 2.0 fix. EmitCalli does not supports cdecl. Falling-back to a slow Marshal-based solution. + x86 fix. * All finalizers are disabled until valid implementation. Helps to avoid non relevant CI build faults. * Mono builds now can be build on Windows. DEBUG;TRACE fix for the case VS + non empty PYTHONNET_DEFINE_CONSTANTS * Python.Runtime.dll now targets NetStandard2.0 inplace of NetCoreApp 2.0 * Wrong NETSTANDARD/NETCOREAPP define constant change. * Typo fix.
1 parent 4b381bf commit df1c224

24 files changed

+223
-61
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ install:
169169
script:
170170
- python -m pytest
171171
- mono $NUNIT_PATH src/embed_tests/bin/Python.EmbeddingTest.dll
172+
- if [[ $BUILD_OPTS == --xplat ]]; then dotnet src/embed_tests/bin/netcoreapp2.0_publish/Python.EmbeddingTest.dll; fi
172173

173174
after_script:
174175
# Uncomment if need to geninterop, ie. py37 final

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
88
## [unreleased][]
99

1010
### Added
11+
- Added support for embedding python into dotnet core 2.0 (NetStandard 2.0)
1112
- Added new build system (pythonnet.15.sln) based on dotnetcore-sdk/xplat(crossplatform msbuild).
1213
Currently there two side-by-side build systems that produces the same output (net40) from the same sources.
1314
After a some transition time, current (mono/ msbuild 14.0) build system will be removed.

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ init:
4343
install:
4444
- pip install --upgrade -r requirements.txt --quiet
4545
- choco install vswhere -y
46+
- cmd: curl -O https://download.microsoft.com/download/5/6/B/56BFEF92-9045-4414-970C-AB31E0FC07EC/dotnet-runtime-2.0.0-win-x86.exe
47+
- cmd: dotnet-runtime-2.0.0-win-x86.exe /install /quiet /norestart /log install.log
4648

4749
# Install OpenCover. Can't put on `packages.config`, not Mono compatible
4850
- .\tools\nuget\nuget.exe install OpenCover -OutputDirectory packages -Verbosity quiet

ci/appveyor_run_tests.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ if ($CS_STATUS -ne 0) {
4444
Write-Host "Embedded tests failed" -ForegroundColor "Red"
4545
}
4646

47+
if ($env:BUILD_OPTS -eq "--xplat"){
48+
if ($env:PLATFORM -eq "x64") {
49+
$DOTNET_CMD = "dotnet"
50+
}
51+
else{
52+
$DOTNET_CMD = "c:\Program Files (x86)\dotnet\dotnet"
53+
}
54+
55+
# Run Embedded tests for netcoreapp2.0 (OpenCover currently does not supports dotnet core)
56+
Write-Host ("Starting embedded tests for netcoreapp2.0") -ForegroundColor "Green"
57+
&$DOTNET_CMD .\src\embed_tests\bin\netcoreapp2.0_publish\Python.EmbeddingTest.dll
58+
$CS_STATUS = $LastExitCode
59+
if ($CS_STATUS -ne 0) {
60+
Write-Host "Embedded tests for netcoreapp2.0 failed" -ForegroundColor "Red"
61+
}
62+
}
63+
4764
# Set exit code to fail if either Python or Embedded tests failed
4865
if ($PYTHON_STATUS -ne 0 -or $CS_STATUS -ne 0) {
4966
Write-Host "Tests failed" -ForegroundColor "Red"

pythonnet.15.sln

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio 15
33
VisualStudioVersion = 15.0.26730.3
44
MinimumVisualStudioVersion = 10.0.40219.1
5-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Runtime.15", "src\runtime\Python.Runtime.15.csproj", "{2759F4FF-716B-4828-916F-50FA86613DFC}"
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Runtime.15", "src/runtime/Python.Runtime.15.csproj", "{2759F4FF-716B-4828-916F-50FA86613DFC}"
66
EndProject
7-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.EmbeddingTest.15", "src\embed_tests\Python.EmbeddingTest.15.csproj", "{66B8D01A-9906-452A-B09E-BF75EA76468F}"
7+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.EmbeddingTest.15", "src/embed_tests/Python.EmbeddingTest.15.csproj", "{66B8D01A-9906-452A-B09E-BF75EA76468F}"
88
EndProject
9-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "clrmodule.15", "src\clrmodule\clrmodule.15.csproj", "{E08678D4-9A52-4AD5-B63D-8EBC7399981B}"
9+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "clrmodule.15", "src/clrmodule/clrmodule.15.csproj", "{E08678D4-9A52-4AD5-B63D-8EBC7399981B}"
1010
EndProject
11-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console.15", "src\console\Console.15.csproj", "{CDAD305F-8E72-492C-A314-64CF58D472A0}"
11+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console.15", "src/console/Console.15.csproj", "{CDAD305F-8E72-492C-A314-64CF58D472A0}"
1212
EndProject
13-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Test.15", "src\testing\Python.Test.15.csproj", "{F94B547A-E97E-4500-8D53-B4D64D076E5F}"
13+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.Test.15", "src/testing/Python.Test.15.csproj", "{F94B547A-E97E-4500-8D53-B4D64D076E5F}"
1414
EndProject
1515
Global
1616
GlobalSection(SolutionConfigurationPlatforms) = preSolution

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ def build_extension(self, ext):
257257

258258
subprocess.check_call(" ".join(cmd + ["/t:Clean"]), shell=use_shell)
259259
subprocess.check_call(" ".join(cmd + ["/t:Build"]), shell=use_shell)
260+
if DEVTOOLS == "MsDev15" or DEVTOOLS == "dotnet":
261+
subprocess.check_call(" ".join(cmd + ['"/t:Console_15:publish;Python_EmbeddingTest_15:publish"', "/p:TargetFramework=netcoreapp2.0"]), shell=use_shell)
260262

261263
if DEVTOOLS == "Mono" or DEVTOOLS == "dotnet":
262264
self._build_monoclr()

src/clrmodule/clrmodule.15.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<NoWarn>1591</NoWarn>
2323
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
2424
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
25+
<PythonBuildDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)\$(TargetFramework)\</PythonBuildDir>
2526
<LangVersion>6</LangVersion>
2627
<ErrorReport>prompt</ErrorReport>
2728
<CustomDefineConstants Condition="'$(CustomDefineConstants)' == ''">$(PYTHONNET_DEFINE_CONSTANTS)</CustomDefineConstants>

src/console/Console.15.csproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
33
<PropertyGroup>
4-
<TargetFrameworks>net40</TargetFrameworks>
4+
<TargetFrameworks>net40;netcoreapp2.0</TargetFrameworks>
55
<Platforms>x64;x86</Platforms>
66
<Configurations>DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3</Configurations>
77
<OutputType>Exe</OutputType>
@@ -15,12 +15,14 @@
1515
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1616
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
1717
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
18-
<DocumentationFile>bin\nPython.xml</DocumentationFile>
1918
<OutputPath>bin\</OutputPath>
20-
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
19+
<AppendTargetFrameworkToOutputPath Condition="'$(TargetFramework)'=='net40'">false</AppendTargetFrameworkToOutputPath>
20+
<DocumentationFile Condition="'$(TargetFramework)'=='net40'">$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
21+
<DocumentationFile Condition="'$(TargetFramework)'!='net40'">$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
2122
<NoWarn>1591</NoWarn>
2223
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
2324
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
25+
<PublishDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)\$(TargetFramework)\</PublishDir>
2426
<LangVersion>6</LangVersion>
2527
<ApplicationIcon>python-clear.ico</ApplicationIcon>
2628
<ErrorReport>prompt</ErrorReport>
@@ -89,7 +91,7 @@
8991
</ItemGroup>
9092
<ItemGroup>
9193
<Content Include="python-clear.ico" />
92-
<EmbeddedResource Include="$(PythonBuildDir)\Python.Runtime.dll">
94+
<EmbeddedResource Condition="'$(TargetFramework)'=='net40'" Include="$(PythonBuildDir)\Python.Runtime.dll">
9395
<LogicalName>Python.Runtime.dll</LogicalName>
9496
</EmbeddedResource>
9597
</ItemGroup>
@@ -100,6 +102,6 @@
100102
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
101103

102104
<Target Name="AfterBuild">
103-
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(PythonBuildDir)" />
105+
<Copy Condition="'$(TargetFramework)'=='net40'" SourceFiles="$(TargetPath)" DestinationFolder="$(PythonBuildDir)" />
104106
</Target>
105107
</Project>

src/console/pythonconsole.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@ namespace Python.Runtime
1616
/// </remarks>
1717
public sealed class PythonConsole
1818
{
19+
#if NET40
1920
private static AssemblyLoader assemblyLoader = new AssemblyLoader();
20-
21+
#endif
2122
private PythonConsole()
2223
{
2324
}
2425

2526
[STAThread]
2627
public static int Main(string[] args)
2728
{
29+
// Only net40 is capable to safely inject python.runtime.dll into resources.
30+
#if NET40
2831
// reference the static assemblyLoader to stop it being optimized away
2932
AssemblyLoader a = assemblyLoader;
30-
33+
#endif
3134
string[] cmd = Environment.GetCommandLineArgs();
3235
PythonEngine.Initialize();
3336

@@ -37,6 +40,7 @@ public static int Main(string[] args)
3740
return i;
3841
}
3942

43+
#if NET40
4044
// Register a callback function to load embedded assemblies.
4145
// (Python.Runtime.dll is included as a resource)
4246
private sealed class AssemblyLoader
@@ -73,5 +77,6 @@ public AssemblyLoader()
7377
};
7478
}
7579
}
80+
#endif
7681
}
7782
}

src/embed_tests/Program.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
using NUnit.Common;
4+
5+
using NUnitLite;
6+
7+
namespace Python.EmbeddingTest
8+
{
9+
public class Program
10+
{
11+
public static int Main(string[] args)
12+
{
13+
return new AutoRun(typeof(Program).Assembly).Execute(
14+
args,
15+
new ExtendedTextWrapper(Console.Out),
16+
Console.In);
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy