Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tinygo build -o /path/to/out does not create intermediate directories, like go build does #4687

Open
jphastings opened this issue Jan 5, 2025 · 1 comment
Labels

Comments

@jphastings
Copy link

  • go build -o /path/to/out . creates /path/to/ if needed, before starting the build.
  • tinygo build -o /path/to/out . does not create /path/to/` if the directory doesn't exist, failing the build with the slightly confusing message "open /path/to/out: no such file or directory"

This is confusing behaviour, but also makes the use of build tooling, like GoReleaser, challenging as substituting tinygo in for go in the build configuration doesn't work as expected, and throws the error: "open [your output path]: no such file or directory".

Repoducing the issue

Get into a Go project directory that can compile with Go and TinyGo.

# Create a space for the experiment & show the structure
$ mkdir -p /tmp/experiment

$ tree /tmp/experiment
/tmp/experiment

# Build to a directory that does not exist with tinygo: failure
$ tinygo build -o /tmp/experiment/somedir/tinygo-built .
open /tmp/experiment/somedir/tinygo-built: no such file or directory

$ tree /tmp/experiment
/tmp/experiment


# Create the directory manually, then try again: success
$ mkdir /tmp/experiment/somedir
$ tinygo build -o /tmp/experiment/somedir/tinygo-built .

$ tree /tmp/experiment
/tmp/experiment
└── somedir
    └── tinygo-built


# Remove that directory, then build with go instead: success
$ rm -rf /tmp/experiment/somedir
$ tree /tmp/experiment
/tmp/experiment

$ go build -o /tmp/experiment/somedir/go-built .

$ tree /tmp/experiment
/tmp/experiment
└── somedir
    └── go-built
@jphastings
Copy link
Author

For GoReleaser specifically I've found a workaround:

builds:
  - id: your-id
    # Your other build options 
    tool: tinygo
    hooks:
      pre:
        # This dir needs to be made manually because TinyGo doesn't create output directories
        # like Go does. https://github.com/tinygo-org/tinygo/issues/4687
        - mkdir -p {{ dir .Path }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants