Skip to content

Commit

Permalink
feat(sqlite): add native sqlite support + module
Browse files Browse the repository at this point in the history
- feat(sqlite): add native sqlite driver
- feat(js): add js module for sqlite access
- test: add testsuite for sqlite
- test: add guest-side tests for sqlite (js)
- chore: update runtime modules
- chore: update to latest sqlite jdbc/jni version

Signed-off-by: Sam Gammon <sam@elide.ventures>
  • Loading branch information
sgammon committed Jun 4, 2024
1 parent c7014ca commit 7b356b2
Show file tree
Hide file tree
Showing 129 changed files with 26,241 additions and 437 deletions.
3 changes: 3 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ ignore:
- "packages/cli/src/main/kotlin/elide/tool/engine/NativeUtil.kt"
- "packages/cli/src/main/kotlin/elide/tool/testing/TestContext.kt"
- "packages/*/src/commonMain/**/*.*"
- "packages/runtime/**/*.*"
- "packages/transport/**/*.*"
- "packages/sqlite/**/*.*"
1 change: 1 addition & 0 deletions .github/workflows/checks.apicheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
egress-policy: block
allowed-endpoints: >
api.github.com:443
objects.githubusercontent.com:443
d3ob9fqp587by1.cloudfront.net:443
download.oracle.com:443
maven.elide.dev:443
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/job.build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ jobs:
repo.maven.apache.org:443
scans-in.gradle.com:443
services.gradle.org:443
- name: "Setup: Clear Tooling Cache"
run: rm -rf /opt/hostedtoolcache
- name: "Setup: Checkout"
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
Expand Down Expand Up @@ -294,8 +296,11 @@ jobs:
java-version: "22"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: "Setup: Buildless"
if: contains(matrix.machine, 'macos') == false
if: false # temporarily disabled
uses: buildless/setup@30e82389418c7f17046606183bc4c78b2c8913e0 # v1.0.2
- name: "Setup: Compiler Environment"
run: |
ldd --version
- name: "Setup: Node"
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
Expand All @@ -317,6 +322,8 @@ jobs:
create_credentials_file: true
export_environment_variables: true
cleanup_credentials: true
- name: "🛠️ Build Third-party"
run: make third-party
- name: "🛠️ Build Natives (Debug)"
run: cargo build
- name: "🛠️ Build Natives (Release)"
Expand Down
31 changes: 30 additions & 1 deletion .github/workflows/job.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ jobs:
uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0
with:
disable-sudo: true
egress-policy: block
egress-policy: audit
allowed-endpoints: >
agent.less.build:443
static.rust-lang.org:443
androidx.dev:443
api.codecov.io:443
api.foojay.io:443
Expand Down Expand Up @@ -198,6 +199,8 @@ jobs:
services.gradle.org:443
sonarcloud.io:443
storage.googleapis.com:443
- name: "Setup: Clear Tooling Cache"
run: rm -rf /opt/hostedtoolcache
- name: "Setup: Checkout"
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
Expand Down Expand Up @@ -254,6 +257,25 @@ jobs:
restore-keys: |
elide-framework-v1-tests-${{ hashFiles('gradle/elide.versions.toml') }}
elide-framework-v1-tests-
- name: "Setup: Rust"
uses: actions-rust-lang/setup-rust-toolchain@b113a30d27a8e59c969077c0a0168cc13dab5ffc # v1.8.0
with:
toolchain: stable
target: wasm32-wasi
components: clippy,rustfmt
cache: false
rustflags: ""
- name: "Setup: Zig"
uses: goto-bus-stop/setup-zig@7ab2955eb728f5440978d5824358023be3a2802d # v2.2.0
- name: "Setup: SCCache"
uses: mozilla-actions/sccache-action@2e7f9ec7921547d4b46598398ca573513895d0bd # v0.0.4
if: false
- name: "Setup: Rust Caching"
if: false && github.event_name != 'release' && github.event_name != 'workflow_dispatch'
run: |
cargo install cargo-zigbuild
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
- name: "Setup: GraalVM (Java 22)"
uses: graalvm/setup-graalvm@2f25c0caae5b220866f732832d5e3e29ff493338 # v1.2.1
with:
Expand All @@ -269,6 +291,7 @@ jobs:
export_environment_variables: true
cleanup_credentials: true
- name: "Setup: Buildless"
if: false
uses: buildless/setup@30e82389418c7f17046606183bc4c78b2c8913e0 # v1.0.2
- name: "Setup: Node"
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
Expand All @@ -288,6 +311,12 @@ jobs:
continue-on-error: true
with:
merge-multiple: true
- name: "🛠️ Build Third-party"
run: make third-party
- name: "🛠️ Build Natives (Debug)"
run: cargo build
- name: "🛠️ Build Natives (Release)"
run: cargo build --release
- name: "Testsuite"
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2
env:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@
[submodule "truffleruby"]
path = third_party/graalvm/truffleruby
url = https://github.com/oracle/truffleruby.git
[submodule "sqlite"]
path = third_party/sqlite
url = git@github.com:sqlite/sqlite.git
14 changes: 14 additions & 0 deletions LICENSES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,17 @@ Updated: 2021-05-15

