Skip to content

Commit b7d031a

Browse files
authored
feat: add Linux support (#20)
1 parent 2565815 commit b7d031a

36 files changed

+358
-196
lines changed

.clang-format

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: Mozilla
4+
AlignAfterOpenBracket: AlwaysBreak
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveDeclarations: false
7+
AlignEscapedNewlines: Right
8+
AlignOperands: true
9+
AlignTrailingComments: true
10+
AllowAllParametersOfDeclarationOnNextLine: false
11+
AllowShortBlocksOnASingleLine: false
12+
AllowShortCaseLabelsOnASingleLine: false
13+
AllowShortFunctionsOnASingleLine: Inline
14+
AllowShortIfStatementsOnASingleLine: false
15+
AllowShortLoopsOnASingleLine: false
16+
AlwaysBreakAfterReturnType: None
17+
AlwaysBreakBeforeMultilineStrings: false
18+
BinPackArguments: false
19+
BinPackParameters: false
20+
BreakBeforeBinaryOperators: None
21+
BreakBeforeBraces: Attach
22+
BreakBeforeTernaryOperators: true
23+
BreakStringLiterals: true
24+
ColumnLimit: 120
25+
ContinuationIndentWidth: 4
26+
DerivePointerAlignment: false
27+
IncludeBlocks: Preserve
28+
IndentCaseLabels: true
29+
IndentPPDirectives: AfterHash
30+
IndentWidth: 4
31+
IndentWrappedFunctionNames: true
32+
KeepEmptyLinesAtTheStartOfBlocks: true
33+
MacroBlockBegin: ''
34+
MacroBlockEnd: ''
35+
MaxEmptyLinesToKeep: 1
36+
PenaltyBreakAssignment: 2
37+
PenaltyBreakBeforeFirstCallParameter: 19
38+
PenaltyBreakComment: 300
39+
PenaltyBreakFirstLessLess: 120
40+
PenaltyBreakString: 1000
41+
PenaltyExcessCharacter: 1000000
42+
PenaltyReturnTypeOnItsOwnLine: 100000
43+
PointerAlignment: Right
44+
ReflowComments: true
45+
SortIncludes: true
46+
SpaceAfterCStyleCast: false
47+
SpaceBeforeAssignmentOperators: true
48+
SpaceBeforeParens: ControlStatements
49+
SpaceInEmptyParentheses: false
50+
SpacesInContainerLiterals: true
51+
SpacesInCStyleCastParentheses: false
52+
SpacesInParentheses: false
53+
SpacesInSquareBrackets: false
54+
Standard: Cpp11
55+
TabWidth: 4
56+
UseTab: Never
57+
...
58+

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.git/
2+
.build/
3+
!.build/checkouts/
4+
!.build/repositories/
5+
!.build/workspace-state.json

.github/workflows/ci.yml

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- '!master'
88

99
env:
10-
BUILDER_VERSION: v0.8.0
10+
BUILDER_VERSION: v0.8.15
1111
BUILDER_SOURCE: releases
1212
BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net
1313
PACKAGE_NAME: aws-crt-swift
@@ -82,9 +82,11 @@ jobs:
8282
echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin
8383
export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/${{ matrix.image }}:${{ env.BUILDER_VERSION }}
8484
docker pull $DOCKER_IMAGE
85-
docker run --mount type=bind,source=$(pwd),target=/root/${{ env.PACKAGE_NAME }} --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --build-dir=/root/${{ env.PACKAGE_NAME }} --spec=downstream --compiler=clang-${{ matrix.version }}
85+
docker run --mount type=bind,source=$(pwd),target=/root/${{ env.PACKAGE_NAME }} --env GITHUB_REF $DOCKER_IMAGE build -p ${{ env.PACKAGE_NAME }} --build-dir=/root/${{ env.PACKAGE_NAME }} --spec=downstream
8686
osx:
87-
runs-on: macos-latest
87+
runs-on: macos-11
88+
env:
89+
DEVELOPER_DIR: /Applications/Xcode_12.5.app
8890
steps:
8991
- name: Checkout Sources
9092
uses: actions/checkout@v2
@@ -96,7 +98,9 @@ jobs:
9698
chmod a+x builder
9799
./builder build -p ${{ env.PACKAGE_NAME }} --spec=downstream
98100
ios:
99-
runs-on: macos-latest
101+
runs-on: macos-11
102+
env:
103+
DEVELOPER_DIR: /Applications/Xcode_12.5.app
100104
steps:
101105
- name: Checkout Sources
102106
uses: actions/checkout@v2

.gitmodules

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
path = aws-common-runtime/aws-c-io
66
url = https://github.com/awslabs/aws-c-io.git
77
[submodule "aws-common-runtime/s2n"]
8-
path = aws-common-runtime/s2n
9-
url = https://github.com/awslabs/s2n.git
8+
path = S2N/s2n
9+
url = https://github.com/aws/s2n-tls.git
1010
[submodule "aws-common-runtime/aws-c-compression"]
1111
path = aws-common-runtime/aws-c-compression
1212
url = https://github.com/awslabs/aws-c-compression.git

Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM swift:5.4-focal
2+
3+
WORKDIR /package
4+
5+
COPY . ./
6+
7+
# to test on al2 swift images uncomment this and comment out other line.
8+
# RUN yum -y install openssl-devel
9+
RUN apt-get update -qq
10+
RUN apt-get -y install libssl-dev
11+
12+
RUN swift package clean
13+
14+
RUN swift build
15+
16+
CMD ["swift", "test", "-Xcc", "-g"]

Package.swift

+51-29
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.4
22
import PackageDescription
33

4+
var packageDependencies: [Package.Dependency] = []
5+
var calDependencies: [Target.Dependency] = ["AwsCCommon"]
6+
var ioDependencies: [Target.Dependency] = ["AwsCCommon", "AwsCCal"]
7+
8+
#if os(Linux)
9+
packageDependencies.append(.package(name: "S2N", path: "./S2N"))
10+
11+
ioDependencies.append(.product(name: "S2N", package: "S2N"))
12+
calDependencies.append(.product(name: "LibCrypto", package: "S2N"))
13+
#endif
14+
415
var package = Package(name: "AwsCrt",
5-
platforms: [.iOS(.v11), .macOS(.v10_14)],
6-
products: [
7-
.library(name: "AwsCommonRuntimeKit", targets: ["AwsCommonRuntimeKit"]),
8-
.executable(name: "Elasticurl", targets: ["Elasticurl"])
9-
])
16+
platforms: [.iOS(.v11), .macOS(.v10_14)],
17+
products: [
18+
.library(name: "AwsCommonRuntimeKit", targets: ["AwsCommonRuntimeKit"]),
19+
.executable(name: "Elasticurl", targets: ["Elasticurl"])
20+
],
21+
dependencies: packageDependencies
22+
)
23+
24+
let excludesFromAll = ["bin", "tests", "cmake", "codebuild", "CONTRIBUTING.md",
25+
"LICENSE", "format-check.sh", "NOTICE", "builder.json",
26+
"sanitizer-blacklist.txt", "CMakeLists.txt", "README.md",
27+
"CODE_OF_CONDUCT.md", "build-deps.sh"]
1028

