Skip to content

Commit

Permalink
feat: zig (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanHope authored Dec 4, 2023
1 parent 1bef737 commit 3d693eb
Show file tree
Hide file tree
Showing 42 changed files with 925 additions and 125 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Setup Task
uses: arduino/setup-task@v1
with:
version: 3.x
- name: Setup golangci-lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.1
- name: Install Nix
uses: cachix/install-nix-action@v22
- name: Build
run: task build
shell: nix develop --command bash -e {0}
- name: Test
run: task test
shell: nix develop --command bash -e {0}
- name: Lint
run: task lint
shell: nix develop --command bash -e {0}
7 changes: 3 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Task
uses: arduino/setup-task@v1
with:
version: 3.x
- name: Install Nix
uses: cachix/install-nix-action@v22
- name: Release
run: task release
shell: nix develop --command bash -e {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155 changes: 121 additions & 34 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,131 @@ env:
- CGO_ENABLED=1

builds:
- id: armaria-darwin-amd64
# - id: armaria-darwin-amd64
# binary: armaria
# main: ./cmd/cli
# goarch:
# - amd64
# goos:
# - darwin
# env:
# - CC=zig cc -target x86_64-macos-none -g0
# - CXX=zig c++ -target x86_64-macos-none -g0
# flags:
# - -trimpath
# - -tags=fts5 netgo osusergo
# - -buildmode=pie
# ldflags:
# - -s
# - -w

# - id: armaria-darwin-arm64
# binary: armria
# main: ./cmd/cli
# goarch:
# - arm64
# goos:
# - darwin
# env:
# - CC=zig cc -target aarch64-macos-none -g0
# - CXX=zig c++ -target aarch64-macos-none -g0
# flags:
# - -trimpath
# - -tags=fts5 netgo osusergo
# - -buildmode=pie
# ldflags:
# - -s
# - -w

- id: armaria-linux-amd64
binary: armaria
main: ./cmd/cli
env:
- CC=zig cc -target x86_64-linux-musl -g0
- CXX=zig c++ -target x86_64-linux-musl -g0
# https://github.com/mattn/go-sqlite3/issues/1164
- CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
goarch:
- amd64
goos:
- darwin
env:
- CC=o64-clang
- CXX=o64-clang++
- linux
flags:
- -trimpath
- -tags=fts5
ldflags:
- -s
- -w

- id: armaria-darwin-arm64
binary: armria
main: ./cmd/cli
- id: armaria-host-linux-amd64
binary: armaria-host
main: ./cmd/host
env:
- CC=zig cc -target x86_64-linux-musl -g0
- CXX=zig c++ -target x86_64-linux-musl -g0
# https://github.com/mattn/go-sqlite3/issues/1164
- CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
goarch:
- arm64
- amd64
goos:
- darwin
env:
- CC=oa64-clang
- CXX=oa64-clang++
- linux
flags:
- -trimpath
- -tags=fts5

- id: armaria-linux-amd64
ldflags:
- -s
- -w

- id: armaria-windows-amd64
binary: armaria
main: ./cmd/cli
env:
- CC=x86_64-linux-gnu-gcc
- CXX=x86_64-linux-gnu-g++
goarch:
- amd64
goos:
- linux
- windows
env:
- CC=zig cc -target x86_64-windows-gnu -g0
- CXX=zig c++ -target x86_64-windows-gnu -g0
flags:
- -trimpath
- -buildmode=exe
- -tags=fts5
ldflags:
- -extldflags "-lc -lrt -lpthread --static"
- -s
- -w
- id: armaria-windows-amd64
binary: armaria
main: ./cmd/cli

- id: armaria-host-windows-amd64
binary: armaria-host
main: ./cmd/host
goarch:
- amd64
goos:
- windows
env:
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
- CC=zig cc -target x86_64-windows-gnu -g0
- CXX=zig c++ -target x86_64-windows-gnu -g0
flags:
- -trimpath
- -buildmode=exe
- -tags=fts5
ldflags:
- -s
- -w

universal_binaries:
- id: armaria-darwin-universal
ids:
- armaria-darwin-amd64
- armaria-darwin-arm64
replace: true
name_template: "armaria"
# universal_binaries:
# - id: armaria-darwin-universal
# ids:
# - armaria-darwin-amd64
# - armaria-darwin-arm64
# replace: true
# name_template: "armaria"

archives:
- id: w/version
builds:
- armaria-darwin-universal
- armaria-linux-amd64
- armaria-host-linux-amd64
- armaria-windows-amd64
- armaria-host-windows-amd64
name_template: "armaria_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: false
format: zip
Expand All @@ -86,8 +136,45 @@ archives:
checksum:
name_template: 'checksums.txt'

gomod:
proxy: true

snapshot:
name_template: "{{ incpatch .Version }}-next"

changelog:
sort: asc

sboms:
- artifacts: archive

snapcrafts:
- id: armaria-snap
builds:
- armaria-linux-amd64
- armaria-host-linux-amd64
name_template: "armaria_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
name: armaria
title: Armaria
icon: ./art/icon-light.svg
# publish: true
summary: Armaria is a fast local-first bookmark manager.
description: Armaria is a FOSS bookmarks manager that keeps all of your local bookmarks in a SQLite database. You can use many different frontends to manage your bookmarks including browsers, and back them up and/or sync them however you see fit.
confinement: strict
license: MIT
base: core18
apps:
armaria:
command: armaria
plugs: ["armaria-dot-mozilla", "armaria-dot-chrome"]
armaria-host:
command: armaria-host
plugs:
armaria-dot-mozilla:
interface: personal-files
write:
- $HOME/.mozilla/native-messaging-hosts
armaria-dot-chrome:
interface: personal-files
write:
- $HOME/.config/google-chrome/NativeMessagingHosts
7 changes: 5 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ tasks:
- find . -name "*.db-wal" -type f -delete
release:
cmds:
- docker run -v $(pwd):/src -w /src -e GITHUB_TOKEN=$GITHUB_TOKEN -i goreleaser/goreleaser-cross:v1.20 release
- goreleaser release
release-snapshot:
cmds:
- docker run -v $(pwd):/src -w /src -i goreleaser/goreleaser-cross:v1.20 release --snapshot
- goreleaser release --snapshot --clean
install-native-manifest:
cmds:
- mkdir -p ~/.mozilla/native-messaging-hosts/
- cp armaria.json ~/.mozilla/native-messaging-hosts/
copy-snap:
cmds:
- scp dist/armaria_0.0.6-next_linux_amd64.snap [email protected]:/home/jhope
16 changes: 16 additions & 0 deletions art/icon-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions art/icon-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 60 additions & 2 deletions cmd/cli/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

"github.com/jonathanhope/armaria"
"github.com/jonathanhope/armaria/pkg/api"
"github.com/jonathanhope/armaria/pkg/model"
)

// RootCmd is the top level CLI command for Armaria.
Expand All @@ -19,7 +19,8 @@ type RootCmd struct {
Update UpdateCmd `cmd:"" help:"Update a folder or bookmark."`
List ListCmd `cmd:"" help:"List folders, bookmarks, or tags."`

Config ConfigCmd `cmd:"" help:"Manage the configuration."`
Config ConfigCmd `cmd:"" help:"Manage the configuration."`
Manifest ManifestCmd `cmd:"" help:"Manage the app manifest."`
}

// RootCmdFactory creates a new RootCmd.
Expand Down Expand Up @@ -67,6 +68,17 @@ type DBConfigCmd struct {
Set SetDBConfigCmd `cmd:"" help:"Set the location of the bookmarks database in the configuration."`
}

// ManifestCmd is a CLI command to manage the app manifest.
type ManifestCmd struct {
Install InstallManifestCmd `cmd:"" help:"Install the app manifest"`
}

// InstallManifestCmd is a CLI command to the app manifest.
type InstallManifestCmd struct {
Firefox InstallFirefoxManifestCmd `cmd:"" help:"Install the app manifest for Firefox."`
Chrome InstallChromeManifestCmd `cmd:"" help:"Install the app manifest for Chrome."`
}

// AddBookCmd is a CLI command to add a bookmark.
type AddBookCmd struct {
Folder *string `help:"Folder to add this bookmark to."`
Expand Down Expand Up @@ -677,3 +689,49 @@ func (r *SetDBConfigCmd) Run(ctx *Context) error {

return nil
}

// InstallFirefoxManifestCmd is a CLI command to install the app manifest for Firefox.
type InstallFirefoxManifestCmd struct {
}

// Run install app manifest for Firefox.
func (r *InstallFirefoxManifestCmd) Run(ctx *Context) error {
start := time.Now()

err := armariaapi.InstallManifestFirefox()

if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
return nil
}

elapsed := time.Since(start)

formatSuccess(ctx.Writer, ctx.Formatter, fmt.Sprintf("Installed in %s", elapsed))

return nil
}

// InstallChromeManifestCmd is a CLI command to install the app manifest for Chrome.
type InstallChromeManifestCmd struct {
}

// Run install app manifest for Chrome.
func (r *InstallChromeManifestCmd) Run(ctx *Context) error {
start := time.Now()

err := armariaapi.InstallManifestChrome()

if err != nil {
formatError(ctx.Writer, ctx.Formatter, err)
ctx.ReturnCode(1)
return nil
}

elapsed := time.Since(start)

formatSuccess(ctx.Writer, ctx.Formatter, fmt.Sprintf("Installed in %s", elapsed))

return nil
}
Loading

0 comments on commit 3d693eb

Please sign in to comment.