Outdated base version: https://github.com/primer/github-syntax-dark
Current colors taken from GitHub's CSS

--------------------

SQLite

SQLite is in the public domain.
https://www.sqlite.org/copyright.html

--------------------

SQLite JDBC

Released under Apache License 2.0
https://github.com/xerial/sqlite-jdbc/blob/master/LICENSE
2 changes: 1 addition & 1 deletion gradle/elide.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ graalvm-tools-lsp-api = { group = "org.graalvm.tools", name = "lsp_api", version
graalvm-tools-lsp-impl = { group = "org.graalvm.tools", name = "lsp-tool", version.ref = "graalvm" }
graalvm-tools-profiler = { group = "org.graalvm.tools", name = "profiler-tool", version.ref = "graalvm" }
graalvm-truffle-api = { group = "org.graalvm.truffle", name = "truffle-api", version.ref = "graalvm" }
graalvm-truffle-enterprise = { group = "org.graalvm.truffle", name = "truffle-enterprise", version.ref = "graalvm" }
graalvm-truffle-enterprise = { group = "org.graalvm.truffle", name = "truffle-enterprise", version.ref = "graalvm-stable" }
graalvm-truffle-nfi = { group = "org.graalvm.truffle", name = "truffle-nfi", version.ref = "graalvm" }
graalvm-truffle-nfi-libffi = { group = "org.graalvm.truffle", name = "truffle-nfi-libffi", version.ref = "graalvm" }
graalvm-truffle-nfi-native-darwin-aarch64 = { group = "org.graalvm.truffle", name = "truffle-nfi-native-darwin-aarch64", version.ref = "graalvm-stable" }
Expand Down
1 change: 1 addition & 0 deletions gradle/verification-metadata.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions packages/base/api/base.api
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,43 @@ public abstract interface annotation class elide/annotations/core/Internal : jav
public abstract interface annotation class elide/annotations/data/Sensitive : java/lang/annotation/Annotation {
}

public abstract interface class elide/jvm/BoundResource : java/io/Closeable, java/lang/AutoCloseable {
public static final field Companion Lelide/jvm/BoundResource$Companion;
}

public final class elide/jvm/BoundResource$AutoCloseableResource : elide/jvm/BoundResource {
public fun <init> (Ljava/lang/AutoCloseable;)V
public fun close ()V
}

public final class elide/jvm/BoundResource$CloseableResource : elide/jvm/BoundResource {
public fun <init> (Ljava/io/Closeable;)V
public fun close ()V
}

public final class elide/jvm/BoundResource$Companion {
public final fun of (Ljava/io/Closeable;)Lelide/jvm/BoundResource;
public final fun of (Ljava/lang/AutoCloseable;)Lelide/jvm/BoundResource;
}

public abstract interface class elide/jvm/LifecycleBoundResources {
public abstract fun getAllResources ()Lkotlin/sequences/Sequence;
public abstract fun register (Ljava/io/Closeable;)V
public abstract fun register (Ljava/lang/AutoCloseable;)V
public abstract fun unregister (Ljava/io/Closeable;)V
public abstract fun unregister (Ljava/lang/AutoCloseable;)V
}

public class elide/jvm/ResourceManager : elide/jvm/LifecycleBoundResources, java/io/Closeable, java/lang/AutoCloseable {
public fun <init> ()V
public fun close ()V
public fun getAllResources ()Lkotlin/sequences/Sequence;
public fun register (Ljava/io/Closeable;)V
public fun register (Ljava/lang/AutoCloseable;)V
public fun unregister (Ljava/io/Closeable;)V
public fun unregister (Ljava/lang/AutoCloseable;)V
}

public final class elide/runtime/LogLevel : java/lang/Enum {
public static final field DEBUG Lelide/runtime/LogLevel;
public static final field ERROR Lelide/runtime/LogLevel;
Expand Down
149 changes: 149 additions & 0 deletions packages/base/src/jvmMain/kotlin/elide/jvm/BoundResources.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Copyright (c) 2024 Elide Technologies, Inc.
*
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://opensource.org/license/mit/
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under the License.
*/
package elide.jvm

import java.io.Closeable
import kotlinx.collections.immutable.toImmutableSet

/**
* ## Bound Resource
*
* Describes a single "bound resource," which is held within the context of a [LifecycleBoundResources] instance; such
* resources have a weak reference back to their owner, and are automatically closed when the owner is closed.
*
* Bound resources are considered disposable types.
*/
public sealed interface BoundResource: Closeable, AutoCloseable {
/**
* Describes a [Closeable] resource as a [BoundResource].
*/
public class CloseableResource(private val resource: Closeable): BoundResource {
override fun close(): Unit = resource.close()
}

/**
* Describes an [AutoCloseable] resource as a [BoundResource].
*/
public class AutoCloseableResource(private val resource: AutoCloseable): BoundResource {
override fun close(): Unit = resource.close()
}

/**
* Companion utilities for creating [BoundResource] instances.
*/
public companion object {
/**
* Create a [BoundResource] from a [Closeable].
*
* @param resource The closeable resource to bind.
* @return A new [BoundResource] instance.
*/
public fun of(resource: Closeable): BoundResource = CloseableResource(resource)

/**
* Create a [BoundResource] from an [AutoCloseable].
*
* @param resource The auto-closeable resource to bind.
* @return A new [BoundResource] instance.
*/
public fun of(resource: AutoCloseable): BoundResource = AutoCloseableResource(resource)
}
}

/**
* ## Lifecycle-bound Resources
*
* Describes a pattern wherein resources ([Closeable] or [AutoCloseable] instances) are bound to a lifecycle, such that
* they are automatically closed when the lifecycle is closed.
*
* Resources are registered via the [register] method, optionally de-registered via the [unregister] method, and always
* closed when persisted to terminal close.
*
* Note that lifecycle-bound resource groups are not necessarily [Closeable] or [AutoCloseable] themselves.
*/
public interface LifecycleBoundResources {
/**
* Returns all resources currently bound to this lifecycle.
*/
public val allResources: Sequence<BoundResource>

/**
* Register a [Closeable] resource to this lifecycle.
*
* @param resource The resource to register.
* @return The bound resource instance.
*/
public fun register(resource: Closeable)

/**
* Register an [AutoCloseable] resource to this lifecycle.
*
* @param resource The resource to register.
*/
public fun unregister(resource: Closeable)

/**
* Unregister a [Closeable] resource from this lifecycle.
*
* @param resource The resource to unregister.
*/
public fun register(resource: AutoCloseable)

/**
* Unregister an [AutoCloseable] resource from this lifecycle.
*
* @param resource The resource to unregister.
*/
public fun unregister(resource: AutoCloseable)
}

/**
* ## Resource Manager
*
* Simple implementation of [LifecycleBoundResources], which propagates [close] calls to resources registered to it.
* Implementations are intended to use delegation:
*
* ```kotlin
* class MyResourceHolder(
* private val manager: LifecycleBoundResources = ResourceManager()
* ): LifecycleBoundResources by manager, AutoCloseable by manager {
* // ...
* private fun somethingThatSpawnsAResource() {
* val resource = // ...
* register(resource)
* }
* }
*
* // later ...
* val instance = MyResourceHolder()
* instance.use {
* // the inner resource will be closed automatically
* }
* ```
*/
public open class ResourceManager : LifecycleBoundResources, AutoCloseable, Closeable {
private val resources: MutableSet<BoundResource> = mutableSetOf()

override val allResources: Sequence<BoundResource>
get() = resources.toImmutableSet().asSequence()

override fun register(resource: Closeable) { resources.add(BoundResource.of(resource)) }
override fun register(resource: AutoCloseable) { resources.add(BoundResource.of(resource)) }
override fun unregister(resource: Closeable) { resources.remove(BoundResource.of(resource)) }
override fun unregister(resource: AutoCloseable) { resources.remove(BoundResource.of(resource)) }

override fun close() {
resources.forEach { it.close() }
resources.clear()
}
}
1 change: 0 additions & 1 deletion packages/cli/gradle.lockfile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7b356b2

Please sign in to comment.