1129
// aws-c-common config
12-
var awsCCommonPlatformExcludes = ["source/windows", "source/android", "AWSCRTAndroidTestRunner",
13-
"cmake", "codebuild", "docker-images", "tests", "verification"]
14-
//var unsafeFlagsArray: [String] = []
30+
var awsCCommonPlatformExcludes = ["source/windows", "source/android",
31+
"AWSCRTAndroidTestRunner", "docker-images", "verification",
32+
"include/aws/common/"]
33+
awsCCommonPlatformExcludes.append(contentsOf: excludesFromAll)
1534

1635
#if arch(i386) || arch(x86_64)
1736
awsCCommonPlatformExcludes.append("source/arch/arm")
@@ -33,7 +52,8 @@ awsCCommonPlatformExcludes.append("source/arch/intel/asm")
3352
awsCCommonPlatformExcludes.append("source/arch/arm/asm")
3453
#endif
3554

36-
var awsCIoPlatformExcludes = ["tests", "cmake", "docs"]
55+
var awsCIoPlatformExcludes = ["docs"]
56+
awsCIoPlatformExcludes.append(contentsOf: excludesFromAll)
3757

3858
#if os(macOS)
3959
awsCIoPlatformExcludes.append("source/windows")
@@ -50,46 +70,47 @@ awsCIoPlatformExcludes.append("source/bsd")
5070
awsCIoPlatformExcludes.append("source/darwin")
5171
#endif
5272

