11import { bold , cyan , yellow } from "jsr:@std/fmt@1/colors" ;
22import { ensureDeps } from "./deps.ts" ;
33import {
4+ BuildTool ,
5+ buildToolToCommand ,
46 exec ,
57 getEnvVars ,
68 getHostTriple ,
79 getSysrootEnv ,
8- needsCross ,
10+ needsCrossCompile ,
911 stripBinary ,
1012} from "./util.ts" ;
1113
1214// Build library
1315export async function buildLib ( target ?: string , debug = false ) {
1416 const host = getHostTriple ( ) ;
15- const useCross = needsCross ( host , target ) ;
17+ const buildTool = needsCrossCompile ( host , target ) ;
1618
1719 // Ensure dependencies are set up
1820 await ensureDeps ( target ) ;
1921
2022 console . log (
2123 cyan ( bold ( "Building" ) ) +
22- ` libdivvun_runtime ${ debug ? yellow ( "DEBUG" ) : bold ( "release" ) } for target: ${
23- bold ( target || host )
24- } ` +
25- ( useCross ? " " + yellow ( "(cross)" ) : "" ) ,
24+ ` libdivvun_runtime ${
25+ debug ? yellow ( "DEBUG" ) : bold ( "release" )
26+ } for target: ${ bold ( target || host ) } ` +
27+ ( buildTool !== BuildTool . Cargo ? " " + yellow ( `( ${ buildTool } )` ) : "" ) ,
2628 ) ;
2729
28- const command = useCross ? "cross" : "cargo" ;
29- const args = [ command , "build" , "--features" , "ffi" ] ;
30+ const baseCmd = buildToolToCommand ( buildTool ) ;
31+ const args = [ ... baseCmd , "build" , "--features" , "ffi" ] ;
3032
3133 if ( ! debug ) {
3234 args . push ( "--release" ) ;
@@ -38,7 +40,7 @@ export async function buildLib(target?: string, debug = false) {
3840
3941 // Add sysroot env vars if cross-compiling
4042 const env = { ...getEnvVars ( target ) } ;
41- if ( useCross && target ) {
43+ if ( buildTool !== BuildTool . Cargo && target ) {
4244 Object . assign ( env , getSysrootEnv ( target ) ) ;
4345 }
4446
@@ -48,7 +50,7 @@ export async function buildLib(target?: string, debug = false) {
4850// Build CLI
4951export async function build ( target ?: string , debug = false ) {
5052 const host = getHostTriple ( ) ;
51- const useCross = needsCross ( host , target ) ;
53+ const buildTool = needsCrossCompile ( host , target ) ;
5254
5355 // Ensure dependencies are set up
5456 await ensureDeps ( target ) ;
@@ -58,12 +60,12 @@ export async function build(target?: string, debug = false) {
5860 ` CLI (${ debug ? yellow ( "debug" ) : bold ( "release" ) } ) for target: ${
5961 bold ( target || host )
6062 } ` +
61- ( useCross ? " " + yellow ( "(cross)" ) : "" ) ,
63+ ( buildTool !== BuildTool . Cargo ? " " + yellow ( `( ${ buildTool } )` ) : "" ) ,
6264 ) ;
6365
64- const command = useCross ? "cross" : "cargo" ;
66+ const baseCmd = buildToolToCommand ( buildTool ) ;
6567 const args = [
66- command ,
68+ ... baseCmd ,
6769 "build" ,
6870 "-p" ,
6971 "divvun-runtime-cli" ,
@@ -86,7 +88,7 @@ export async function build(target?: string, debug = false) {
8688
8789 // Add sysroot env vars if cross-compiling
8890 Object . assign ( env , getEnvVars ( target ) ) ;
89- if ( useCross && target ) {
91+ if ( buildTool !== BuildTool . Cargo && target ) {
9092 Object . assign ( env , getSysrootEnv ( target ) ) ;
9193 }
9294
@@ -99,7 +101,7 @@ export async function build(target?: string, debug = false) {
99101// Check CLI
100102export async function check ( target ?: string , debug = false ) {
101103 const host = getHostTriple ( ) ;
102- const useCross = needsCross ( host , target ) ;
104+ const buildTool = needsCrossCompile ( host , target ) ;
103105
104106 // Ensure dependencies are set up
105107 await ensureDeps ( target ) ;
@@ -109,12 +111,12 @@ export async function check(target?: string, debug = false) {
109111 ` CLI (${ debug ? yellow ( "debug" ) : bold ( "release" ) } ) for target: ${
110112 bold ( target || host )
111113 } ` +
112- ( useCross ? " " + yellow ( "(cross)" ) : "" ) ,
114+ ( buildTool !== BuildTool . Cargo ? " " + yellow ( `( ${ buildTool } )` ) : "" ) ,
113115 ) ;
114116
115- const command = useCross ? "cross" : "cargo" ;
117+ const baseCmd = buildToolToCommand ( buildTool ) ;
116118 const args = [
117- command ,
119+ ... baseCmd ,
118120 "check" ,
119121 "-p" ,
120122 "divvun-runtime-cli" ,
@@ -137,7 +139,7 @@ export async function check(target?: string, debug = false) {
137139
138140 // Add sysroot env vars if cross-compiling
139141 Object . assign ( env , getEnvVars ( target ) ) ;
140- if ( useCross && target ) {
142+ if ( buildTool !== BuildTool . Cargo && target ) {
141143 Object . assign ( env , getSysrootEnv ( target ) ) ;
142144 }
143145
0 commit comments