diff --git a/Sources/WasmKit/ModuleParser.swift b/Sources/WasmKit/ModuleParser.swift index 92a819d4..64eb94f1 100644 --- a/Sources/WasmKit/ModuleParser.swift +++ b/Sources/WasmKit/ModuleParser.swift @@ -1,10 +1,30 @@ import SystemPackage import WasmParser +#if os(Windows) +import ucrt + +extension FileDescriptor.AccessMode { + static var binary: FileDescriptor.AccessMode { + FileDescriptor.AccessMode(rawValue: O_BINARY) + } +} + +#endif + + /// Parse a given file as a WebAssembly binary format file /// > Note: public func parseWasm(filePath: FilePath, features: WasmFeatureSet = .default) throws -> Module { - let fileHandle = try FileDescriptor.open(filePath, .readOnly) + #if os(Windows) + // TODO: Upstream `O_BINARY` to `SystemPackage + let accessMode = FileDescriptor.AccessMode( + rawValue: FileDescriptor.AccessMode.readOnly.rawValue | FileDescriptor.AccessMode.binary.rawValue + ) + #else + let accessMode: FileDescriptor.AccessMode = .readOnly + #endif + let fileHandle = try FileDescriptor.open(filePath, accessMode) defer { try? fileHandle.close() } let stream = try FileHandleStream(fileHandle: fileHandle) let module = try parseModule(stream: stream, features: features)