Skip to content

Commit

Permalink
feat: build wasi binary (#1)
Browse files Browse the repository at this point in the history
* feat: symlink relatively

* feat: build wasi binary
  • Loading branch information
tyhopp authored Sep 21, 2024
1 parent b773480 commit d8188fe
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ jobs:
lenv-freebsd-arm64
lenv-openbsd-amd64
lenv-openbsd-arm64
lenv-wasip1.wasm
LICENSE
body: ${{ env.changelog }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ lenv-darwin-arm64
lenv-freebsd-amd64
lenv-freebsd-arm64
lenv-openbsd-amd64
lenv-openbsd-arm64
lenv-openbsd-arm64
lenv-wasip1.wasm
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ build: deps
GOOS=freebsd GOARCH=arm64 go build -ldflags="-s -w" -trimpath -o lenv-freebsd-arm64 ./cmd/lenv/main.go
GOOS=openbsd GOARCH=amd64 go build -ldflags="-s -w" -trimpath -o lenv-openbsd-amd64 ./cmd/lenv/main.go
GOOS=openbsd GOARCH=arm64 go build -ldflags="-s -w" -trimpath -o lenv-openbsd-arm64 ./cmd/lenv/main.go
GOOS=wasip1 GOARCH=wasm go build -ldflags="-s -w" -trimpath -o lenv-wasip1.wasm ./cmd/lenv/main.go
13 changes: 10 additions & 3 deletions lenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ func Check(source string, destinations []string) error {
if err != nil {
panic(err)
}
if link == source {
relSource, err := filepath.Rel(filepath.Dir(destination), source)
if err != nil {
return fmt.Errorf("lenv: failed to get relative path from %s to %s", destination, source)
}
if link == relSource {
fmt.Printf("lenv: symlink links %s to %s\n", source, destination)
} else {
return fmt.Errorf("lenv: symlink %s does not link to %s, it should be removed", destination, source)
Expand Down Expand Up @@ -119,8 +123,11 @@ func Link(source string, destinations []string) error {
return fmt.Errorf("lenv: physical file at %s should be removed first", destination)
}
}

err = os.Symlink(source, destination)
relSource, err := filepath.Rel(filepath.Dir(destination), source)
if err != nil {
return fmt.Errorf("lenv: failed to get relative path from %s to %s", destination, source)
}
err = os.Symlink(relSource, destination)
if err != nil {
return fmt.Errorf("lenv: failed to symlink %s to %s", source, destination)
}
Expand Down

0 comments on commit d8188fe

Please sign in to comment.