Skip to content

Commit

Permalink
refactor(build): Splits Makefile into smaller ones, moves scripts to …
Browse files Browse the repository at this point in the history
…a separate folder
  • Loading branch information
mishamyrt committed Aug 11, 2023
1 parent 14278f2 commit 94b1006
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[{Makefile,go.mod,go.sum,*.go,.gitmodules}]
[{Makefile,*.mk,go.mod,go.sum,*.go,.gitmodules}]
indent_style = tab
indent_size = 4

Expand Down
116 changes: 10 additions & 106 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,121 +1,25 @@
VERSION = 1.0.0-rc
DIST_PATH = dist
BUILD_PATH = app/build/bin

PLATFORMS_DARWIN = darwin/arm64,darwin/amd64
PLATFORMS_LINUX = linux/arm64,linux/amd64

LD_FLAGS = -X 'nuga_ui/internal/nuga.AppVersion=v$(VERSION)' -s -w
UNAME := $(shell uname)
OS := `echo $(shell uname) | tr A-Z a-z`
ARCH := $(shell arch)

define go_lint
golangci-lint run ./$(1)/...
revive -config ./revive.toml ./$(1)/...
endef

define build_platforms
cd app; wails build \
-clean \
-platform "$(1)" \
-trimpath \
-ldflags "$(LD_FLAGS)"
endef

define pack_darwin_release
mkdir -p "$(DIST_PATH)/$(1)"
mv "$(BUILD_PATH)/Nuga-$(1).app" "$(DIST_PATH)/$(1)/Nuga.app"
cd "$(DIST_PATH)/$(1)"; codesign -fs 'Nuga Developer' --deep Nuga.app
cd "$(DIST_PATH)/$(1)"; zip -9 -y -r -q Nuga.zip Nuga.app
mv "$(DIST_PATH)/$(1)/Nuga.zip" "$(DIST_PATH)/Nuga-$(VERSION)-mac-$(1).zip"
rm -rf "$(DIST_PATH)/$(1)"
endef
include makefiles/build.mk
include makefiles/install.mk
include makefiles/dev.mk
include makefiles/qa.mk
include makefiles/linux-builder.mk

sync:
.PHONY: configure
configure:
go work sync

.PHONY: lint
lint:
make lint-lib
make lint-app

.PHONY: lint-lib
lint-lib:
$(call go_lint,lib)

.PHONY: lint-app
lint-app:
$(call go_lint,app)
cd app/frontend; pnpm run lint
wails doctor

.PHONY: generate
generate:
./utils/update-version.mjs app/wails.json "$(VERSION)"
./scripts/update-version.mjs app/wails.json "$(VERSION)"
cd app; wails generate module

.PHONY: build/Darwin
build/Darwin:
$(call build_platforms,"$(PLATFORMS_DARWIN)")
mkdir -p "$(DIST_PATH)"
$(call pack_darwin_release,arm64)
$(call pack_darwin_release,amd64)

.PHONY: build/Linux
build/Linux:
$(call build_platforms,"$(PLATFORMS_LINUX)")

.PHONY: build
build:
make build/$(UNAME)

.PHONY: build-dumper
build-dumper:
go build -o dist/k916-dumper utils/k916-dumper/main.go

.PHONY: release
release:
make generate
make build/mac
rm -rf "$(DIST_PATH)"
mkdir -p "$(DIST_PATH)"
$(call pack_release,arm64)
$(call pack_release,amd64)

.PHONY: dev
dev:
cd app; wails dev -loglevel Debug -v 2

.PHONY: dev-universal
dev-universal:
cd app; wails dev -ldflags "-X 'nuga_ui/internal/nuga.Universal=true'" -loglevel Debug -v 2

.PHONY: dev-memtest
dev-memtest:
cd app; wails dev -tags memtest -loglevel Debug -v 2

.PHONY: memtest-view
memtest-view:
go tool pprof \
-http=:8081 \
-alloc_space \
http://localhost:8080/debug/pprof/heap

.PHONY: install_Darwin_arm64
install_Darwin_arm64:
rm -rf /Applications/Nuga.app
cd dist; unzip Nuga-*-arm64.zip
mv dist/Nuga.app /Applications/Nuga.app

.PHONY: install_Darwin_amd64
install_Darwin_amd64:
rm -rf /Applications/Nuga.app
cd dist; unzip Nuga-*-amd64.zip
mv dist/Nuga.app /Applications/Nuga.app

.PHONY: install
install:
make install_$(UNAME)_$(ARCH)

.PHONY: clean
clean:
rm -rf app/frontend/node_modules
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For local development, you need to set up environments. For this purpose you wil
#### macOS

```sh
brew install libhid
brew install hidapi
```

### Starting
Expand All @@ -48,12 +48,12 @@ make dev-universal

### Build

Cross-compiling the application is not possible at this time. Therefore, full build is only possible on macOS. Native macOS build is built natively, Linux via x86 Docker container.
Cross-compiling the application is not possible at this time. Therefore, full build is only possible on macOS. A native build for macOS can be built on macs with Intel® and Apple Silicon™ processors , Linux version is built on either macOS (via Docker) or the amd64 version of Linux.

For native builds, there are targets in the Makefile:

