Skip to content

fix: Adjust platform detection logic in Stride.Core.targets file - #3344

Open
Jklawreszuk wants to merge 3 commits into
stride3d:masterfrom
Jklawreszuk:stride-platform
Open

fix: Adjust platform detection logic in Stride.Core.targets file#3344
Jklawreszuk wants to merge 3 commits into
stride3d:masterfrom
Jklawreszuk:stride-platform

Conversation

@Jklawreszuk

Copy link
Copy Markdown
Collaborator

PR Details

Temporary fix for Linux. It brings platform detection logic from Stride.Platform.props, so It makes setting StridePlatform msbuild variable fully optional.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

@ds5678 ds5678 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix for Linux

What is broken? Is there a GitHub issue about the problem?

Temporary fix

Why temporary?

<StridePlatform Condition="'$(StridePlatform)' == '' And '$(TargetPlatformIdentifier)' == 'iOS'">iOS</StridePlatform>
<StridePlatform Condition="'$(StridePlatform)' == '' And $(RuntimeIdentifier.StartsWith('osx'))">macOS</StridePlatform>
<StridePlatform Condition="'$(StridePlatform)' == '' And $(RuntimeIdentifier.StartsWith('linux'))">Linux</StridePlatform>
<StridePlatform></StridePlatform>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you clearing StridePlatform?

Comment on lines +39 to +46
<StridePlatform Condition="'$(RuntimeIdentifier.StartsWith(win))'">Windows</StridePlatform>
<StridePlatform Condition="'$(RuntimeIdentifier.StartsWith(osx))'">macOS</StridePlatform>
<StridePlatform Condition="'$(RuntimeIdentifier.StartsWith(linux))'">Linux</StridePlatform>
<StridePlatform Condition="'$(TargetPlatformIdentifier)' == 'Windows'">Windows</StridePlatform>
<StridePlatform Condition="'$(TargetPlatformIdentifier)' == 'macOS'">macOS</StridePlatform>
<StridePlatform Condition="'$(TargetPlatformIdentifier)' == 'UAP'">UWP</StridePlatform>
<StridePlatform Condition="'$(TargetPlatformIdentifier)' == 'Android'">Android</StridePlatform>
<StridePlatform Condition="'$(TargetPlatformIdentifier)' == 'iOS'">iOS</StridePlatform>

@ds5678 ds5678 Aug 10, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you reverse the priority of RuntimeIdentifier and TargetPlatformIdentifier?

It's seems like consistency with Stride.Platform.props.

<StridePlatform></StridePlatform>
<StridePlatform Condition=" '$(RuntimeIdentifier.StartsWith(win))' ">Windows</StridePlatform>
<StridePlatform Condition=" '$(RuntimeIdentifier.StartsWith(osx))' ">macOS</StridePlatform>
<StridePlatform Condition=" '$(RuntimeIdentifier.StartsWith(linux))' ">Linux</StridePlatform>
<StridePlatform Condition=" '$(StrideTargetFramework)' == '$(StrideFrameworkWindows)' ">Windows</StridePlatform>
<StridePlatform Condition=" '$(StrideTargetFramework)' == '$(StrideFrameworkmacOS)' ">macOS</StridePlatform>
<StridePlatform Condition=" '$(StrideTargetFramework)' == '$(StrideFrameworkUWP)' ">UWP</StridePlatform>
<StridePlatform Condition=" '$(StrideTargetFramework)' == '$(StrideFrameworkAndroid)' ">Android</StridePlatform>
<StridePlatform Condition=" '$(StrideTargetFramework)' == '$(StrideFrameworkiOS)' ">iOS</StridePlatform>
<StridePlatform Condition=" '$(StridePlatform)' == '' And '$([MSBuild]::IsOSPlatform(Linux))' ">Linux</StridePlatform>
<StridePlatform Condition=" '$(StridePlatform)' == '' And '$([MSBuild]::IsOSPlatform(OSX))' ">macOS</StridePlatform>
<StridePlatform Condition=" '$(StridePlatform)' == '' ">Windows</StridePlatform>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've tried to replicate logic from the Stride.Platform.props file

@Kryptos-FR

Kryptos-FR commented Aug 10, 2026

Copy link
Copy Markdown
Member

I'm not sure to understand the fix. .props files are loaded before any .targets file. So if the logic already exists in Stride.Platform.props then there is no need to override it in a .targets file. (edit: it's used for different contexts. Stride.Platform.props is for our stride projects (engine and editor), while Stride.Core.targets is for game projects that are using Stride).

What is exactly the bug that this fixes?

In addition, not checking that the value hasn't already been set doesn't make it optional, it makes it impossible to set in the command line.

