From c1b267a208d996dcf3210b4b7fc06910ac0581f3 Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Sat, 18 Jan 2025 18:53:09 +0000 Subject: [PATCH] Ensure build output directory is created `tinygo build -o /path/to/out .` expected `/path/to/out` to already exist, which is different behaviour to `go build`. This change ensures tinygo creates any directories needed to be able to build to the specified output dir. --- builder/build.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builder/build.go b/builder/build.go index 87c342a32..3ae23b021 100644 --- a/builder/build.go +++ b/builder/build.go @@ -604,6 +604,11 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe }, } + // Create the output directory, if needed + if err := os.MkdirAll(filepath.Dir(outpath), 0777); err != nil { + return result, err + } + // Check whether we only need to create an object file. // If so, we don't need to link anything and will be finished quickly. outext := filepath.Ext(outpath)