Add Freestanding OS Types (#2399)

* Add Freestanding OS Types to `env::`
This commit is contained in:
Zack Puhl
2025-08-16 13:47:03 -04:00
committed by GitHub
parent 261184b5c1
commit ad02fad167
6 changed files with 12 additions and 6 deletions

View File

@@ -154,7 +154,12 @@ const bool NETBSD = LIBC && OS_TYPE == NETBSD;
const bool BSD_FAMILY = env::FREEBSD || env::OPENBSD || env::NETBSD;
const bool WASI = LIBC && OS_TYPE == WASI;
const bool ANDROID = LIBC && OS_TYPE == ANDROID;
const bool WASM_NOLIBC @builtin = !LIBC && ARCH_TYPE == ArchType.WASM32 || ARCH_TYPE == ArchType.WASM64;
const bool WASM_NOLIBC @builtin @deprecated("Use 'FREESTANDING_WASM' instead") = !LIBC && ARCH_TYPE == ArchType.WASM32 || ARCH_TYPE == ArchType.WASM64;
const bool FREESTANDING_PE32 = NO_LIBC && OS_TYPE == WIN32;
const bool FREESTANDING_MACHO = NO_LIBC && OS_TYPE == MACOS;
const bool FREESTANDING_ELF = NO_LIBC && !env::FREESTANDING_PE32 && !env::FREESTANDING_MACHO && !env::FREESTANDING_WASM;
const bool FREESTANDING_WASM = NO_LIBC && (ARCH_TYPE == ArchType.WASM32 || ARCH_TYPE == ArchType.WASM64);
const bool FREESTANDING = env::FREESTANDING_PE32 || env::FREESTANDING_MACHO || env::FREESTANDING_ELF || env::FREESTANDING_WASM;
const bool ADDRESS_SANITIZER = $$ADDRESS_SANITIZER;
const bool MEMORY_SANITIZER = $$MEMORY_SANITIZER;
const bool THREAD_SANITIZER = $$THREAD_SANITIZER;

View File

@@ -646,7 +646,7 @@ macro void @pool(usz reserve = 0; @body) @builtin
@body();
}
module std::core::mem @if(WASM_NOLIBC);
module std::core::mem @if(env::FREESTANDING_WASM);
import std::core::mem::allocator @public;
SimpleHeapAllocator wasm_allocator @private;
extern int __heap_base;

View File

@@ -511,7 +511,7 @@ macro Allocator temp() @deprecated("Use 'tmem' instead")
alias tmem @builtin = current_temp;
fn void allow_implicit_temp_allocator_on_load_thread() @init(1) @local @if(env::LIBC || env::WASM_NOLIBC)
fn void allow_implicit_temp_allocator_on_load_thread() @init(1) @local @if(env::LIBC || env::FREESTANDING_WASM)
{
auto_create_temp = true;
}

View File

@@ -39,7 +39,7 @@ macro @enum_lookup_new($Type, $name, value)
}
module std::core::runtime @if(WASM_NOLIBC);
module std::core::runtime @if(env::FREESTANDING_WASM);
extern fn void __wasm_call_ctors();
fn void wasm_initialize() @extern("_initialize") @wasm

View File

@@ -72,7 +72,7 @@ macro uint hash(value) @local
return (uint)a5hash::hash(&&bitcast(value, char[$sizeof(value)]));
}
fn char[8 * 4] entropy() @if(!env::WASM_NOLIBC)
fn char[8 * 4] entropy() @if(!env::FREESTANDING_WASM)
{
void* addr = malloc(1);
free(addr);
@@ -91,7 +91,7 @@ fn char[8 * 4] entropy() @if(!env::WASM_NOLIBC)
return bitcast(entropy_data, char[8 * 4]);
}
fn char[8 * 4] entropy() @if(env::WASM_NOLIBC)
fn char[8 * 4] entropy() @if(env::FREESTANDING_WASM)
{
static uint random_int;
random_int += 0xedf19156;

View File

@@ -53,6 +53,7 @@
- Added the experimental `std::core::log` for logging.
- Added array `@zip` and `@zip_into` macros. #2370
- Updated termios bindings to use bitstructs and fixed some constants with incorrect values #2372
- Add Freestanding OS types to runtime `env::` booleans.
- Added libloaderapi to `std::os::win32`.
- Added `HashSet.values` and `String.contains_char` #2386