Skip to content

[API Proposal]: Add OSPlatform.OpenBSD and OperatingSystem.IsOpenBSD APIs #129482

Closed

Description

@am11

Background and motivation

Code targeting OpenBSD currently rely on OSPlatform.Create("OPENBSD") stringly API. These workarounds lack compile-time safety and feature-parity with other operating systems.

While System.Private.CoreLib already utilizes an internal IsOpenBSD() check, it remains inaccessible to external libraries, NuGet packages, and application code.

Adding public OSPlatform.OpenBSD and OperatingSystem.IsOpenBSD{VersionAtLeast} APIs delivers:

  • Dead-Code Elimination: Allows NativeAOT and Mono LLVM compilers to trim unsupported code branches at build time.
  • Versioned Guarding: Safely isolates OS-specific system calls across OpenBSD releases.
  • API Symmetry: Replaces custom string matching with optimized platform checks consistent with FreeBSD.

API Proposal

namespace System.Runtime.InteropServices
{
    public readonly partial struct OSPlatform
    {
        public static OSPlatform OpenBSD { get; }
    }
}

namespace System
{
    public static partial class OperatingSystem
    {
        public static bool IsOpenBSD();
        public static bool IsOpenBSDVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0);
    }
}

API Usage

using System;
using System.Runtime.InteropServices;

// 1. Guarding platform-specific features using OperatingSystem
if (OperatingSystem.IsOpenBSD())
{
    Console.WriteLine("Running natively on OpenBSD.");
    
    // Check for specific version constraints (e.g., OpenBSD 7.4+)
    if (OperatingSystem.IsOpenBSDVersionAtLeast(7, 4))
    {
        // Invoke modern OpenBSD-specific system calls or APIs
    }
}

// 2. Passing the OS platform token to generic runtime dispatch APIs
if (RuntimeInformation.IsOSPlatform(OSPlatform.OpenBSD))
{
    Console.WriteLine("OSPlatform validation successful.");
}

Alternative Designs

  • Rely on existing workarounds: Developers can continue using OSPlatform.Create("OPENBSD") or parsing RuntimeInformation.OSDescription. This is not ideal as it creates runtime string allocation overhead, lacks compile-time safety, and prevents build-time dead-code elimination by the compiler.
  • Keep APIs internal: Maintain the status quo where IsOpenBSD() remains an internal helper inside System.Private.CoreLib. This forces external library authors and NuGet package maintainers to duplicate brittle, less efficient platform-detection logic across the ecosystem.

Risks

Low (new API)

Activity

  1. added
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Jun 16, 2026
  2. added
    os-openbsdOpenBSD OS, currently not officially supported
    on Jun 16, 2026
  3. dotnet-policy-service commented on Jun 16, 2026

    @dotnet-policy-service
    Contributor

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

  4. am11 commented on Jun 16, 2026

    @am11
    MemberAuthor

    cc @sethjackson, @wfurt, similar to #23530, related to #124911.

  5. added this to the Future milestone on Jun 30, 2026
  6. added
    api-ready-for-reviewAPI is ready for review, it is NOT ready for implementation
    and removed
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Jul 11, 2026
  7. bartonjs commented on Sep 8, 2026

    @bartonjs
    Member

    Video

    • Given that OSPlatform does not have tvOS/watchOS/et al, it seems that we've moved past that type, so let's only add the OperatingSystem members.
    namespace System
    {
        public static partial class OperatingSystem
        {
            public static bool IsOpenBSD();
            public static bool IsOpenBSDVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0);
        }
    }
  8. added
    api-approvedAPI was approved in API review, it can be implemented
    and removed
    api-ready-for-reviewAPI is ready for review, it is NOT ready for implementation
    on Sep 8, 2026
  9. locked and limited conversation to collaborators on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status
      No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions