Skip to content

Commit

Permalink
fix(cli): use shell file path instead of commands for zig CC and CXX
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Mar 13, 2022
1 parent 1cac0ac commit 09ccfaa
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions cli/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,18 @@ export class BuildCommand extends Command {
throw new Error(`${triple.raw} can not be cross compiled by zig`)
}
const paths = envPaths('napi-rs')
const shellFileExt = process.platform === 'win32' ? 'bat' : 'sh'
const linkerWrapperShell = join(
paths.cache,
`zig-cc-${triple.raw}.${process.platform === 'win32' ? 'bat' : 'sh'}`,
`zig-linker-${triple.raw}.${shellFileExt}`,
)
const CCWrapperShell = join(
paths.cache,
`zig-cc-${triple.raw}.${shellFileExt}`,
)
const CXXWrapperShell = join(
paths.cache,
`zig-cxx-${triple.raw}.${shellFileExt}`,
)
const linkerWrapper = join(paths.cache, `zig-cc-${triple.raw}.js`)
mkdirSync(paths.cache, { recursive: true })
Expand All @@ -256,6 +265,20 @@ export class BuildCommand extends Command {
mode: '777',
},
)
await writeFileAsync(
CCWrapperShell,
`#!/bin/sh\nzig cc -target ${zigTarget} ${forwardArgs}`,
{
mode: '777',
},
)
await writeFileAsync(
CXXWrapperShell,
`#!/bin/sh\nzig c++ -target ${zigTarget} ${forwardArgs}`,
{
mode: '777',
},
)
await writeFileAsync(
linkerWrapper,
`#!/usr/bin/env node\nconst{writeFileSync} = require('fs')\n${processZigLinkerArgs.toString()}\nconst {status} = require('child_process').spawnSync('zig', ['${
Expand All @@ -272,10 +295,10 @@ export class BuildCommand extends Command {
)
const envTarget = triple.raw.replaceAll('-', '_').toUpperCase()
Object.assign(additionalEnv, {
CC: `zig cc -target ${zigTarget}`,
CXX: `zig c++ -target ${zigTarget}`,
TARGET_CC: `zig cc -target ${zigTarget}`,
TARGET_CXX: `zig c++ -target ${zigTarget}`,
CC: CCWrapperShell,
CXX: CXXWrapperShell,
TARGET_CC: CCWrapperShell,
TARGET_CXX: CXXWrapperShell,
})
additionalEnv[`CARGO_TARGET_${envTarget}_LINKER`] = linkerWrapperShell
}
Expand Down

0 comments on commit 09ccfaa

Please sign in to comment.