Skip to content

Commit

Permalink
Support arm64 Lambdas (#17)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AndrewBarba authored Aug 28, 2023
1 parent 15d2598 commit 28339fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Plugins/VercelPackager/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import PackagePlugin

public enum Architecture: String {
public enum Architecture: String, Codable {
case arm64 = "arm64"
case x86 = "x86_64"
}
Expand Down
17 changes: 13 additions & 4 deletions Plugins/VercelPackager/VercelOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ extension VercelOutput {
argument("port") ?? "7676"
}

public var architecture: Architecture {
if let value = argument("arch"), let arch = Architecture(rawValue: value) {
return arch
}
return Utils.currentArchitecture ?? .x86
}

public func argument(_ key: String) -> String? {
guard let index = arguments.firstIndex(of: "--\(key)") else {
return nil
Expand Down Expand Up @@ -368,11 +375,11 @@ extension VercelOutput {
let vercel = vercelConfiguration()
let routes: [OutputConfiguration.Route] = [
// Remove trailing slash
.init(src: "^/(.*)/$", headers: ["Location": "/$1"], status: 308),
.init(src: "^(?:/((?:[^/]+?)(?:/(?:[^/]+?))*))/$", headers: ["Location": "/$1"], status: 308),
// Handle filesystem
.init(handle: "filesystem"),
// Proxy all other routes
.init(src: "^(?:/(.*))$", dest: product.name, check: true)
.init(src: "^.*$", dest: product.name, check: true)
]
let config = OutputConfiguration(
routes: routes,
Expand Down Expand Up @@ -415,6 +422,7 @@ extension VercelOutput {
public struct FunctionConfiguration: Codable {
public var runtime: String = "provided.al2"
public var handler: String = "bootstrap"
public var architecture: Architecture? = nil
public var memory: Int? = nil
public var maxDuration: Int? = nil
public var regions: [String]? = nil
Expand All @@ -427,6 +435,7 @@ extension VercelOutput {

public func writeFunctionConfigurations() throws {
let config = FunctionConfiguration(
architecture: architecture,
memory: .init(functionMemory),
maxDuration: .init(functionDuration),
regions: functionRegions?.components(separatedBy: ",").map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
Expand Down Expand Up @@ -511,7 +520,7 @@ extension VercelOutput {
executable: dockerToolPath,
arguments: [
"run",
"--platform", "linux/x86_64",
"--platform", "linux/\(architecture.rawValue)",
"--rm",
"-v", "\(context.package.directory.string):/workspace",
"-w", "/workspace",
Expand All @@ -529,7 +538,7 @@ extension VercelOutput {
executable: dockerToolPath,
arguments: [
"run",
"--platform", "linux/x86_64",
"--platform", "linux/\(architecture.rawValue)",
"--rm",
"-v", "\(context.package.directory.string):/workspace",
"-w", "/workspace",
Expand Down

0 comments on commit 28339fe

Please sign in to comment.