Skip to content

Commit

Permalink
windows dev support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgerlag committed Aug 29, 2024
1 parent 332d7f5 commit 5dfa25c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
42 changes: 34 additions & 8 deletions cli/Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

VERSION ?= latest
ifeq ($(OS),Windows_NT)
IS_WINDOWS := true
else
IS_WINDOWS := false
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
ifeq ($(OS),Windows_NT)
SHELL := powershell.exe
DELIM := ;
else
SHELL := /usr/bin/env bash -o pipefail
.SHELLFLAGS := -ec
DELIM := :
endif

VERSION ?= latest

DRASI_LOCATION ?= /usr/local/bin/drasi
DRASI_LOCATION ?= $(if $(filter $(OS),Windows_NT),$(shell $$Env:ProgramFiles)\drasi\,/usr/local/bin/)

.PHONY: all
all: fmt vet
ifeq ($(IS_WINDOWS),true)
$$env:GOOS = "windows"; $$env:GOARCH = "amd64"; go build -ldflags "-X drasi.io/cli/config.version=$(VERSION)" -o bin/windows-x64/drasi.exe main.go
$$env:GOOS = "linux"; $$env:GOARCH = "amd64"; go build -ldflags "-X drasi.io/cli/config.version=$(VERSION)" -o bin/linux-x64/drasi main.go
$$env:GOOS = "linux"; $$env:GOARCH = "arm64"; go build -ldflags "-X drasi.io/cli/config.version=$(VERSION)" -o bin/linux-arm64/drasi main.go
$$env:GOOS = "darwin"; $$env:GOARCH = "amd64"; go build -ldflags "-X drasi.io/cli/config.version=$(VERSION)" -o bin/darwin-x64/drasi main.go
$$env:GOOS = "darwin"; $$env:GOARCH = "arm64"; go build -ldflags "-X drasi.io/cli/config.version=$(VERSION)" -o bin/darwin-arm64/drasi main.go
else
GOOS=windows GOARCH=amd64 go build -ldflags "-X drasi.io/cli/config.version=$(VERSION)" -o bin/windows-x64/drasi.exe main.go
GOOS=linux GOARCH=amd64 go build -ldflags "-X drasi.io/cli/config.version=$(VERSION)" -o bin/linux-x64/drasi main.go
GOOS=linux GOARCH=arm64 go build -ldflags "-X drasi.io/cli/config.version=$(VERSION)" -o bin/linux-arm64/drasi main.go
GOOS=darwin GOARCH=amd64 go build -ldflags "-X drasi.io/cli/config.version=$(VERSION)" -o bin/darwin-x64/drasi main.go
GOOS=darwin GOARCH=arm64 go build -ldflags "-X drasi.io/cli/config.version=$(VERSION)" -o bin/darwin-arm64/drasi main.go
endif

.PHONY: fmt
fmt:
Expand All @@ -33,10 +49,20 @@ vet:

.PHONY: build
build: fmt vet
ifeq ($(IS_WINDOWS),true)
go build -ldflags "-X drasi.io/cli/config.Version=$(VERSION)" -o bin/drasi.exe main.go
else
go build -ldflags "-X drasi.io/cli/config.Version=$(VERSION)" -o bin/drasi main.go
endif

.PHONY: install
install: build ## Installs a local build for development

ifeq ($(IS_WINDOWS),true)
@echo "Installing Drasi";
New-Item -ItemType Directory -Path "$(DRASI_LOCATION)" -Force; Copy-Item -Path bin\drasi.exe -Destination "$(DRASI_LOCATION)" -Force; $$currentPath = (Get-Item -Path HKCU:\Environment).GetValue('Path', $$null, 'DoNotExpandEnvironmentNames'); if (-Not ($$currentPath -like '*$(DRASI_LOCATION)*')) { Set-ItemProperty HKCU:\Environment "PATH" "$$currentPath;$(DRASI_LOCATION)" -Type ExpandString; $$env:PATH += ";$(DRASI_LOCATION)" }
else
@echo "Installing Drasi"
cp ./bin/drasi $(DRASI_LOCATION)
endif

10 changes: 10 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,19 @@ bin/darwin-arm64/drasi

## Installing a local build


### MacOS

You can use the Makefile to install a local build of Drasi. By default this will install to `/usr/local/bin/drasi`. You may also need to specify `sudo` depending on the destination and its permissions.

```sh
sudo make install
```

### Windows

You can use the Makefile to install a local build of Drasi. By default this will install to `Program Files\drasi`. You may also need to run the command in an elavated terminal.

```sh
make install
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Depending on the task you need to perform, you may need to install more tools, b

## Operating system

We support developing on macOS, Linux and Windows with [WSL](https://docs.microsoft.com/windows/wsl/install).
We support developing on macOS, Linux and Windows.

## Development environment

Expand Down Expand Up @@ -47,6 +47,14 @@ Using Homebrew:
brew install make
```

#### Windows

Using Chocolatey

```bash
choco install make
```

### Enable Git Hooks

We use pre-commit hooks to catch some issues early, enable the local git hooks using the following commands
Expand Down

0 comments on commit 5dfa25c

Please sign in to comment.