53-
var awsCCalPlatformExcludes = ["tests", "cmake"]
73+
var awsCCalPlatformExcludes = ["include/aws/cal/private"]
74+
awsCCalPlatformExcludes.append(contentsOf: excludesFromAll)
5475

5576
#if os(macOS)
5677
awsCCalPlatformExcludes.append("source/windows")
5778
awsCCalPlatformExcludes.append("source/unix")
5879
#elseif(Windows)
59-
awsCCalPlatformExcludes.append("source/darin")
80+
awsCCalPlatformExcludes.append("source/darwin")
6081
awsCCalPlatformExcludes.append("source/unix")
6182
#else
6283
awsCCalPlatformExcludes.append("source/windows")
6384
awsCCalPlatformExcludes.append("source/darwin")
6485
#endif
6586

66-
var awsCCompressionPlatformExcludes = ["tests", "cmake", "codebuild", "source/huffman_generator/"]
67-
var awsCHttpPlatformExcludes = ["tests", "bin", "integration-testing", "continuous-delivery", "cmake", "codebuild"]
68-
var awsCAuthPlatformExcludes = ["tests"]
69-
var awsCMqttPlatformExcludes = ["tests", "cmake"]
87+
var awsCCompressionPlatformExcludes = ["source/huffman_generator/"]
88+
awsCCompressionPlatformExcludes.append(contentsOf: excludesFromAll)
89+
var awsCHttpPlatformExcludes = ["integration-testing", "continuous-delivery", "include/aws/http/private"]
90+
awsCHttpPlatformExcludes.append(contentsOf: excludesFromAll)
91+
let awsCAuthPlatformExcludes = excludesFromAll
92+
let awsCMqttPlatformExcludes = excludesFromAll
7093

