Skip to content

Commit 86e215a

Browse files
committed
🔥 Remove statical linking of PRQL
PRQL is a rust library that offers an alternative to SQL. Because it's written with rust, it causes a lot of issues with statical linking. This commit removes the statical linking of PRQL and instead uses the prqlc binary to compile the PRQL queries. Due to this change, users are now required to install the prqlc binary to compile the PRQL queries. Documentation has therefore been updated to reflect this change. Also, thanks to this changes, it's now easier to compile anyquery for Linux. .goreleaser.yaml doesn't use an external VM anymore to compile for Linux and now uses the zig cc compiler.
1 parent 1fc1da7 commit 86e215a

19 files changed

+36
-863
lines changed

.goreleaser.yaml

+4-7
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,25 @@ builds:
4242
goarch: arm64
4343

4444
- id: linux
45-
gobinary: ./orbstack_go.sh
4645
tags:
4746
- vtable
4847
- fts5
4948
- sqlite_json
5049
- sqlite_math_functions
51-
- prql
5250

5351
ldflags:
5452
- -s -w
5553
- -X "main.version={{.Version}}"
5654
env:
5755
- CGO_ENABLED=1
58-
- "ORBENV=CGO_ENABLED:CC:CGO_CFLAGS:CGO_LDFLAGS:GOOS:GOARCH"
5956
- CGO_CFLAGS=-O2
6057
- >-
6158
{{- if eq .Os "linux" }}
62-
{{- if eq .Arch "amd64" }}CC=musl-gcc{{- end }}
63-
{{- if eq .Arch "arm64" }}CC=aarch64-linux-gnu-gcc{{- end }}
59+
{{- if eq .Arch "amd64" }}CC=zig cc -target x86_64-linux-musl{{- end }}
60+
{{- if eq .Arch "arm64" }}CC=zig cc -target aarch64-linux-musl{{- end }}
6461
{{- end }}
65-
- >-
66-
{{- if eq .Arch "amd64" }}CGO_LDFLAGS=-static{{- end }}
62+
# - >-
63+
# {{- if eq .Arch "amd64" }}CGO_LDFLAGS=-static{{- end }}
6764

6865
goos:
6966
- linux

cmd/query.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ func init() {
4848

4949
// Alternative language flags
5050
queryCmd.Flags().String("language", "", "Alternative language to use")
51-
queryCmd.Flags().Bool("prql", false, "Use the PRQL language")
51+
queryCmd.Flags().Bool("prql", false, "Use the PRQL language (requires prqlc in PATH)")
5252
queryCmd.Flags().Bool("pql", false, "Use the PQL language")
5353
}

cmd/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ func init() {
5858

5959
// Alternative language flags
6060
rootCmd.Flags().String("language", "", "Alternative language to use")
61-
rootCmd.Flags().Bool("prql", false, "Use the PRQL language")
61+
rootCmd.Flags().Bool("prql", false, "Use the PRQL language (requires prqlc in PATH)")
6262
rootCmd.Flags().Bool("pql", false, "Use the PQL language")
6363
}

makefile

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ BUILD_FLAGS := "-ldflags=-s -w"
1313
all: $(FILES)
1414
go build -o main.out -tags "$(TAGS)" $(BUILD_FLAGS) $(FILES)
1515

16-
prql: $(FILES)
17-
go build -o main.out -tags "$(TAGS) prql" $(BUILD_FLAGS) $(FILES)
18-
1916
clean:
2017
rm -f main.out
2118

orbstack_go.sh

-4
This file was deleted.

other/prql/.cargo/config.toml

-1
This file was deleted.

other/prql/.gitignore

-11
This file was deleted.

other/prql/Cargo.toml

-22
This file was deleted.

other/prql/cbindgen.toml

-14
This file was deleted.

other/prql/createLib.mjs

-53
This file was deleted.

other/prql/prql.go

+23-53
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,32 @@
1-
//go:build prql
2-
31
package prql
42

5-
// #cgo CFLAGS: -I.
6-
// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR} -lprqlc-aarch64-apple-darwin
7-
// #cgo darwin,amd64 LDFLAGS: -L${SRCDIR} -lprqlc-x86_64-apple-darwin
8-
// #cgo linux,arm64 LDFLAGS: -L${SRCDIR} -lprqlc-aarch64-unknown-linux-musl
9-
// #cgo linux,amd64 LDFLAGS: -L${SRCDIR} -lprqlc-x86_64-unknown-linux-musl -lm
10-
// #cgo windows,amd64 LDFLAGS: -L${SRCDIR} -lprqlc-x86_64-pc-windows-gnu -lws2_32 -luserenv -lntdll
11-
/*#include <stdlib.h>
12-
#include "prqlc.h"
13-
14-
Options global_options = {
15-
false, // Remove the pretty print
16-
"sql.sqlite", // The dialect to use
17-
false // Remove the trailing comments
18-
};
19-
20-
CompileResult to_sql(char *prql_query) {
21-
return compile(prql_query, &global_options);
22-
}
23-
24-
*/
25-
import "C"
26-
273
import (
28-
"unsafe"
4+
"fmt"
5+
"os/exec"
6+
"strings"
297
)
308

9+
// Calls the prqlc CLI to compile the PRQL query to SQL
3110
func ToSQL(prqlQuery string) (string, []CompileMessage) {
32-
res := C.to_sql(C.CString(prqlQuery))
33-
a := res.messages
34-
if res.messages_len > 0 {
35-
messages := make([]CompileMessage, res.messages_len)
36-
// Convert the messages
37-
for i := 0; i < int(res.messages_len); i++ {
38-
message := (*C.struct_Message)(unsafe.Pointer(uintptr(unsafe.Pointer(a)) + uintptr(i)*unsafe.Sizeof(*res.messages)))
39-
compileMessage := CompileMessage{}
40-
if message.code != nil && *message.code != nil {
41-
compileMessage.ErrorCode = rune(**message.code)
42-
}
43-
44-
if message.display != nil && *message.display != nil {
45-
compileMessage.Display = C.GoString(*message.display)
46-
}
47-
48-
if message.location != nil {
49-
compileMessage.LocationError.StartLine = int(message.location.start_line)
50-
compileMessage.LocationError.StartColumn = int(message.location.start_col)
51-
compileMessage.LocationError.EndLine = int(message.location.end_line)
52-
compileMessage.LocationError.EndColumn = int(message.location.end_col)
53-
}
54-
55-
messages[i] = compileMessage
56-
57-
}
11+
_, err := exec.LookPath("prqlc")
12+
if err != nil {
13+
return "", []CompileMessage{{
14+
ErrorCode: 'E',
15+
Display: "prqlc not found in PATH.\nMake sure it is installed: https://prql-lang.org/book/project/integrations/prqlc-cli.html#installation",
16+
}}
17+
}
5818

59-
return "", messages
19+
// prqlc compile --target sql.sqlite"
20+
cmd := exec.Command("prqlc")
21+
cmd.Args = append(cmd.Args, "compile", "--target", "sql.sqlite")
22+
cmd.Stdin = strings.NewReader(prqlQuery)
23+
out, err := cmd.CombinedOutput()
24+
if err != nil {
25+
return "", []CompileMessage{{
26+
ErrorCode: 'E',
27+
Display: fmt.Sprintf("prqlc failed with error %s: %s", err, string(out)),
28+
}}
6029
}
61-
return C.GoString(res.output), nil
30+
31+
return string(out), nil
6232
}

other/prql/prql_blank.go

-7
This file was deleted.

0 commit comments

Comments
 (0)