Skip to content

Commit 28339fe

Browse files
authored
Support arm64 Lambdas (#17)
* Build on native arch * Support custom architecture * Output architecture * Strip * Force build lhr * Try args * Try pre * Pass debug * Fix region name * Another * Another * Cleanup * Beef up trailing slash regex * Remove build region
1 parent 15d2598 commit 28339fe

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

Plugins/VercelPackager/Utils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99
import PackagePlugin
1010

11-
public enum Architecture: String {
11+
public enum Architecture: String, Codable {
1212
case arm64 = "arm64"
1313
case x86 = "x86_64"
1414
}

Plugins/VercelPackager/VercelOutput.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ extension VercelOutput {
160160
argument("port") ?? "7676"
161161
}
162162

163+
public var architecture: Architecture {
164+
if let value = argument("arch"), let arch = Architecture(rawValue: value) {
165+
return arch
166+
}
167+
return Utils.currentArchitecture ?? .x86
168+
}
169+
163170
public func argument(_ key: String) -> String? {
164171
guard let index = arguments.firstIndex(of: "--\(key)") else {
165172
return nil
@@ -368,11 +375,11 @@ extension VercelOutput {
368375
let vercel = vercelConfiguration()
369376
let routes: [OutputConfiguration.Route] = [
370377
// Remove trailing slash
371-
.init(src: "^/(.*)/$", headers: ["Location": "/$1"], status: 308),
378+
.init(src: "^(?:/((?:[^/]+?)(?:/(?:[^/]+?))*))/$", headers: ["Location": "/$1"], status: 308),
372379
// Handle filesystem
373380
.init(handle: "filesystem"),
374381
// Proxy all other routes
375-
.init(src: "^(?:/(.*))$", dest: product.name, check: true)
382+
.init(src: "^.*$", dest: product.name, check: true)
376383
]
377384
let config = OutputConfiguration(
378385
routes: routes,
@@ -415,6 +422,7 @@ extension VercelOutput {
415422
public struct FunctionConfiguration: Codable {
416423
public var runtime: String = "provided.al2"
417424
public var handler: String = "bootstrap"
425+
public var architecture: Architecture? = nil
418426
public var memory: Int? = nil
419427
public var maxDuration: Int? = nil
420428
public var regions: [String]? = nil
@@ -427,6 +435,7 @@ extension VercelOutput {
427435

428436
public func writeFunctionConfigurations() throws {
429437
let config = FunctionConfiguration(
438+
architecture: architecture,
430439
memory: .init(functionMemory),
431440
maxDuration: .init(functionDuration),
432441
regions: functionRegions?.components(separatedBy: ",").map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
@@ -511,7 +520,7 @@ extension VercelOutput {
511520
executable: dockerToolPath,
512521
arguments: [
513522
"run",
514-
"--platform", "linux/x86_64",
523+
"--platform", "linux/\(architecture.rawValue)",
515524
"--rm",
516525
"-v", "\(context.package.directory.string):/workspace",
517526
"-w", "/workspace",
@@ -529,7 +538,7 @@ extension VercelOutput {
529538
executable: dockerToolPath,
530539
arguments: [
531540
"run",
532-
"--platform", "linux/x86_64",
541+
"--platform", "linux/\(architecture.rawValue)",
533542
"--rm",
534543
"-v", "\(context.package.directory.string):/workspace",
535544
"-w", "/workspace",

0 commit comments

Comments
 (0)