7194
package.targets = ( [
7295
.target(
7396
name: "AwsCPlatformConfig",
7497
path: "aws-common-runtime/config",
75-
publicHeadersPath: "."
76-
),
98+
publicHeadersPath: "."),
7799
.target(
78100
name: "AwsCCommon",
79101
dependencies: ["AwsCPlatformConfig"],
80102
path: "aws-common-runtime/aws-c-common",
81103
exclude: awsCCommonPlatformExcludes),
104+
.target(
105+
name: "AwsCCal",
106+
dependencies: calDependencies,
107+
path: "aws-common-runtime/aws-c-cal",
108+
exclude: awsCCalPlatformExcludes),
82109
.target(
83110
name: "AwsCIo",
84-
dependencies: ["AwsCCommon"],
111+
dependencies: ioDependencies,
85112
path: "aws-common-runtime/aws-c-io",
86113
exclude: awsCIoPlatformExcludes),
87-
.target(
88-
name: "AwsCCal",
89-
dependencies: ["AwsCCommon"],
90-
path: "aws-common-runtime/aws-c-cal",
91-
exclude: awsCCalPlatformExcludes
92-
),
93114
.target(
94115
name: "AwsCCompression",
95116
dependencies: ["AwsCCommon"],
@@ -98,7 +119,7 @@ package.targets = ( [
98119
),
99120
.target(
100121
name: "AwsCHttp",
101-
dependencies: ["AwsCCompression", "AwsCIo", "AwsCCommon"],
122+
dependencies: ["AwsCCompression", "AwsCIo", "AwsCCal", "AwsCCommon"],
102123
path: "aws-common-runtime/aws-c-http",
103124
exclude: awsCHttpPlatformExcludes
104125
),
@@ -110,9 +131,10 @@ package.targets = ( [
110131
),
111132
.target(
112133
name: "AwsCMqtt",
113-
dependencies: ["AwsCHttp", "AwsCCompression", "AwsCIo", "AwsCCommon"],
134+
dependencies: ["AwsCHttp", "AwsCCompression", "AwsCIo", "AwsCCal", "AwsCCommon"],
114135
path: "aws-common-runtime/aws-c-mqtt",
115-
exclude: awsCMqttPlatformExcludes
136+
exclude: awsCMqttPlatformExcludes,
137+
cSettings: [.define("AWS_MQTT_WITH_WEBSOCKETS")]
116138
),
117139
.target(
118140
name: "AwsCommonRuntimeKit",
@@ -124,7 +146,7 @@ package.targets = ( [
124146
dependencies: ["AwsCommonRuntimeKit"],
125147
path: "Test"
126148
),
127-
.target(
149+
.executableTarget(
128150
name: "Elasticurl",
129151
dependencies: ["AwsCommonRuntimeKit"],
130152
path: "Source/Elasticurl"

S2N/Package.swift

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// swift-tools-version:5.3
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "S2N",
6+
products: [
7+
.library(
8+
name: "S2N",
9+
targets: ["S2N"]
10+
),
11+
.library(
12+
name: "LibCrypto",
13+
targets: ["LibCrypto"]
14+
)
15+
],
16+
targets: [
17+
.target(
18+
name: "S2N",
19+
dependencies: ["LibCrypto"],
20+
path: "s2n",
21+
// add pq-crypto back after adding in platform and chipset detection
22+
exclude: ["bin", "cmake", "codebuild", "coverage", "docker-images",
23+
"docs", "lib", "pq-crypto/bike_r1", "pq-crypto/bike_r2",
24+
"pq-crypto/bike_r3", "pq-crypto/kyber_90s_r2", "pq-crypto/kyber_r3",
25+
"pq-crypto/kyber_r2", "pq-crypto/sike_r1", "pq-crypto/sike_r2",
26+
"pq-crypto/README.md", "pq-crypto/Makefile", "pq-crypto/s2n_pq_asm.mk",
27+
"libcrypto-build", "scram", "tests",
28+
"s2n.mk", "Makefile", "stuffer/Makefile", "crypto/Makefile",
29+
"tls/Makefile", "utils/Makefile", "error/Makefile",
30+
"extensions/Makefile", "tls/extensions/Makefile",
31+
"codecov.yml", "scripts/", "tests", "cmake", "codebuild", "CONTRIBUTING.md",
32+
"LICENSE", "format-check.sh", "NOTICE", "builder.json",
33+
"sanitizer-blacklist.txt", "CMakeLists.txt", "README.md",
34+
"CODE_OF_CONDUCT.md", "build-deps.sh"],
35+
publicHeadersPath: "api",
36+
cSettings: [
37+
.headerSearchPath("./"),
38+
.define("POSIX_C_SOURCE=200809L"),
39+
.define("S2N_NO_PQ")
40+
]
41+
),
42+
.systemLibrary(
43+
name: "LibCrypto",
44+
pkgConfig: "libcrypto",
45+
providers: [
46+
.apt(["openssl libssl-dev"])
47+
//add this back when swift pm get's their crap together \\ .yum(["openssl openssl-devel"])
48+
]
49+
)
50+
]
51+
)
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
module LibCrypto {
3+
header "shim.h"
4+
link "crypto"
5+
export *
6+
}
7+

S2N/Sources/LibCrypto/shim.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef OpenSSLHelper_h
2+
#define OpenSSLHelper_h
3+
4+
#include <openssl/conf.h>
5+
#include <openssl/evp.h>
6+
#include <openssl/err.h>
7+
#include <openssl/md4.h>
8+
#include <openssl/md5.h>
9+
#include <openssl/sha.h>
10+
#include <openssl/hmac.h>
11+
#include <openssl/rand.h>
12+
#include <openssl/pkcs12.h>
13+
#include <openssl/x509v3.h>
14+
#include <openssl/x509.h>
15+
16+
#endif
17+

S2N/s2n

Submodule s2n added at aa581bf

Source/AwsCommonRuntimeKit/crt/Allocator.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public final class TracingAllocator: Allocator {
5555

5656
/**
5757
Creates an `Allocator` that doesn't track anything.
58-
58+
5959
- Parameter allocator: The allocator to be traced.
6060
*/
6161
public convenience init(_ allocator: Allocator = defaultAllocator) {
@@ -78,7 +78,7 @@ public final class TracingAllocator: Allocator {
7878
* - Parameter framesPerStack: How many frames to record for each allocation
7979
* (8 as usually a good default to start with).
8080
*/
81-
public convenience init(tracingStacksOf allocator: Allocator, framesPerStack: Int = 8) {
81+
public convenience init(tracingStacksOf allocator: Allocator, framesPerStack: Int = 16) {
8282
self.init(allocator, level: .stacks, framesPerStack: framesPerStack)
8383
}
8484

0 commit comments

Comments
 (0)