Skip to content

Commit a02702d

Browse files
authored
bin/sqlc: Add SQLCTMPDIR environment variable (#2189)
* bin/sqlc: Add SQLCTMPDIR environment variable If specified, use the given directory as the base for temporary folders. Only applies when using WASM-based codegen plugins. * Use non-deprecated function * docs: Add SQLCCACHE and SQLCTMPDIR to reference
1 parent 6ec6f51 commit a02702d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

docs/reference/environment-variables.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Environment variables
22

3+
## SQLCCACHE
4+
5+
The `SQLCCACHE` environment variable dictates where `sqlc` will store cached
6+
WASM-based plugins and modules. By default `sqlc` follows the [XDG Base
7+
Directory
8+
Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html).
9+
310
## SQLCDEBUG
411

512
The `SQLCDEBUG` variable controls debugging variables within the runtime. It is
@@ -110,3 +117,18 @@ log showing the execution time for each package.
110117
0.046042779 . 5148212 1 region writefiles started (duration: 1.718259ms)
111118
0.047767781 . 1725002 1 task end
112119
```
120+
121+
### processplugins
122+
123+
Setting this value to `0` disables process-based plugins. If a process-based
124+
plugin is declared in the configuration file, running any `sqlc` command will
125+
return an error.
126+
127+
`SQLCDEBUG=processplugins=0`
128+
129+
## SQLCTMPDIR
130+
131+
If specified, use the given directory as the base for temporary folders. Only
132+
applies when using WASM-based codegen plugins. When not specified, this
133+
defaults to passing an empty string to
134+
[`os.MkdirTemp`](https://pkg.go.dev/os#MkdirTemp).

internal/ext/wasm/wasm.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"errors"
1212
"fmt"
1313
"io"
14-
"io/ioutil"
1514
"net/http"
1615
"os"
1716
"path/filepath"
@@ -236,7 +235,7 @@ func (r *Runner) Generate(ctx context.Context, req *plugin.CodeGenRequest) (*plu
236235
return nil, err
237236
}
238237

239-
dir, err := ioutil.TempDir("", "out")
238+
dir, err := os.MkdirTemp(os.Getenv("SQLCTMPDIR"), "out")
240239
if err != nil {
241240
return nil, fmt.Errorf("temp dir: %w", err)
242241
}

0 commit comments

Comments
 (0)