Skip to content

Commit

Permalink
fix: Make SPI builds work for macOS (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
hassila authored Apr 18, 2023
1 parent 51066a6 commit d98ed5a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,17 @@ let package = Package(
)
// Check if this is a SPI build, then we need to disable jemalloc for macOS

let spiBuild: Bool
let macOSSPIBuild: Bool // Disables jemalloc for macOS SPI builds as the infrastructure doesn't have jemalloc there

#if canImport(Darwin)
#if os(macOS)
if let spiBuildEnvironment = ProcessInfo.processInfo.environment["SPI_BUILD"], spiBuildEnvironment == "1" {
spiBuild = true
macOSSPIBuild = true
print("Building for SPI@macOS, disabling Jemalloc")
} else {
spiBuild = false
macOSSPIBuild = false
}
#else
spiBuild = false
macOSSPIBuild = false
#endif

// Add Benchmark target dynamically
Expand All @@ -144,10 +145,13 @@ var dependencies: [PackageDescription.Target.Dependency] = [
"SwiftRuntimeHooks",
]

if let disableJemalloc, disableJemalloc != "false", disableJemalloc != "0", spiBuild != false {
} else {
package.dependencies += [.package(url: "https://github.com/ordo-one/package-jemalloc", .upToNextMajor(from: "1.0.0"))]
dependencies += [.product(name: "jemalloc", package: "package-jemalloc")]
if macOSSPIBuild == false { // jemalloc always disable for macOSSPIBuild
if let disableJemalloc, disableJemalloc != "false", disableJemalloc != "0" {
print("Jemalloc disabled through environment variable.")
} else {
package.dependencies += [.package(url: "https://github.com/ordo-one/package-jemalloc", .upToNextMajor(from: "1.0.0"))]
dependencies += [.product(name: "jemalloc", package: "package-jemalloc")]
}
}

package.targets += [.target(name: "Benchmark", dependencies: dependencies)]
Expand Down

0 comments on commit d98ed5a

Please sign in to comment.