Skip to content

Commit be772a1

Browse files
authored
More module fixes (#15)
* Fix framework structure * more fixes * imports
1 parent d6d93bc commit be772a1

File tree

14 files changed

+25
-12
lines changed

14 files changed

+25
-12
lines changed

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ let package = Package(
3030
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"),
3131
],
3232
targets: [
33-
.target(name: "CNodeAPI"),
33+
.systemLibrary(name: "CNodeAPI"),
34+
.target(name: "CNodeAPISupport"),
3435
.macro(
3536
name: "NodeAPIMacros",
3637
dependencies: [
@@ -41,7 +42,7 @@ let package = Package(
4142
),
4243
.target(
4344
name: "NodeAPI",
44-
dependencies: ["CNodeAPI", "NodeAPIMacros"],
45+
dependencies: ["CNodeAPI", "CNodeAPISupport", "NodeAPIMacros"],
4546
swiftSettings: baseSwiftSettings
4647
),
4748
.target(

Sources/CNodeAPI/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module CNodeAPI {
2+
export Darwin.POSIX
3+
header "vendored/node_api.h"
4+
}

Sources/NodeAPI/NodeActor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import CNodeAPISupport
23
@_implementationOnly import CNodeAPI
34

45
extension NodeContext {

Sources/NodeAPI/NodeContext.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import CNodeAPISupport
23
@_implementationOnly import CNodeAPI
34

45
extension NodeEnvironment {

Sources/NodeModuleSupport/register.c renamed to Sources/NodeModuleSupport/register.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "vendored/node_api.h"
1+
@import CNodeAPI;
22

33
NAPI_MODULE_INIT() {
44
napi_value node_swift_register(napi_env);

src/builder.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { rm, rename, realpath } from "fs/promises";
2-
import { spawnSync } from "child_process";
2+
import { spawn, spawnSync } from "child_process";
33
import { forceSymlink } from "./utils";
44
import path from "path";
55
import { isDeepStrictEqual } from "util";
@@ -270,25 +270,31 @@ export async function build(mode: BuildMode, config: Config = {}): Promise<strin
270270
throw new Error(`xcodebuild exited with status ${result.status}`);
271271
}
272272

273+
// the exec realpath must end with .node for it to be considered a native module.
273274
await Promise.all([
274275
rename(
275276
originalBinary,
276-
// the realpath must end with .node for it to be considered a native module.
277277
path.join(binaryDir, `${product}.framework`, "Versions", "A", `${product}.node`)
278278
),
279-
forceSymlink(
280-
`${product}.node`,
281-
// fixes symlinks that point to the binary without the .node ext
282-
originalBinary
283-
),
284-
// convenience
279+
rm(path.join(binaryDir, `${product}.framework`, `${product}`), { force: true }),
285280
forceSymlink(
286281
path.join("Versions", "Current", `${product}.node`),
287282
path.join(binaryDir, `${product}.framework`, `${product}.node`)
288283
),
289284
forceSymlink(
290285
path.join(`${product}.framework`, `${product}.node`),
291-
path.join(binaryDir, `${product}.node`)
286+
binaryPath
287+
),
288+
spawn(
289+
"/usr/libexec/PlistBuddy",
290+
[
291+
"-c",
292+
`Set :CFBundleExecutable ${product}.node`,
293+
path.join(binaryDir, `${product}.framework`, "Resources", "Info.plist"),
294+
],
295+
{
296+
stdio: "inherit",
297+
}
292298
),
293299
]);
294300
} else {

0 commit comments

Comments
 (0)