Skip to content

Commit

Permalink
THRIFT-5796 Indicate target environment via #if check
Browse files Browse the repository at this point in the history
Client: netstd
Patch: Jens Geyer
  • Loading branch information
Jens-G committed Jul 18, 2024
1 parent 3caf963 commit 97abc68
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions compiler/cpp/src/thrift/generate/t_netstd_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ void t_netstd_generator::reset_indent() {

void t_netstd_generator::pragmas_and_directives(ostream& out)
{
if( target_net_version >= 8) {
out << "// targeting net 8" << '\n';
out << "#if( !NET8_0_OR_GREATER)" << '\n';
} else if( target_net_version >= 6) {
out << "// targeting net 6" << '\n';
out << "#if( NET8_0_OR_GREATER || !NET6_0_OR_GREATER)" << '\n';
} else {
out << "// targeting netstandard 2.x" << '\n';
out << "#if(! NETSTANDARD2_0_OR_GREATER)" << '\n';
}
out << "#error Unexpected target platform. See 'thrift --help' for details." << '\n';
out << "#endif" << '\n';
out << '\n';

if( target_net_version >= 6) {
out << "// Thrift code generated for net" << target_net_version << '\n';
out << "#nullable enable // requires C# 8.0" << '\n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@
<Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./Thrift5382.thrift" />
<Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./Thrift5795.thrift" />
<!-- special options (see ticket) -->
<!-- wil be reacivated later
<Exec Command="$(PathToThrift) -gen netstd -r ./Thrift5794-netstd.thrift" />
<Exec Command="$(PathToThrift) -gen netstd:net6 -r ./Thrift5794-net6.thrift" />
-->
<Exec Command="$(PathToThrift) -gen netstd:net8 -r ./Thrift5794-net8.thrift" />
</Target>

Expand Down
6 changes: 3 additions & 3 deletions tutorial/netstd/Interfaces/Interfaces.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="where thrift" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="PathToThrift" />
</Exec>
<Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../tutorial.thrift" />
<Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../tutorial.thrift" />
<Exec Condition="Exists('./../../../compiler/cpp/thrift')" Command="./../../../compiler/cpp/thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../tutorial.thrift" />
<Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../tutorial.thrift" />
<Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../tutorial.thrift" />
<Exec Condition="Exists('./../../../compiler/cpp/thrift')" Command="./../../../compiler/cpp/thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../tutorial.thrift" />
</Target>
</Project>

0 comments on commit 97abc68

Please sign in to comment.