Handle PowerShell vs. Git Bash on Windows (#6207)

This commit is contained in:
Jace Browning
2025-04-08 19:47:56 -04:00
committed by GitHub
parent 997f539a8c
commit 4c6ef841bb

View File

@ -5,33 +5,40 @@ all: install build check
# INSTALL # INSTALL
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
CARGO ?= ~/.cargo/bin/cargo.exe export WINDOWS := true
WASM_PACK ?= ~/.cargo/bin/wasm-pack.exe ifndef MSYSTEM
else export POWERSHELL := true
CARGO ?= ~/.cargo/bin/cargo
WASM_PACK ?= ~/.cargo/bin/wasm-pack
endif endif
endif
ifdef WINDOWS
CARGO ?= $(USERPROFILE)/.cargo/bin/cargo.exe
WASM_PACK ?= $(USERPROFILE)/.cargo/bin/wasm-pack.exe
else
CARGO ?= ~/.cargo/bin/cargo
WASM_PACK ?= ~/.cargo/bin/wasm-pack
endif
.PHONY: install .PHONY: install
install: node_modules/.yarn-integrity $(CARGO) $(WASM_PACK) ## Install dependencies install: node_modules/.yarn-integrity $(CARGO) $(WASM_PACK) ## Install dependencies
node_modules/.yarn-integrity: package.json yarn.lock node_modules/.yarn-integrity: package.json yarn.lock
yarn install yarn install
ifeq ($(OS),Windows_NT) ifdef POWERSHELL
@ type nul > $@ @ type nul > $@
else else
@ touch $@ @ touch $@
endif endif
$(CARGO): $(CARGO):
ifeq ($(OS),Windows_NT) ifdef WINDOWS
yarn install:rust:windows yarn install:rust:windows
else else
yarn install:rust yarn install:rust
endif endif
$(WASM_PACK): $(WASM_PACK):
ifeq ($(OS),Windows_NT) ifdef WINDOWS
yarn install:wasm-pack:cargo yarn install:wasm-pack:cargo
else else
yarn install:wasm-pack:sh yarn install:wasm-pack:sh
@ -57,7 +64,7 @@ build-web: install public/kcl_wasm_lib_bg.wasm build/index.html
build-desktop: install public/kcl_wasm_lib_bg.wasm .vite/build/main.js build-desktop: install public/kcl_wasm_lib_bg.wasm .vite/build/main.js
public/kcl_wasm_lib_bg.wasm: $(CARGO_SOURCES) $(RUST_SOURCES) public/kcl_wasm_lib_bg.wasm: $(CARGO_SOURCES) $(RUST_SOURCES)
ifeq ($(OS),Windows_NT) ifdef WINDOWS
yarn build:wasm:dev:windows yarn build:wasm:dev:windows
else else
yarn build:wasm:dev yarn build:wasm:dev
@ -140,8 +147,8 @@ endif
.PHONY: clean .PHONY: clean
clean: ## Delete all artifacts clean: ## Delete all artifacts
ifeq ($(OS),Windows_NT) ifdef POWERSHELL
git clean --force -d -X git clean --force -d -x --exclude=.env* --exclude=**/*.env
else else
rm -rf .vite/ build/ rm -rf .vite/ build/
rm -rf trace.zip playwright-report/ test-results/ rm -rf trace.zip playwright-report/ test-results/
@ -152,7 +159,7 @@ endif
.PHONY: help .PHONY: help
help: install help: install
ifeq ($(OS),Windows_NT) ifdef POWERSHELL
@ powershell -Command "Get-Content $(MAKEFILE_LIST) | Select-String -Pattern '^[^\s]+:.*##\s.*$$' | ForEach-Object { $$line = $$_.Line -split ':.*?##\s+'; Write-Host -NoNewline $$line[0].PadRight(30) -ForegroundColor Cyan; Write-Host $$line[1] }" @ powershell -Command "Get-Content $(MAKEFILE_LIST) | Select-String -Pattern '^[^\s]+:.*##\s.*$$' | ForEach-Object { $$line = $$_.Line -split ':.*?##\s+'; Write-Host -NoNewline $$line[0].PadRight(30) -ForegroundColor Cyan; Write-Host $$line[1] }"
else else
@ grep -E '^[^[:space:]]+:.*## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @ grep -E '^[^[:space:]]+:.*## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'