Skip to content

Commit e3ada86

Browse files
authored
Merge pull request #48 from EmbeddedEnterprises/glibc-conflict
fix: prevent conflict between binaries
2 parents 0a59e8c + 549247d commit e3ada86

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/build.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ export async function buildConfig(config: BuildConfiguration, opts: Options) {
7979

8080
logger.debug("> Building directories... ")
8181

82-
const stagingDir = resolve(
83-
join(config.stagingDirectory, config.os, config.arch, config.runtime, `${dist.abi()}`, config.addonSubdirectory),
84-
)
85-
const targetDir = resolve(
86-
join(config.targetDirectory, config.os, config.arch, config.runtime, `${dist.abi()}`, config.addonSubdirectory),
82+
const subDirectory = join(
83+
config.os,
84+
config.arch,
85+
config.runtime,
86+
`${config.libc}-${dist.abi()}-${config.buildType}`,
87+
config.addonSubdirectory,
8788
)
89+
90+
const stagingDir = resolve(join(config.stagingDirectory, subDirectory))
91+
const targetDir = resolve(join(config.targetDirectory, subDirectory))
8892
logger.debug("[ DONE ]")
8993

9094
logger.debug("> Applying overrides... ")
@@ -150,6 +154,18 @@ Build Type: ${config.buildType}
150154
manifest = JSON.parse(manifestContent)
151155
}
152156
// add the new entry to the manifest
153-
manifest[JSON.stringify(config)] = relative(config.targetDirectory, addonPath)
157+
manifest[serializeConfig(config, config.packageDirectory)] = relative(config.targetDirectory, addonPath)
154158
await writeFile(manifestPath, JSON.stringify(manifest, null, 2))
155159
}
160+
161+
function serializeConfig(config: BuildConfiguration, rootDir: string) {
162+
// replace absolute paths with relative paths
163+
const serialized = JSON.stringify(config, (_key, value) => {
164+
if (typeof value === "string" && value.startsWith(rootDir)) {
165+
return relative(rootDir, value)
166+
}
167+
return value
168+
})
169+
170+
return serialized
171+
}

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export type BuildConfiguration = {
176176
// Optimization levels
177177

178178
/** Release, Debug, or RelWithDebInfo build */
179-
buildType: string
179+
buildType: "Release" | "Debug" | "RelWithDebInfo"
180180
/** Whether the build is a development build. */
181181
dev: boolean
182182

@@ -388,7 +388,7 @@ const architectures = new Set<NodeJS.Architecture>([
388388
"x64",
389389
])
390390

391-
const buildTypes = new Map<BuildConfiguration["buildType"], BuildConfiguration["buildType"]>([
391+
const buildTypes = new Map<string, BuildConfiguration["buildType"]>([
392392
["release", "Release"],
393393
["debug", "Debug"],
394394
["relwithdebinfo", "RelWithDebInfo"],

test/zeromq.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ suite("zeromq", { timeout: 300_000 }, async () => {
5959
runtime: "node",
6060
runtimeVersion: process.versions.node,
6161
buildType: "Release",
62-
packageDirectory: zeromqPath,
62+
packageDirectory: "",
6363
projectName: "addon",
6464
nodeAPI: "node-addon-api",
65-
targetDirectory: await realpath(join(zeromqPath, "build")),
66-
stagingDirectory: await realpath(join(zeromqPath, "staging")),
65+
targetDirectory: "build",
66+
stagingDirectory: "staging",
6767
cmakeToUse: await which("cmake"),
6868
generatorToUse: "Ninja",
6969
generatorBinary: await which("ninja"),
@@ -75,7 +75,13 @@ suite("zeromq", { timeout: 300_000 }, async () => {
7575
}
7676

7777
expect(configKey.abi).toBeDefined()
78-
const addonPath = join(process.platform, process.arch, "node", configKey.abi!.toString(), "addon.node")
78+
const addonPath = join(
79+
process.platform,
80+
process.arch,
81+
"node",
82+
`${configKey.libc}-${configKey.abi}-${configKey.buildType}`,
83+
"addon.node",
84+
)
7985

8086
expect(configKey).toEqual(expectedConfig)
8187
expect(configValue).toEqual(addonPath)

0 commit comments

Comments
 (0)