Skip to content

Commit

Permalink
[dart:io] Adds Platform.architecture
Browse files Browse the repository at this point in the history
Exposes "Platform::HostArchitecture" from the runtime to the "dart:io"
package as a new getter under "Platform". This could be useful for
determining which CPU architecture Dart is running on.
  • Loading branch information
RossComputerGuy committed Oct 24, 2024
1 parent 9774348 commit 6712eb6
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtime/bin/io_natives.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ namespace bin {
V(Namespace_GetPointer, 1) \
V(OSError_inProgressErrorCode, 0) \
V(Platform_NumberOfProcessors, 0) \
V(Platform_Architecture, 0) \
V(Platform_OperatingSystem, 0) \
V(Platform_OperatingSystemVersion, 0) \
V(Platform_PathSeparator, 0) \
Expand Down
6 changes: 6 additions & 0 deletions runtime/bin/platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ void FUNCTION_NAME(Platform_NumberOfProcessors)(Dart_NativeArguments args) {
Dart_SetReturnValue(args, Dart_NewInteger(Platform::NumberOfProcessors()));
}

void FUNCTION_NAME(Platform_Architecture)(Dart_NativeArguments args) {
Dart_Handle str = DartUtils::NewString(Platform::HostArchitecture());
ThrowIfError(str);
Dart_SetReturnValue(args, str);
}

void FUNCTION_NAME(Platform_OperatingSystem)(Dart_NativeArguments args) {
Dart_Handle str = DartUtils::NewString(Platform::OperatingSystem());
ThrowIfError(str);
Expand Down
5 changes: 5 additions & 0 deletions sdk/lib/_internal/js_dev_runtime/patch/io_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ class _Platform {
throw UnsupportedError("Platform._numberOfProcessors");
}

@patch
static String _architecture() {
throw UnsupportedError("Platform._architecture");
}

@patch
static String _pathSeparator() {
throw UnsupportedError("Platform._pathSeparator");
Expand Down
5 changes: 5 additions & 0 deletions sdk/lib/_internal/js_runtime/lib/io_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ class _Platform {
throw UnsupportedError("Platform._numberOfProcessors");
}

@patch
static String _architecture() {
throw UnsupportedError("Platform._architecture");
}

@patch
static String _pathSeparator() {
throw UnsupportedError("Platform._pathSeparator");
Expand Down
3 changes: 3 additions & 0 deletions sdk/lib/_internal/vm/bin/platform_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class _Platform {
@pragma("vm:external-name", "Platform_NumberOfProcessors")
external static int _numberOfProcessors();
@patch
@pragma("vm:external-name", "Platform_Architecture")
external static String _architecture();
@patch
@pragma("vm:external-name", "Platform_PathSeparator")
external static String _pathSeparator();
@patch
Expand Down
5 changes: 5 additions & 0 deletions sdk/lib/_internal/wasm/lib/io_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ class _Platform {
throw new UnsupportedError("Platform._numberOfProcessors");
}

@patch
static String _architecture() {
throw new UnsupportedError("Platform._architecture");
}

@patch
static String _pathSeparator() {
throw new UnsupportedError("Platform._pathSeparator");
Expand Down
14 changes: 14 additions & 0 deletions sdk/lib/io/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ abstract final class Platform {
@pragma("vm:platform-const")
static final pathSeparator = _Platform.pathSeparator;

/// A string representing the CPU architecture
///
/// Possible values include:
/// * "arm64"
/// * "arm"
/// * "ia32"
/// * "riscv32"
/// * "riscv64"
/// * "x64"
///
/// Note that this list may change over time.
@pragma("vm:platform-const")
static final architecture = _Platform.architecture;

/// A string representing the operating system or platform.
///
/// Possible values include:
Expand Down
2 changes: 2 additions & 0 deletions sdk/lib/io/platform_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ part of dart.io;

class _Platform {
external static int _numberOfProcessors();
external static String _architecture();
external static String _pathSeparator();
external static String _operatingSystem();
external static _operatingSystemVersion();
Expand Down Expand Up @@ -52,6 +53,7 @@ class _Platform {
static var /*OSError?|Map<String,String>?*/ _environmentCache;

static int get numberOfProcessors => _numberOfProcessors();
static String get architecture => _architecture();
static String get pathSeparator => _pathSeparator();
static String get operatingSystem => _operatingSystem();
static Uri get script => _script();
Expand Down

0 comments on commit 6712eb6

Please sign in to comment.