diff --git a/.gitignore b/.gitignore index 4db4159..7773828 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -luxtools-client -*.exe -.vscode/ \ No newline at end of file +dist/ \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..94fa3dd --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,45 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug server (default)", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}", + "cwd": "${workspaceFolder}", + "args": [], + "console": "integratedTerminal" + }, + { + "name": "Debug server (port 9000)", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}", + "cwd": "${workspaceFolder}", + "args": ["-listen", "127.0.0.1:9000"], + "console": "integratedTerminal" + }, + { + "name": "Debug install (dry-run)", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}", + "cwd": "${workspaceFolder}", + "args": ["install", "-dry-run"], + "console": "integratedTerminal" + }, + { + "name": "Debug uninstall (dry-run)", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}", + "cwd": "${workspaceFolder}", + "args": ["uninstall", "-dry-run"], + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..ab1e75d --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,19 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "make", + "args": ["build"], + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "reveal": "always", + "panel": "shared" + } + } + ] +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e579dc0 --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +.PHONY: help build build-linux build-windows build-all clean + +APP_NAME := luxtools-client +DIST_DIR := dist + +NATIVE_GOOS := $(shell go env GOOS) +NATIVE_GOARCH := $(shell go env GOARCH) +NATIVE_EXT := $(if $(filter windows,$(NATIVE_GOOS)),.exe,) + +# Native (current platform) +NATIVE_EXE := $(APP_NAME)$(if $(filter windows,$(OS)),.exe,) + +help: + @echo "Targets:" + @echo " make build Build for current platform -> $(DIST_DIR)/$(APP_NAME)$(NATIVE_EXT) ($(NATIVE_GOOS)/$(NATIVE_GOARCH))" + @echo " make build-linux Cross-compile -> $(DIST_DIR)/$(APP_NAME)-linux-amd64" + @echo " make build-windows Cross-compile -> $(DIST_DIR)/$(APP_NAME)-windows-amd64.exe" + @echo " make build-all Build linux + windows artifacts" + @echo " make clean Remove $(DIST_DIR)/" + +$(DIST_DIR): + @mkdir -p $(DIST_DIR) + +build: $(DIST_DIR) + @echo "Building $(APP_NAME) for current platform..." + go build -trimpath -o $(DIST_DIR)/$(APP_NAME)$(NATIVE_EXT) . + +build-linux: $(DIST_DIR) + @echo "Cross-compiling $(APP_NAME) for linux/amd64..." + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -o $(DIST_DIR)/$(APP_NAME)-linux-amd64 . + +build-windows: $(DIST_DIR) + @echo "Cross-compiling $(APP_NAME) for windows/amd64..." + GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -o $(DIST_DIR)/$(APP_NAME)-windows-amd64.exe . + +build-all: build-linux build-windows + +clean: + @rm -rf $(DIST_DIR) diff --git a/README.md b/README.md index 59418f5..232a7d8 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,24 @@ This program runs on the user’s machine and listens on a loopback address only Requires Go 1.22+. ```bash -go build -o luxtools-client . +make build +``` + +Output: + +- `dist/luxtools-client` (or `dist/luxtools-client.exe` on Windows) + +### Cross-compile + +```bash +# Linux (amd64) +make build-linux + +# Windows (amd64) +make build-windows + +# Both +make build-all ``` ## Run