* `build/Darwin` – To build macOS app (arm64, amd64)
* `build/Linux` – To build Linux app binary (arm64, amd64)
* `build/darwin` – To build macOS app (arm64, amd64)
* `build/linux` – To build Linux app binary (arm64, amd64)

The `build` command is a common alias for these commands and performs a build on the OS that is currently in use.

Expand Down
44 changes: 44 additions & 0 deletions makefiles/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Nuga build Makefile targets
BUILD_PATH = app/build/bin
PLATFORMS_DARWIN = darwin/arm64,darwin/amd64
LD_FLAGS = -X 'nuga_ui/internal/nuga.AppVersion=v$(VERSION)' -s -w

define build_platforms
cd app; wails build \
-clean \
-platform "$(1)" \
-trimpath \
-ldflags "$(LD_FLAGS)"
endef

define pack_darwin_release
mkdir -p "$(DIST_PATH)/$(1)"
mv "$(BUILD_PATH)/Nuga-$(1).app" "$(DIST_PATH)/$(1)/Nuga.app"
cd "$(DIST_PATH)/$(1)"; codesign -fs 'Nuga Developer' --deep Nuga.app
cd "$(DIST_PATH)/$(1)"; zip -9 -y -r -q Nuga.zip Nuga.app
mv "$(DIST_PATH)/$(1)/Nuga.zip" "$(DIST_PATH)/Nuga-$(VERSION)-mac-$(1).zip"
rm -rf "$(DIST_PATH)/$(1)"
endef

.PHONY: build/darwin
build/darwin:
$(call build_platforms,"$(PLATFORMS_DARWIN)")
mkdir -p "$(DIST_PATH)"
$(call pack_darwin_release,arm64)
$(call pack_darwin_release,amd64)

.PHONY: build/linux
build/linux:
cd app; wails build \
-clean \
-trimpath \
-ldflags "-X 'nuga_ui/internal/nuga.AppVersion=v$(VERSION)' -s -w"


.PHONY: build
build:
make build/$(OS)

.PHONY: build/dumper
build/dumper:
go build -o dist/k916-dumper utils/k916-dumper/main.go
19 changes: 19 additions & 0 deletions makefiles/dev.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Nuga dev Makefile targets
.PHONY: dev
dev:
cd app; wails dev -loglevel Debug -v 2

.PHONY: dev-universal
dev-universal:
cd app; wails dev -ldflags "-X 'nuga_ui/internal/nuga.Universal=true'" -loglevel Debug -v 2

.PHONY: dev-memtest
dev-memtest:
cd app; wails dev -tags memtest -loglevel Debug -v 2

.PHONY: memtest-view
memtest-view:
go tool pprof \
-http=:8081 \
-alloc_space \
http://localhost:8080/debug/pprof/heap
16 changes: 16 additions & 0 deletions makefiles/install.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Nuga install Makefile targets
.PHONY: install/darwin/arm64
install/darwin/arm64:
rm -rf /Applications/Nuga.app
cd dist; unzip Nuga-*-arm64.zip
mv dist/Nuga.app /Applications/Nuga.app

.PHONY: install/darwin/amd64
install/darwin/amd64:
rm -rf /Applications/Nuga.app
cd dist; unzip Nuga-*-amd64.zip
mv dist/Nuga.app /Applications/Nuga.app

.PHONY: install
install:
make install/$(OS)/$(ARCH)
18 changes: 18 additions & 0 deletions makefiles/qa.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
define go_lint
golangci-lint run ./$(1)/...
revive -config ./revive.toml ./$(1)/...
endef

.PHONY: lint
lint:
make lint-lib
make lint-app

.PHONY: lint-lib
lint-lib:
$(call go_lint,lib)

.PHONY: lint-app
lint-app:
$(call go_lint,app)
cd app/frontend; pnpm run lint
11 changes: 9 additions & 2 deletions utils/format-hex-stream.mjs → scripts/format-hex-stream.mjs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env node
// @ts-check
/*
Script for converting Hex Stream from WireShark to a format suitable for Golang arrays
Usage: ./scripts/format-hex-stream.mjs <input_stream>
`input_stream` format is hex pairs without spaces. Like: fffff000...
Output be like: 0xFF, 0xFF, 0xF0, 0x00...
*/

import { argv, exit } from 'process'

/**
Expand All @@ -21,9 +28,9 @@ function main() {
console.log(result)
}

if (argv.length < 4) {
if (argv.length < 3) {
console.error("Too few arguments")
console.log("Usage: update-version.mjs <path> <version>")
console.log("Usage: format-hex-stream.mjs <input_stream>")
exit(1)
}

Expand Down
7 changes: 7 additions & 0 deletions utils/update-version.mjs → scripts/update-version.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env node
// @ts-check
/*
Script to update the version in the wails.json file. In the current build system,
the main version is specified in the Makefile, so it is necessary to update it in other places.
Usage: ./scripts/update-version.mjs <path> <version>
* `path` is the path to wails.json
* `version` is the version that should be included in the final file
*/
import { readFile, writeFile } from 'fs/promises'
import { argv, exit } from 'process'

Expand Down

0 comments on commit 94b1006

Please sign in to comment.