Skip to content
Merged
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
42 changes: 30 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

27 changes: 22 additions & 5 deletions src/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import {describe, expect, test, vi, beforeEach, afterEach} from 'vitest'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import {getVExecutable, getWindowsBuildCommand, resolveVersionRef} from './installer'
import {
getVExecutable,
getWindowsBuildCommand,
resolveVersionRef
} from './installer'
import * as githubApiHelper from './github-api-helper'

describe('getVExecutable', () => {
Expand Down Expand Up @@ -62,17 +66,30 @@ describe('getWindowsBuildCommand', () => {
}
})

test('prefers makev.bat when present', () => {
test('prefers makev.bat when present (MSVC by default)', () => {
fs.writeFileSync(path.join(tempDir, 'makev.bat'), '@echo off')
fs.writeFileSync(path.join(tempDir, 'make.bat'), '@echo off')

expect(getWindowsBuildCommand(tempDir)).toBe('.\\makev.bat -gcc')
expect(getWindowsBuildCommand(tempDir)).toBe('.\\makev.bat')
})

test('falls back to make.bat for older releases', () => {
test('uses makev.bat with -gcc when useGcc is true', () => {
fs.writeFileSync(path.join(tempDir, 'makev.bat'), '@echo off')
fs.writeFileSync(path.join(tempDir, 'make.bat'), '@echo off')

expect(getWindowsBuildCommand(tempDir, true)).toBe('.\\makev.bat -gcc')
})

test('falls back to make.bat for older releases (MSVC by default)', () => {
fs.writeFileSync(path.join(tempDir, 'make.bat'), '@echo off')

expect(getWindowsBuildCommand(tempDir)).toBe('.\\make.bat')
})

test('falls back to make.bat with -gcc when useGcc is true', () => {
fs.writeFileSync(path.join(tempDir, 'make.bat'), '@echo off')

expect(getWindowsBuildCommand(tempDir)).toBe('.\\make.bat -gcc')
expect(getWindowsBuildCommand(tempDir, true)).toBe('.\\make.bat -gcc')
})

test('throws when no build script exists', () => {
Expand Down
53 changes: 39 additions & 14 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,54 @@ export async function getVlang({
return installDir
}

export function getWindowsBuildCommand(installDir: string): string {
export function getWindowsBuildCommand(
installDir: string,
useGcc = false
): string {
const gccFlag = useGcc ? ' -gcc' : ''
if (fs.existsSync(path.join(installDir, 'makev.bat'))) {
return '.\\makev.bat -gcc'
return `.\\makev.bat${gccFlag}`
}
if (fs.existsSync(path.join(installDir, 'make.bat'))) {
return '.\\make.bat -gcc'
return `.\\make.bat${gccFlag}`
}
throw new Error(`No Windows build script found in ${installDir}`)
}

function buildV(installDir: string): void {
if (process.platform === 'win32') {
const command = getWindowsBuildCommand(installDir)
// vlang/v CI builds Windows with .\makev.bat (see windows_ci_gcc.yml).
core.info(`Running ${command}...`)
// eslint-disable-next-line no-console
console.log(
execSync(command, {
cwd: installDir,
shell: process.env.ComSpec ?? 'cmd.exe',
stdio: 'pipe'
}).toString()
)
// GHA Windows runners ship MSVC (Visual Studio Build Tools), which
// provides the POSIX-compatible headers V needs to bootstrap. MinGW
// (-gcc) lacks sys/mman.h, termios.h and pthread types, so try MSVC
// first and fall back to GCC only if the MSVC build fails.
try {
const msvcCommand = getWindowsBuildCommand(installDir, false)
core.info(`Running ${msvcCommand} (MSVC)...`)
// eslint-disable-next-line no-console
console.log(
execSync(msvcCommand, {
cwd: installDir,
shell: process.env.ComSpec ?? 'cmd.exe',
stdio: 'pipe'
}).toString()
)
} catch (msvcError) {
const msvcMessage =
msvcError instanceof Error ? msvcError.message : String(msvcError)
core.warning(
`MSVC build failed (${msvcMessage}), falling back to GCC (MinGW)...`
)
const gccCommand = getWindowsBuildCommand(installDir, true)
core.info(`Running ${gccCommand} (GCC)...`)
// eslint-disable-next-line no-console
console.log(
execSync(gccCommand, {
cwd: installDir,
shell: process.env.ComSpec ?? 'cmd.exe',
stdio: 'pipe'
}).toString()
)
}
return
}

Expand Down
Loading