Skip to content

Commit

Permalink
Merge pull request #840 from hardliner66/use_exe_for_windows
Browse files Browse the repository at this point in the history
Use proper .exe extension on windows
  • Loading branch information
emil14 authored Jan 22, 2025
2 parents 3cd0540 + 6853c5d commit dd02589
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions internal/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"

"github.com/nevalang/neva/internal/compiler"

Expand Down Expand Up @@ -49,13 +50,18 @@ func newRunCmd(workdir string, nativec compiler.Compiler) *cli.Command {
return err
}

fileName := "output"
if runtime.GOOS == "windows" {
fileName += ".exe"
}

defer func() {
if err := os.Remove(filepath.Join(workdir, "output")); err != nil {
if err := os.Remove(filepath.Join(workdir, fileName)); err != nil {
fmt.Println("failed to remove output file:", err)
}
}()

pathToExec := filepath.Join(workdir, "output")
pathToExec := filepath.Join(workdir, fileName)

cmd := exec.CommandContext(cliCtx.Context, pathToExec)
cmd.Stdin = os.Stdin
Expand Down
8 changes: 7 additions & 1 deletion internal/compiler/backend/golang/native/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"

"github.com/nevalang/neva/internal/compiler/backend/golang"
"github.com/nevalang/neva/internal/compiler/ir"
Expand Down Expand Up @@ -48,12 +49,17 @@ func (b Backend) buildExecutable(gomodule, output string) error {
}
}()

fileName := "output"
if runtime.GOOS == "windows" {
fileName += ".exe"
}

cmd := exec.Command(
"go",
"build",
"-ldflags", "-s -w", // strip debug information
"-o",
filepath.Join(output, "output"),
filepath.Join(output, fileName),
gomodule,
)
cmd.Stdout = os.Stdout
Expand Down

0 comments on commit dd02589

Please sign in to comment.