Skip to content

Commit f1baa63

Browse files
committed
windows build support, untested
Signed-off-by: Connor Braa <connor@dagger.io>
1 parent e3aabe8 commit f1baa63

File tree

10 files changed

+164
-34
lines changed

10 files changed

+164
-34
lines changed

.goreleaser.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ builds:
1616
goos:
1717
- linux
1818
- darwin
19+
- windows
1920
goarch:
2021
- amd64
2122
- arm64

cmd/cu/main.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,8 @@ func init() {
6262
)
6363
}
6464

65-
func handleSIGUSR(sigusrCh <-chan os.Signal) {
66-
for sig := range sigusrCh {
67-
if sig == syscall.SIGUSR1 {
68-
dumpStacks()
69-
}
70-
}
71-
}
72-
7365
func main() {
74-
sigusrCh := make(chan os.Signal, 1)
75-
signal.Notify(sigusrCh, syscall.SIGUSR1)
76-
77-
go handleSIGUSR(sigusrCh)
66+
setupPlatformSignals()
7867

7968
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
8069
defer stop()

cmd/cu/signals_unix.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//go:build unix
2+
3+
package main
4+
5+
import (
6+
"os"
7+
"os/signal"
8+
"syscall"
9+
)
10+
11+
func setupPlatformSignals() {
12+
sigusrCh := make(chan os.Signal, 1)
13+
signal.Notify(sigusrCh, syscall.SIGUSR1)
14+
go handleSIGUSR(sigusrCh)
15+
}
16+
17+
func handleSIGUSR(sigusrCh <-chan os.Signal) {
18+
for sig := range sigusrCh {
19+
if sig == syscall.SIGUSR1 {
20+
dumpStacks()
21+
}
22+
}
23+
}

cmd/cu/signals_windows.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build windows
2+
3+
package main
4+
5+
import (
6+
"os"
7+
)
8+
9+
func setupPlatformSignals() {
10+
// Windows doesn't support SIGUSR1, so this is a no-op
11+
}
12+
13+
func handleSIGUSR(sigusrCh <-chan os.Signal) {
14+
// Windows doesn't support SIGUSR1, so this is a no-op
15+
}

cmd/cu/terminal.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package main
22

33
import (
4-
"errors"
5-
"fmt"
64
"log/slog"
75
"os"
8-
"os/exec"
9-
"syscall"
106

117
"dagger.io/dagger"
128
"github.com/dagger/container-use/environment"
@@ -24,14 +20,7 @@ var terminalCmd = &cobra.Command{
2420
// FIXME(aluzzardi): This is a hack to make sure we're wrapped in `dagger run` since `Terminal()` only works with the CLI.
2521
// If not, it will auto-wrap this command in a `dagger run`.
2622
if _, ok := os.LookupEnv("DAGGER_SESSION_TOKEN"); !ok {
27-
daggerBin, err := exec.LookPath("dagger")
28-
if err != nil {
29-
if errors.Is(err, exec.ErrNotFound) {
30-
return fmt.Errorf("dagger is not installed. Please install it from https://docs.dagger.io/install/")
31-
}
32-
return fmt.Errorf("failed to look up dagger binary: %w", err)
33-
}
34-
return syscall.Exec(daggerBin, append([]string{"dagger", "run"}, os.Args...), os.Environ())
23+
return execDagger(os.Args)
3524
}
3625

3726
dag, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))

cmd/cu/terminal_unix.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//go:build unix
2+
3+
package main
4+
5+
import (
6+
"errors"
7+
"fmt"
8+
"os"
9+
"os/exec"
10+
"syscall"
11+
)
12+
13+
func execDagger(args []string) error {
14+
daggerBin, err := exec.LookPath("dagger")
15+
if err != nil {
16+
if errors.Is(err, exec.ErrNotFound) {
17+
return fmt.Errorf("dagger is not installed. Please install it from https://docs.dagger.io/install/")
18+
}
19+
return fmt.Errorf("failed to look up dagger binary: %w", err)
20+
}
21+
return syscall.Exec(daggerBin, append([]string{"dagger", "run"}, args...), os.Environ())
22+
}

cmd/cu/terminal_windows.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//go:build windows
2+
3+
package main
4+
5+
import (
6+
"errors"
7+
"fmt"
8+
"os"
9+
"os/exec"
10+
)
11+
12+
func execDagger(args []string) error {
13+
daggerBin, err := exec.LookPath("dagger")
14+
if err != nil {
15+
if errors.Is(err, exec.ErrNotFound) {
16+
return fmt.Errorf("dagger is not installed. Please install it from https://docs.dagger.io/install/")
17+
}
18+
return fmt.Errorf("failed to look up dagger binary: %w", err)
19+
}
20+
21+
cmd := exec.Command(daggerBin, append([]string{"run"}, args...)...)
22+
cmd.Stdout = os.Stdout
23+
cmd.Stderr = os.Stderr
24+
cmd.Stdin = os.Stdin
25+
26+
err = cmd.Run()
27+
if err != nil {
28+
if exitError, ok := err.(*exec.ExitError); ok {
29+
os.Exit(exitError.ExitCode())
30+
}
31+
return err
32+
}
33+
34+
os.Exit(0)
35+
return nil
36+
}

cmd/cu/watch.go renamed to cmd/cu/watch_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build unix
2+
13
package main
24

35
import (

cmd/cu/watch_windows.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//go:build windows
2+
3+
package main
4+
5+
import (
6+
"context"
7+
"fmt"
8+
"os"
9+
"os/exec"
10+
"time"
11+
12+
"github.com/spf13/cobra"
13+
)
14+
15+
var watchCmd = &cobra.Command{
16+
Use: "watch",
17+
Short: "Watch git log output",
18+
Long: `Watch the following git log command every second: 'git log --color=always --remotes=container-use --oneline --graph --decorate'.`,
19+
RunE: func(app *cobra.Command, _ []string) error {
20+
ctx := app.Context()
21+
ticker := time.NewTicker(time.Second)
22+
defer ticker.Stop()
23+
24+
// Run once immediately
25+
if err := runGitLog(ctx); err != nil {
26+
return err
27+
}
28+
29+
for {
30+
select {
31+
case <-ctx.Done():
32+
return ctx.Err()
33+
case <-ticker.C:
34+
if err := runGitLog(ctx); err != nil {
35+
return err
36+
}
37+
}
38+
}
39+
},
40+
}
41+
42+
func runGitLog(ctx context.Context) error {
43+
// Clear screen (Windows cmd equivalent)
44+
clearCmd := exec.CommandContext(ctx, "cmd", "/c", "cls")
45+
clearCmd.Stdout = os.Stdout
46+
clearCmd.Run() // Ignore errors for clearing screen
47+
48+
// Run git log command
49+
cmd := exec.CommandContext(ctx, "git", "log", "--color=always", "--remotes=container-use", "--oneline", "--graph", "--decorate")
50+
cmd.Stdout = os.Stdout
51+
cmd.Stderr = os.Stderr
52+
53+
if err := cmd.Run(); err != nil {
54+
fmt.Fprintf(os.Stderr, "Error running git log: %v\n", err)
55+
return err
56+
}
57+
58+
return nil
59+
}
60+
61+
func init() {
62+
rootCmd.AddCommand(watchCmd)
63+
}

go.sum

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
dagger.io/dagger v0.18.9 h1:IXZhlGm893LuqYFpo6VHtaCAEP6Qz0VjMhLvyKQVl1Y=
2-
dagger.io/dagger v0.18.9/go.mod h1:e6Y+sAPWh04pHvBf4s3sSiOe1QMoCEcccmMv898RnZA=
31
dagger.io/dagger v0.18.10 h1:Ibyz5LqxjjEHfLMlaU9PJ3xt3ju7p29RWy0lVfvSNU0=
42
dagger.io/dagger v0.18.10/go.mod h1:VSj+2HMd/EnaCVt7gTY70p8LBW+oQDYjA1XTadr8vBE=
53
github.com/99designs/gqlgen v0.17.74 h1:1FuVtkXxOc87xpKio3f6sohREmec+Jvy86PcYOuwgWo=
@@ -109,29 +107,21 @@ go.opentelemetry.io/proto/otlp v1.7.0 h1:jX1VolD6nHuFzOYso2E73H85i92Mv8JQYk0K9vz
109107
go.opentelemetry.io/proto/otlp v1.7.0/go.mod h1:fSKjH6YJ7HDlwzltzyMj036AJ3ejJLCgCSHGj4efDDo=
110108
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
111109
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
112-
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
113-
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
114110
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
115111
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
116-
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
117-
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
118112
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
119113
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
120114
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
121115
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
122116
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
123117
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
124118
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
125-
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
126-
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
127119
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
128120
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
129121
google.golang.org/genproto/googleapis/api v0.0.0-20250603155806-513f23925822 h1:oWVWY3NzT7KJppx2UKhKmzPq4SRe0LdCijVRwvGeikY=
130122
google.golang.org/genproto/googleapis/api v0.0.0-20250603155806-513f23925822/go.mod h1:h3c4v36UTKzUiuaOKQ6gr3S+0hovBtUrXzTG/i3+XEc=
131123
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 h1:fc6jSaCT0vBduLYZHYrBBNY4dsWuvgyff9noRNDdBeE=
132124
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
133-
google.golang.org/grpc v1.72.2 h1:TdbGzwb82ty4OusHWepvFWGLgIbNo1/SUynEN0ssqv8=
134-
google.golang.org/grpc v1.72.2/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
135125
google.golang.org/grpc v1.73.0 h1:VIWSmpI2MegBtTuFt5/JWy2oXxtjJ/e89Z70ImfD2ok=
136126
google.golang.org/grpc v1.73.0/go.mod h1:50sbHOUqWoCQGI8V2HQLJM0B+LMlIUjNSZmow7EVBQc=
137127
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=

0 commit comments

Comments
 (0)