From 70387acf957ce81910828c6b7202982acc3fe328 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 87c342a323..3ae23b021d 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)