# Supported Target Platforms for TypePHP: Windows, Linux, macOS, and WASI

> Discover TypePHP's supported target platforms: Windows, Linux, macOS, and WASI. Compile portable binaries easily with automatic host detection and cross-compilation.

- Repository: [Swoole Project/typephp](https://github.com/swoole/typephp)
- Tags: getting-started
- Published: 2026-08-30

---

**TypePHP supports four target platforms: Windows, Linux, macOS, and WebAssembly System Interface (WASI), with automatic host detection and cross-compilation capabilities for portable binaries.**

TypePHP is a PHP-to-native transpiler maintained in the swoole/typephp repository. Understanding the supported target platforms for TypePHP is critical for deploying binaries across diverse operating systems and runtime environments. The platform abstraction layer automatically handles compiler-specific flags, file extensions, and linking conventions for each supported architecture.

## Native Host Platform Support

TypePHP automatically detects the host operating system at runtime through the `PlatformFactory::create()` method located in [`src/Platform/PlatformFactory.php`](https://github.com/swoole/typephp/blob/main/src/Platform/PlatformFactory.php) (lines 16-22). This factory inspects the `PHP_OS` constant and instantiates the appropriate concrete implementation of the abstract `PlatformBase` class.

### Windows Platform

When the `PHP_OS` constant starts with "WIN", TypePHP initializes the Windows platform via [`src/Platform/Windows.php`](https://github.com/swoole/typephp/blob/main/src/Platform/Windows.php). This implementation provides Windows-specific compiler flags, executable file extensions (`.exe`), and dynamic library handling compatible with MSVC and MinGW toolchains.

### Linux Platform

Linux serves as the default platform for most Unix-like systems. The [`src/Platform/Linux.php`](https://github.com/swoole/typephp/blob/main/src/Platform/Linux.php) implementation supplies GNU-compatible compiler settings, standard ELF binary formats, and shared library conventions used across major Linux distributions including Ubuntu, CentOS, and Debian.

### macOS Platform

For Darwin-based systems, TypePHP uses [`src/Platform/Macos.php`](https://github.com/swoole/typephp/blob/main/src/Platform/Macos.php) to configure Apple-specific compiler details. This includes framework linking support, bundle structures, and Mach-O binary formats required for both Apple silicon (ARM64) and Intel-based Macs.

## Cross-Compilation and WebAssembly Support

Beyond native host platforms, TypePHP supports cross-compilation to alternative architectures through the `--target-platform` CLI option. This functionality is implemented in [`src/Translator.php`](https://github.com/swoole/typephp/blob/main/src/Translator.php) between lines 176-188, where the system checks for user-defined target triples.

### WASI Target Platform

TypePHP can generate WebAssembly binaries targeting the WebAssembly System Interface through [`src/Platform/Wasi.php`](https://github.com/swoole/typephp/blob/main/src/Platform/Wasi.php). When you specify a target triple such as `wasm32-wasip2`, the `Translator` class instantiates a `Wasi` platform instance instead of using auto-detection. This enables creation of portable binaries that execute in any WASI-compliant runtime environment without platform-specific dependencies.

## Specifying Target Platforms in Practice

You can control the target platform through command-line options or programmatically via the Platform API.

### Command-Line Usage

```bash

# Build for the native host platform (auto-detected)

php tpc.php build

# Cross-compile to Linux ARM64 target

php tpc.php build --target-platform aarch64-linux-gnu

# Compile to WebAssembly WASI binary

php tpc.php build --target-platform wasm32-wasip2

```

### Programmatic Platform Detection

```php
use TypePhp\Platform\PlatformFactory;

// Auto-detect current platform (Windows, Linux, or macOS)
$platform = PlatformFactory::create();
echo "Running on: " . $platform->getName();

```

## Summary

- TypePHP supports **four target platforms**: Windows, Linux, macOS, and WASI (WebAssembly System Interface).
- **Auto-detection** occurs via `PlatformFactory::create()` in [`src/Platform/PlatformFactory.php`](https://github.com/swoole/typephp/blob/main/src/Platform/PlatformFactory.php) based on the `PHP_OS` constant.
- **Windows** platforms are identified when `PHP_OS` starts with "WIN", loading Windows-specific compiler settings from [`src/Platform/Windows.php`](https://github.com/swoole/typephp/blob/main/src/Platform/Windows.php).
- **Cross-compilation** to WASI targets uses the `--target-platform` CLI option handled in [`src/Translator.php`](https://github.com/swoole/typephp/blob/main/src/Translator.php) lines 176-188.
- Target triples like `aarch64-linux-gnu` or `wasm32-wasip2` instantiate the `Wasi` class for architecture-specific builds.

## Frequently Asked Questions

### How does TypePHP detect which platform to use?

TypePHP uses the `PlatformFactory::create()` method in [`src/Platform/PlatformFactory.php`](https://github.com/swoole/typephp/blob/main/src/Platform/PlatformFactory.php) (lines 16-22) to inspect the `PHP_OS` constant at runtime. If the string starts with "WIN", it returns a Windows instance. It then checks for Darwin to return macOS, defaulting to Linux for all other Unix-like systems.

### Can I compile TypePHP binaries for WebAssembly?

Yes. TypePHP supports WebAssembly System Interface (WASI) targets through the [`src/Platform/Wasi.php`](https://github.com/swoole/typephp/blob/main/src/Platform/Wasi.php) implementation. Specify a WASM target triple using the `--target-platform wasm32-wasip2` flag to generate portable binaries that run in WASI-compliant runtimes like Wasmtime or Wasmer.

### Does TypePHP support cross-compilation to different CPU architectures?

Yes. While native platforms are auto-detected, you can cross-compile to specific architectures using target triples. The `Translator` class processes the `--target-platform` argument (lines 176-188 in [`src/Translator.php`](https://github.com/swoole/typephp/blob/main/src/Translator.php)) to instantiate platform handlers for non-native targets like ARM64 Linux.

### Where are the platform-specific compiler settings defined?

Each platform resides in the `src/Platform/` directory: [`Windows.php`](https://github.com/swoole/typephp/blob/main/Windows.php) handles Windows systems, [`Linux.php`](https://github.com/swoole/typephp/blob/main/Linux.php) manages Linux distributions, [`Macos.php`](https://github.com/swoole/typephp/blob/main/Macos.php) covers macOS, and [`Wasi.php`](https://github.com/swoole/typephp/blob/main/Wasi.php) implements WebAssembly targets. All platform classes extend the abstract `PlatformBase` class and define compiler-specific configurations for their respective environments.