Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/argumentBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join, resolve } from "path"
import type { BuildConfiguration } from "./config-types.d"
import type { Architecture, BuildConfiguration, Platform } from "./config-types.d"
import { getNodeApiInclude } from "./nodeAPIInclude/index.js"
import type { RuntimeDistribution } from "./runtimeDistribution.js"
import { getPathsForConfig } from "./urlRegistry.js"
Expand Down Expand Up @@ -147,7 +147,7 @@ export class ArgumentBuilder {
*
* @note Based on https://stackoverflow.com/a/70498851/7910299
*/
export function getCMakeArchitecture(arch: NodeJS.Architecture, os: NodeJS.Platform) {
export function getCMakeArchitecture(arch: Architecture, os: Platform) {
return os in cmakeArchMap && arch in cmakeArchMap[os]
? cmakeArchMap[os][arch]
: os === "win32"
Expand Down Expand Up @@ -202,4 +202,5 @@ const cmakeSystemNameMap = {
aix: "AIX",
sunos: "SunOS",
haiku: "Haiku",
wasm32: "Emscripten"
} as const
9 changes: 5 additions & 4 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ export async function buildConfig(config: BuildConfiguration, opts: Options) {
await runProgram(buildCmd, buildArgs, stagingDir)

// Copy back the previously built binary
logger.debug(`> Copying ${config.projectName}.node to ${targetDir}`)
const extension = config.os === "wasm32" ? ".wasm" : ".node"
logger.debug(`> Copying ${config.projectName}${extension} to ${targetDir}`)

const addonPath = join(targetDir, `${config.projectName}.node`)
const addonPath = join(targetDir, `${config.projectName}${extension}`)
const sourceAddonPath = config.generatorToUse.includes("Visual Studio")
? join(stagingDir, config.buildType, `${config.projectName}.node`)
: join(stagingDir, `${config.projectName}.node`)
? join(stagingDir, config.buildType, `${config.projectName}${extension}`)
: join(stagingDir, `${config.projectName}${extension}`)
await ensureDir(targetDir)
await retry(() => copy(sourceAddonPath, addonPath))

Expand Down
7 changes: 5 additions & 2 deletions src/config-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,19 @@ export type DeprecatedGlobalOptions = {

export type ArrayOrSingle<T> = T | T[]

type Platform = typeof process.platform | "wasm32"
type Architecture = typeof process.arch | "unknown"

export type BuildConfiguration = {
/** The name of the build configuration. */
name: string

// Platform

/** The operating system that is used by the runtime (e.g. win32, darwin, linux, etc.) */
os: typeof process.platform
os: Platform
/** The architecture that is used by the runtime (e.g. x64, arm64, etc.) */
arch: typeof process.arch
arch: Architecture
/** Whether the build is cross-compiling. */
cross?: boolean

Expand Down
8 changes: 5 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readJson } from "fs-extra"
import which from "which"
import type { BuildCommandOptions, BuildConfiguration, BuildConfigurations, Options } from "./config-types.d"
import type { Architecture, BuildCommandOptions, BuildConfiguration, BuildConfigurations, Options, Platform } from "./config-types.d"
import { getCmakeGenerator } from "./generator.js"
import { logger } from "./lib.js"

Expand Down Expand Up @@ -188,7 +188,7 @@ export function parseBuiltInConfigs(configName: string) {
return { os, arch, runtime, buildType, cross }
}

const platforms = new Set<NodeJS.Platform>([
const platforms = new Set<Platform>([
"aix",
"android",
"darwin",
Expand All @@ -200,9 +200,10 @@ const platforms = new Set<NodeJS.Platform>([
"win32",
"cygwin",
"netbsd",
"wasm32"
])

const architectures = new Set<NodeJS.Architecture>([
const architectures = new Set<Architecture>([
"arm",
"arm64",
"ia32",
Expand All @@ -215,6 +216,7 @@ const architectures = new Set<NodeJS.Architecture>([
"s390",
"s390x",
"x64",
"unknown"
])

const buildTypes = new Map<string, BuildConfiguration["buildType"]>([
Expand Down
5 changes: 3 additions & 2 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import which from "which"
import { getCMakeArchitecture } from "./argumentBuilder.js"
import { execCapture } from "./utils/exec.js"
import { logger } from "./utils/logger.js"
import type { Platform, Architecture } from "./config-types.js"

export const getCmakeGenerator = memoizee(
async (
cmake: string,
os: NodeJS.Platform,
arch: NodeJS.Architecture,
os: Platform,
arch: Architecture,
): Promise<{
generator?: string
generatorFlags?: string[]
Expand Down
4 changes: 2 additions & 2 deletions src/libc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "fs"

export function detectLibc(os: typeof process.platform) {
import type { Platform } from "./config-types.d"
export function detectLibc(os: Platform) {
if (os === "linux") {
if (fs.existsSync("/etc/alpine-release")) {
return "musl"
Expand Down
2 changes: 1 addition & 1 deletion src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function loadAddon<Addon>(buildDir: string): Addon | undefined {
}
}
} catch (err) {
throw new Error(`Failed to load zeromq.js addon.node: ${errorString(err)}`)
throw new Error(`Failed to load zeromq.js addon: ${errorString(err)}`)
}

if (addon === undefined) {
Expand Down
3 changes: 2 additions & 1 deletion test/zeromq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ async function testZeromqBuildResults(config: BuildConfiguration, ctx: Ctx) {
const addonPath = manifest[manifestKey]

// check if the addon.node file exists
const expectedAddonPath = join(os, arch, "node", `${config.libc}-${config.abi}-${buildType}`, "addon.node")
const extension = config.os === "wasm32" ? ".wasm" : ".node"
const expectedAddonPath = join(os, arch, "node", `${config.libc}-${config.abi}-${buildType}`, `addon${extension}`)
expect(addonPath).toEqual(expectedAddonPath)
const addonNodePath = join(ctx.zeromqPath, config.targetDirectory, addonPath)
expect(existsSync(addonNodePath), `Addon node file ${addonNodePath} does not exist`).toBe(true)
Expand Down
Loading