edit: ok so after reading the content of Stride.Platform.props, I kind of understand the PR. With that said, I'm not sure either are correct now. In defeat the purpose of being able to set StridePlatform and through that allow cross-compilation.

@ds5678

ds5678 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

I'm not sure to understand the fix. .props files are loaded before any .targets file. So if the logic already exists in Stride.Platform.props then there is no need to override it in a .targets file.

According to a message in Discord, this pull request is based on #3075. However, I didn't know much about .props and .targets files when making that pull request. I just assumed that having logic in all three files was necessary and adjusted the logic to be "complete". Should I have removed the .targets logic?

@Jklawreszuk

Copy link
Copy Markdown
Collaborator Author

I am sorry my PR description wasn't specific enough, I should have gone into more detail about the situation.
The thing is I found the bug on the latest build (4.4.0-beta4):
As a developer, If I create a new project - either through Stride.Cli or by setting up a new console project and adding packages and I DO NOT manually set the StridePlatform variable to Linux in the .csproj file (e.g., MyGame.Linux), the StridePlatform still automatically defaults to Windows.
Result of binlog on Linux:
image
This is happening due to the current logic within the Stride.Core.targets file, which is loaded via the Stride packages.

Also, I understand that the @ds5678's fixes were previously located in Stride.Core.props, which I believe was removed in favor of Stride.Platform.props (?), which is part of the currently developing Stride.Build.Sdk. I realize that the SDK is not yet available for use in the projects, which is why I referred to this as a 'temporary' fix."

Comment on lines +47 to +48
<StridePlatform Condition="'$(StridePlatform)' == '' And '$([MSBuild]::IsOSPlatform(Linux))' ">Linux</StridePlatform>
<StridePlatform Condition="'$(StridePlatform)' == '' And '$([MSBuild]::IsOSPlatform(OSX))' ">macOS</StridePlatform>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 3 lines are sufficient to solve your issue: these two and

<StridePlatform Condition="'$(StridePlatform)' == '' And $(RuntimeIdentifier.StartsWith('win'))">Windows</StridePlatform>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, I agree that TargetPlatformIdentifier and RuntimeIdentifier should be switched for consistency with Stride.Platform.props.

@Jklawreszuk

Copy link
Copy Markdown
Collaborator Author

@Kryptos-FR Well, maybe you're right. I will close the PR for now and I’ll try to take a closer look at the new SDK and how to integrate it, as it’s something I’ve completely missed and new to me. Sorry for the confusion 😬️

@ds5678

ds5678 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

I don't think this should be closed.

@Kryptos-FR

Kryptos-FR commented Aug 10, 2026

Copy link
Copy Markdown
Member

Me neither. It's a good discussion to have. I believe you were on something.

Game projects don't use the SDK, only our internal engine projects. So Stride.Core.targets might need some tweaks. I was confused earlier (I edited my comments since then).

@Jklawreszuk Jklawreszuk reopened this Aug 10, 2026
@Jklawreszuk

Copy link
Copy Markdown
Collaborator Author

Ohhhh I see, I thought the SDK was also designed for the game projects as well.

@ds5678

ds5678 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

I didn't test anything, but I think these changes would resolve your issue:

ds5678@372c3df

@Jklawreszuk

Jklawreszuk commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

@ds5678 Yes, your changes are completely correct! I can apply that

@ds5678

ds5678 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Why not the changes to Stride.Platform.props too?

@Jklawreszuk

Copy link
Copy Markdown
Collaborator Author

Sure, Done! And most importantly, It works again :
image

<StridePlatform Condition=" '$(RuntimeIdentifier.StartsWith(win))' ">Windows</StridePlatform>
<StridePlatform Condition=" '$(RuntimeIdentifier.StartsWith(osx))' ">macOS</StridePlatform>
<StridePlatform Condition=" '$(RuntimeIdentifier.StartsWith(linux))' ">Linux</StridePlatform>
<StridePlatform Condition=" '$(StrideTargetFramework)' == '$(StrideFrameworkWindows)' ">Windows</StridePlatform>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If those rules aren't needed anymore, we might need to review Stride.Frameworks.props.

@ds5678 ds5678 Aug 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look at the file you mentioned.

<StrideTargetFramework Condition="$(TargetFramework.StartsWith('$(StrideFrameworkWindows)'))">$(StrideFrameworkWindows)</StrideTargetFramework>

<!-- Written by me for comparision -->
<StrideTargetFramework Condition="'$(TargetPlatformIdentifier)' == 'Windows'">$(StrideFrameworkWindows)</StrideTargetFramework>

These two lines are basically the same since TargetPlatformIdentifier is internally calculated by parsing TargetFramework.

So I agree that if StrideTargetFramework isn't used anywhere else, it could be removed since this code now uses the "official" way of extracting the platform from the TargetFramework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants