Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Build and test on Windows. #290

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ var awsCCommonPlatformExcludes = ["source/android",
// includes arch/generic because the SwiftPM doesn't like the necessary compiler flags.
awsCCommonPlatformExcludes.append("source/arch/intel")
awsCCommonPlatformExcludes.append("source/arch/arm")
#if !os(Windows)
#if os(Windows)
awsCCommonPlatformExcludes.append("source/posix")
#else
awsCCommonPlatformExcludes.append("source/windows")
#endif
let cSettingsCommon: [CSetting] = [

var cSettingsCommon: [CSetting] = [
.headerSearchPath("source/external/libcbor"),
.define("DEBUG_BUILD", .when(configuration: .debug))
]
#if os(Windows)
cSettingsCommon.append(.define("AWS_OS_WINDOWS_DESKTOP"))
#endif

//////////////////////////////////////////////////////////////////////
/// aws-c-cal
Expand Down Expand Up @@ -117,13 +123,16 @@ var cSettingsIO = cSettings
#if os(Linux)
ioDependencies.append("S2N_TLS")
cSettingsIO.append(.define("USE_S2N"))
#elseif os(Windows)
cSettingsIO.append(.define("AWS_USE_IO_COMPLETION_PORTS"))
#endif

#if os(Windows)
awsCIoPlatformExcludes.append("source/posix")
awsCIoPlatformExcludes.append("source/linux")
awsCIoPlatformExcludes.append("source/s2n")
awsCIoPlatformExcludes.append("source/darwin")
awsCIoPlatformExcludes.append("source/bsd")
#elseif os(Linux)
awsCIoPlatformExcludes.append("source/windows")
awsCIoPlatformExcludes.append("source/bsd")
Expand All @@ -146,9 +155,6 @@ var awsCChecksumsExcludes = [
"cmake",
"tests"]

// swift never uses Microsoft Visual C++ compiler
awsCChecksumsExcludes.append("source/intel/visualc")

// Hardware accelerated checksums are disabled because SwiftPM doesn't like the necessary compiler flags.
// We can add it once SwiftPM has the necessary support for CPU flags or builds C libraries
// using CMake.
Expand Down Expand Up @@ -192,6 +198,14 @@ let awsCEventStreamExcludes = [
"CODE_OF_CONDUCT.md",
"clang-tidy/run-clang-tidy.sh"] + excludesFromAll

//////////////////////////////////////////////////////////////////////
/// AwsCommonRuntimeKitTests
//////////////////////////////////////////////////////////////////////
var awsCommonRuntimeKitTestsExcludes: [String] = []
#if !os(Windows)
awsCommonRuntimeKitTestsExcludes.append("shims/windows")
#endif

packageTargets.append(contentsOf: [
.target(
name: "AwsCPlatformConfig",
Expand Down Expand Up @@ -281,6 +295,7 @@ packageTargets.append(contentsOf: [
name: "AwsCommonRuntimeKitTests",
dependencies: ["AwsCommonRuntimeKit"],
path: "Test/AwsCommonRuntimeKitTests",
exclude: awsCommonRuntimeKitTestsExcludes,
resources: [
.process("Resources")
]
Expand Down
2 changes: 1 addition & 1 deletion Source/AwsCommonRuntimeKit/crt/Allocator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final class TracingAllocator: Allocator {
self.rawValue = aws_mem_tracer_new(
tracingAllocator.rawValue,
nil,
aws_mem_trace_level(level.rawValue),
aws_mem_trace_level(Int32(level.rawValue)),
framesPerStack)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import AwsCEventStream
import Foundation

#if os(Windows)
// Resolve ambiguity with the Windows SDK type.
import struct Foundation.UUID
#endif

public struct EventStreamHeader {
/// max header name length is 127 bytes (Int8.max)
public static let maxNameLength = AWS_EVENT_STREAM_HEADER_NAME_LEN_MAX
Expand Down
2 changes: 1 addition & 1 deletion Source/AwsCommonRuntimeKit/io/StreamCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private func doSeek(_ stream: UnsafeMutablePointer<aws_input_stream>!,
let iStreamCore = Unmanaged<IStreamCore>.fromOpaque(stream.pointee.impl).takeUnretainedValue()
let iStreamable = iStreamCore.iStreamable
do {
let streamSeekType = StreamSeekType(rawValue: seekBasis.rawValue)!
let streamSeekType = StreamSeekType(rawValue: UInt32(seekBasis.rawValue))!
try iStreamable.seek(offset: offset, streamSeekType: streamSeekType)
iStreamCore.isEndOfStream = false
return AWS_OP_SUCCESS
Expand Down
2 changes: 1 addition & 1 deletion Source/AwsCommonRuntimeKit/io/TLSContextOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class TLSContextOptions: CStruct {
}

public func setMinimumTLSVersion(_ tlsVersion: TLSVersion) {
aws_tls_ctx_options_set_minimum_tls_version(rawValue, aws_tls_versions(rawValue: tlsVersion.rawValue))
aws_tls_ctx_options_set_minimum_tls_version(rawValue, aws_tls_versions(rawValue: Int32(tlsVersion.rawValue)))
}

typealias RawType = aws_tls_ctx_options
Expand Down
6 changes: 6 additions & 0 deletions Test/AwsCommonRuntimeKitTests/XCBaseTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ extension XCTestCase {
#endif
}

func skipIfWindows() throws {
#if os(Windows)
throw XCTSkip("Skipping test on Windows")
#endif
}

func skipIftvOS() throws {
#if os(tvOS)
throw XCTSkip("Skipping test on tvOS")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class FileBasedConfigurationTests: XCBaseTestCase {
}

func testResolveConfigPath() throws {
try skipIfWindows()

// from $HOME
let home = "/test/home"
let oldHome = getenv("HOME")
Expand Down
21 changes: 21 additions & 0 deletions Test/AwsCommonRuntimeKitTests/shims/windows/SetEnvShim.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation
import WinSDK

@discardableResult
func setenv(_ name: String, _ value: String, _ overwrite: Int) -> Int {
let namePtr = name.withCString(encodedAs: UTF8.self) { $0 }
let valuePtr = value.withCString(encodedAs: UTF8.self) { $0 }
return SetEnvironmentVariableA(namePtr, valuePtr) ? 0 : -1
}

@discardableResult
func setenv(_ name: String, _ value: LPCSTR, _ overwrite: Int) -> Int {
let namePtr = name.withCString(encodedAs: UTF8.self) { $0 }
return SetEnvironmentVariableA(namePtr, value) ? 0 : -1
}

@discardableResult
func unsetenv(_ name: String) -> Int {
let namePtr = name.withCString(encodedAs: UTF8.self) { $0 }
return SetEnvironmentVariableA(namePtr, nil) ? 0 : -1
}