Skip to content

CoreLib: accept LINUX as a platform-name alias on OpenHarmony - #136211

Closed
springmin wants to merge 2 commits into
dotnet:mainfrom
springmin:pr/ohos-corelib-linux-alias
Closed

springmin wants to merge 2 commits into
dotnet:mainfrom
springmin:pr/ohos-corelib-linux-alias

Conversation

@springmin

@springmin springmin commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On OpenHarmony, TARGET_LINUX is not defined and OSPlatformName is
OPENHARMONY, so RuntimeInformation.IsOSPlatform(OSPlatform.Linux) returns
false. MSBuild's NativeMethodsShared uses that check to choose Unix-like
Exec behavior; with false, it writes Windows-style .exec.cmd scripts on
device, and the NativeAOT linker probe fails with "linker not found" even
though clang++ is on PATH.

Changes

Keep OPENHARMONY as the canonical platform name and accept LINUX as an
alias under TARGET_OPENHARMONY, following the macOS alias precedent.

One file, 8 insertions. The new branch is compiled only for
TARGET_OPENHARMONY and is inert on other platforms.

Test

  • Device: a minimal console app (net11.0-openharmony26.0, PublishAot=true)
    builds and runs; RuntimeInformation.IsOSPlatform(OSPlatform.Linux) reports
    true.
  • Device: with the host runtime built from this change, dotnet publish -c Release -r openharmony-arm64 -p:PublishAot=true reaches "Generating
    native code" and completes with rc=0. Before the change, the same host
    wrote .exec.cmd and failed with Platform linker ('clang' or 'gcc') not found.
  • Note: the AOT binary in that run used the prebuilt target runtime pack; its
    own OSPlatform value follows that pack. The host runtime used for the
    publish contains this change.
  • A unit test in OperatingSystemTests asserts the LINUX alias on OpenHarmony;
    it returns early on other platforms. PR CI validates the CoreLib build.

Note

This PR was authored with AI assistance (agent tooling) under the author's direction.

OpenHarmony uses the Linux ABI (musl), but TARGET_LINUX is not defined and
OSPlatformName is "OPENHARMONY". RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
therefore returns false. MSBuild's NativeMethodsShared uses that check to
choose Unix-like Exec behavior; with false it writes Windows-style .exec.cmd
scripts on device, and the NativeAOT linker probe fails with "linker not
found" even though clang++ is on PATH.

Keep "OPENHARMONY" as the canonical platform name and accept "LINUX" as an
alias under TARGET_OPENHARMONY, following the macOS alias precedent.
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 21, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

Comment on lines +135 to +140
// OpenHarmony uses the Linux ABI (musl). Accept LINUX as an alias so
// callers that probe for Linux - e.g. MSBuild's
// IsOSPlatform(OSPlatform.Linux), which selects sh vs Windows-style
// Exec scripts - behave as on Linux, while OPENHARMONY stays the
// canonical name.
|| platform.Equals("LINUX", StringComparison.OrdinalIgnoreCase)

@huoyaoyuan huoyaoyuan Oct 21, 2026 •

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.

I don't think this is a correct change. Android expliclty returns false for IsLinux.
Build scripts testing ONLY IsOSPlatform(OSPlatform.Linux) are obviously incorrect.
If we add some "is Linux-like" like IsApplePlatform, it can return true then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed — IsOSPlatform(Linux) should not be true for OpenHarmony (Android follows the same rule). The problem is MSBuild's Unix-like detection, not the OS identity. I'll close this and move the fix to MSBuild's NativeMethodsShared (treat OPENHARMONY as Unix-like) rather than changing CoreLib.

Note

This reply was drafted with AI assistance (agent tooling) under the author's direction.

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

Labels

area-Infrastructure-libraries community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants