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

[WIP] Python bindings proof of concept #241

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Conversation

beauby
Copy link
Contributor

@beauby beauby commented May 22, 2024

Build:

$ (cd sql && skargo build -r --lib)
$ cd pyskdb && pip install .

Run:

$ python -c "import skdb; skdb.exec('CREATE TABLE foo(a INTEGER, b \
TEXT, c FLOAT); INSERT INTO foo VALUES (1337, \'hello\', \
3.14159267), (42, \'foo\', 2e64)'); print(skdb.exec('SELECT * FROM \
foo'))"
[{'a': 42, 'b': 'foo', 'c': 2e+64}, {'a': 1337, 'b': 'hello', 'c': 3.14159267}]

beauby added 21 commits May 21, 2024 10:59
This commit makes `skc` invokations cleaner by passing relative paths
to sources files.
This has not been an issue so far because the `build/` directory would
be explicitly created when building the `build.sk` for `std`, which so
far has always been the first thing to be built during a `skargo
build` run.
This package is intended to be used in custom build scripts in order
to link against system libraries.
This package is meant to be used in custom build scripts in order to
build simple C/C++ extensions.
Some places used `ginfo->fileName == NULL` to check whether persistent
allocation was enabled, while other places checked `gmutex ==
NULL`. This commit makes all checks `ginfo->fileName == NULL`.
Also define `SKIP_LIBRARY`/`SKIP_BINARY` when compiling
`runtime64_specific.cpp`.
Example usage:
- Define an exported function within skdb, for instance:
```
// src/skdb_main.sk

@export("skdb_main")
untracked fun skdb_main(): void {
  SKDB.main()
}
```
Note: while it may be tempting to just `@export("skdb_main")` the
actual `SKDB.main()`, this would clash with the compiler exporting it
as `skip_main` so that the runtime picks it up.
- Call it from C:
```
// foo.c

// Forward-declare the exported function.
void skdb_main();

int main() {
  // Just call it. The shared library constructor will initialize the runtime.
  skdb_main();

  return 0;
}
```
- Build and run:
```
$ skargo build
$ clang -lskdb -Ltarget/host/dev foo.c -o foo
$ LD_LIBRARY_PATH=target/host/dev ./foo
```
The `end` global variable is a non-standard symbol whose address is
the first valid address beyond the bss segment. Having it non-static
in `obstack.c` causes issues when loading `libskdb.so`.
@beauby beauby force-pushed the cdylib2 branch 2 times, most recently from d3df1ce to 4b6bde4 Compare May 22, 2024 17:27
Build:
```
$ (cd sql && skargo build -r --lib)
$ cd pyskdb && pip install .
```

Run:
```
$ python -c "import skdb; skdb.exec('CREATE TABLE foo(a INTEGER, b \
TEXT, c FLOAT); INSERT INTO foo VALUES (1337, \'hello\', \
3.14159267), (42, \'foo\', 2e64)'); print(skdb.exec('SELECT * FROM \
foo'))"
[{'a': 42, 'b': 'foo', 'c': 2e+64}, {'a': 1337, 'b': 'hello', 'c': 3.14159267}]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant