bpo-41039: Simplify python3.dll build (GH-20989)

Use linker comment #pragma and preprocessor for re-exporting stable
API functions and variables.

Module definition file, custom build targets and entry point code
become unnecessary and can be removed.

This change also fixes missing _PyErr_BadInternalCall export on x86.
This commit is contained in:
Nikita Nemkin 2020-06-24 00:33:23 +05:00 committed by GitHub
parent 4efc3360c9
commit 2c6e4e91c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 817 additions and 892 deletions

View file

@ -88,31 +88,16 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<_Machine>X86</_Machine>
<_Machine Condition="$(Platform) == 'x64'">X64</_Machine>
<_Machine Condition="$(Platform) == 'ARM'">ARM</_Machine>
<_Machine Condition="$(Platform) == 'ARM64'">ARM64</_Machine>
<ExtensionsToDeleteOnClean>$(ExtensionsToDeleteOnClean);$(IntDir)python3_d.def;$(IntDir)python3stub.def</ExtensionsToDeleteOnClean>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>PYTHON_DLL_NAME="$(PyDllName)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BufferSecurityCheck>false</BufferSecurityCheck>
</ClCompile>
<Link>
<AdditionalDependencies>$(OutDir)$(TargetName)stub.lib</AdditionalDependencies>
<ModuleDefinitionFile Condition="$(Configuration) != 'Debug'">$(PySourcePath)PC\python3.def</ModuleDefinitionFile>
<ModuleDefinitionFile Condition="$(Configuration) == 'Debug'">$(IntDir)python3_d.def</ModuleDefinitionFile>
<EntryPointSymbol>DllMain</EntryPointSymbol>
<NoEntryPoint>true</NoEntryPoint>
</Link>
<PreLinkEvent>
<Command>lib /nologo /def:"$(IntDir)python3stub.def" /out:"$(OutDir)$(TargetName)stub.lib" /MACHINE:$(_Machine)</Command>
<Message>Rebuilding $(TargetName)stub.lib</Message>
<Outputs>$(OutDir)$(TargetName)stub.lib</Outputs>
</PreLinkEvent>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="..\PC\python3.def" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\PC\python3dll.c" />
</ItemGroup>
@ -122,62 +107,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<Target Name="BuildPython3_dDef" BeforeTargets="BuildStubDef" Condition="$(Configuration) == 'Debug'">
<ItemGroup>
<_DefLines Remove="@(_DefLines)" />
<_Lines Remove="@(_Lines)" />
<_OriginalLines Remove="@(_OriginalLines)" />
</ItemGroup>
<ReadLinesFromFile File="..\PC\python3.def">
<Output TaskParameter="Lines" ItemName="_DefLines" />
</ReadLinesFromFile>
<ReadLinesFromFile File="$(IntDir)python3_d.def" Condition="Exists('$(IntDir)python3_d.def')">
<Output TaskParameter="Lines" ItemName="_OriginalLines" />
</ReadLinesFromFile>
<PropertyGroup>
<_Pattern1>(=python$(MajorVersionNumber)$(MinorVersionNumber))\.</_Pattern1>
<_Sub1>$1_d.</_Sub1>
<_Pattern2>"python3"</_Pattern2>
<_Sub2>"python3_d"</_Sub2>
</PropertyGroup>
<ItemGroup>
<_Lines Include="@(_DefLines)">
<New>$([System.Text.RegularExpressions.Regex]::Replace($([System.Text.RegularExpressions.Regex]::Replace(`%(Identity)`, `$(_Pattern1)`, `$(_Sub1)`)), `$(_Pattern2)`, `$(_Sub2)`))</New>
</_Lines>
</ItemGroup>
<MakeDir Directories="$(IntDir)" />
<Message Text="Updating python3_d.def" Condition="@(_Lines->'%(New)') != @(_OriginalLines)" Importance="high" />
<WriteLinesToFile File="$(IntDir)python3_d.def" Lines="@(_Lines->'%(New)')" Overwrite="true"
Condition="@(_Lines->'%(New)') != @(_OriginalLines)" />
</Target>
<Target Name="BuildStubDef" BeforeTargets="PreLinkEvent">
<ItemGroup>
<_DefLines Remove="@(_DefLines)" />
<_Lines Remove="@(_Lines)" />
<_OriginalLines Remove="@(_OriginalLines)" />
</ItemGroup>
<ReadLinesFromFile File="..\PC\python3.def">
<Output TaskParameter="Lines" ItemName="_DefLines" />
</ReadLinesFromFile>
<ReadLinesFromFile File="$(IntDir)python3stub.def" Condition="Exists('$(IntDir)python3stub.def')">
<Output TaskParameter="Lines" ItemName="_OriginalLines" />
</ReadLinesFromFile>
<PropertyGroup>
<_Pattern>^[\w.]+=.+?\.([^ ]+).*$</_Pattern>
<_Sub>$1</_Sub>
</PropertyGroup>
<ItemGroup>
<_Lines Include="EXPORTS" />
<_Symbols Include="@(_DefLines)" Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(`%(Identity)`, `$(_Pattern)`))">
<Symbol>$([System.Text.RegularExpressions.Regex]::Replace(`%(Identity)`, `$(_Pattern)`, `$(_Sub)`))</Symbol>
</_Symbols>
<_Lines Include="@(_Symbols->'%(Symbol)')" />
</ItemGroup>
<MakeDir Directories="$(IntDir)" />
<Message Text="Updating python3stub.def" Condition="@(_Lines) != @(_OriginalLines)" Importance="high" />
<WriteLinesToFile File="$(IntDir)python3stub.def" Lines="@(_Lines)" Overwrite="true"
Condition="@(_Lines) != @(_OriginalLines)" />
</Target>
</Project>

View file

@ -10,11 +10,6 @@
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="..\PC\python3.def">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\PC\python3dll.c">
<Filter>Source Files</Filter>