Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Ensure the following are installed:
- Java 8+ (JDK)
- [Rust](https://www.rust-lang.org/tools/install)
- [sbt](https://www.scala-sbt.org/)
- [just](https://github.com/casey/just)

---

Expand Down Expand Up @@ -53,31 +54,31 @@ compiler are installed, then follow the commands below as per the need.
### Full project (Rust + Scala/Java)

```bash
sbt compile
just compile
```

### Native Rust library only

```bash
sbt generateNativeLibrary
just build-native
```

### Native Rust library only (Release profile)

```bash
NATIVE_RELEASE=true sbt generateNativeLibrary
NATIVE_RELEASE=true just build-native
```

### Locally publish

```bash
sbt publishLocal
just release-local
```

### Fat JAR

```bash
sbt assembly
just assembly
```

---
Expand All @@ -87,7 +88,7 @@ sbt assembly
Run unit tests via:

```bash
sbt test
just test
```

---
Expand All @@ -107,7 +108,7 @@ If you're a maintainer:

```bash
# Publish to Sonatype snapshots
sbt +publish
just release
```

---
Expand All @@ -118,4 +119,3 @@ sbt +publish
- Join the [Polars Discord](https://discord.gg/4UfP5cfBE7)

We appreciate every contribution ❤️

18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ repositories {
}
implementation("com.github.chitralverma:scala-polars_2.12:SOME-VERSION-SNAPSHOT")
```

> Note: Use `scala-polars_2.13` for Scala 2.13.x projects or `scala-polars_3` for Scala 3.x projects as the artifact ID

---

## 🧱 Modules
Expand All @@ -95,7 +97,7 @@ implementation("com.github.chitralverma:scala-polars_2.12:SOME-VERSION-SNAPSHOT"

## 🧪 Getting Started

### Scala
### Scala

```scala
import com.github.chitralverma.polars.api.{DataFrame, Series}
Expand All @@ -116,6 +118,7 @@ result.show()
```

### Java

```java
import com.github.chitralverma.polars.api.DataFrame;
import com.github.chitralverma.polars.api.Series;
Expand Down Expand Up @@ -161,24 +164,25 @@ df.show();
- JDK 8+
- [Rust](https://www.rust-lang.org/tools/install)
- [sbt](https://www.scala-sbt.org/)
- [just](https://github.com/casey/just)

### Commands

```bash
# Compile Rust + Scala + Java
sbt compile
just compile

# Publish locally
sbt publishLocal
just release-local

# Fat JAR (default Scala version)
sbt assembly
just assembly

# Rust native only
sbt generateNativeLibrary
just build-native

# Rust native only (Release profile)
NATIVE_RELEASE=true sbt generateNativeLibrary
NATIVE_RELEASE=true just build-native
```

---
Expand All @@ -192,4 +196,4 @@ Apache 2.0 — see [LICENSE](LICENSE)
## 🤝 Community

- Discuss Polars on [Polars Discord](https://discord.gg/4UfP5cfBE7)
- To contribute, see [CONTRIBUTING.md](CONTRIBUTING.md)
- To contribute, see [CONTRIBUTING.md](CONTRIBUTING.md)
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ lazy val core = project
publishMavenStyle := true
)
.settings(
nativeRoot := baseDirectory.value.toPath.resolveSibling("native").toFile,
inConfig(Compile)(NativeBuildSettings.settings)
)
.settings(ExtraCommands.commands)
.settings(ExtraCommands.commandAliases)
// .configureUnidoc("scala-polars API Reference")

Expand Down
78 changes: 29 additions & 49 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ set shell := ["bash", "-c"]
set ignore-comments := true

root := justfile_directory()
native_root := "native"
native_manifest := "native/Cargo.toml"
native_root := root / 'native'
native_manifest := native_root / 'Cargo.toml'
cargo_flags := env("CARGO_FLAGS", "--locked")

# Default recipe to 'help' to display this help screen
Expand All @@ -22,9 +22,9 @@ echo-command args:
# Format all code (Scala, Java, Rust, sbt)
[group('lint')]
fmt:
@just echo-command 'Formatting Scala, Java & Sbt'
@sbt -error --batch scalafmtAll scalafmtSbt javafmtAll
@just echo-command 'Formatting Rust'
@just echo-command 'Formatting core module'
@sbt -error scalafmtAll scalafmtSbt javafmtAll reload
@just echo-command 'Formatting native module'
@cargo clippy -q {{ cargo_flags }} --no-deps --fix --allow-dirty --allow-staged --manifest-path {{ native_manifest }}
@cargo sort {{ native_root }}
@cargo fmt --quiet --manifest-path {{ native_manifest }}
Expand All @@ -33,9 +33,9 @@ fmt:
# Check formatting and linting
[group('lint')]
lint:
@just echo-command 'Checking Scala, Java & Sbt'
@sbt -error --batch scalafmtCheckAll scalafmtSbtCheck javafmtCheckAll
@just echo-command 'Checking Rust'
@just echo-command 'Checking core module'
@sbt -error scalafmtCheckAll scalafmtSbtCheck javafmtCheckAll
@just echo-command 'Checking native module'
@cargo clippy -q {{ cargo_flags }} --no-deps --manifest-path {{ native_manifest }} -- -D warnings
@cargo sort {{ native_root }} --check
@cargo fmt --check --manifest-path {{ native_manifest }}
Expand All @@ -47,60 +47,35 @@ pre-commit: fmt lint

# Generate JNI headers
[group('dev')]
gen-headers: clean-headers
@sbt -error --batch genHeaders

# Remove generated JNI headers
[group('dev')]
clean-headers:
@rm -rf core/target/native
@just echo-command 'Removed JNI headers directory'
gen-headers:
@just echo-command 'Generating JNI headers'
@sbt genHeaders

# Build native library TARGET_TRIPLE, NATIVE_RELEASE, NATIVE_LIB_LOCATION env vars are supported
[group('dev')]
build-native:
#!/usr/bin/env bash
set -euo pipefail
if [ "${SKIP_NATIVE_GENERATION:-false}" = "false" ]; then
TRIPLE="${TARGET_TRIPLE:-$(rustc -vV | grep host | cut -d' ' -f2)}"
ARCH=$(echo "$TRIPLE" | cut -d'-' -f1)
RELEASE_FLAG=""
if [ "${NATIVE_RELEASE:-false}" = "true" ]; then
RELEASE_FLAG="--release"
fi

# Generate native library artifacts in a predictable output directory
NATIVE_OUTPUT_DIR="core/target/native-libs/$ARCH"
mkdir -p "$NATIVE_OUTPUT_DIR"
cargo build {{ cargo_flags }} --manifest-path {{ native_manifest }} -Z unstable-options $RELEASE_FLAG --lib --target "$TRIPLE" --artifact-dir "$NATIVE_OUTPUT_DIR"

if [ -n "${NATIVE_LIB_LOCATION:-}" ]; then
# Remove trailing slash if present
CLEAN_NATIVE_LIB_LOCATION="${NATIVE_LIB_LOCATION%/}"
DEST="$CLEAN_NATIVE_LIB_LOCATION/$ARCH"
echo "Environment variable NATIVE_LIB_LOCATION is set, copying built native library from location '$NATIVE_OUTPUT_DIR' to '$DEST'."
mkdir -p "$DEST"
cp -rf "$NATIVE_OUTPUT_DIR"/* "$DEST/"
fi
else
@just echo-command 'Environment variable SKIP_NATIVE_GENERATION is set, skipping cargo build.'
fi
@just echo-command 'Building native library'
@sbt generateNativeLibrary

# Build assembly jars
[group('dev')]
assembly: build-native
sbt +assembly
assembly:
@sbt +assembly

# Compile
[group('dev')]
compile: build-native
sbt compile
compile:
@sbt compile

# Clean build artifacts
[group('dev')]
clean: clean-headers
@sbt clean cleanFiles
@cargo clean --manifest-path {{ native_manifest }}
clean:
@just echo-command 'Cleaning native artifacts'
@cargo clean --manifest-path {{ native_manifest }} --quiet
@just echo-command 'Cleaning JNI headers'
@sbt -error cleanHeaders
@just echo-command 'Cleaning core artifacts'
@sbt -error clean cleanFiles reload

# Run tests
[group('dev')]
Expand All @@ -121,3 +96,8 @@ publish-site:
[group('release')]
release:
@sbt ci-release

# Release/ publish artifacts locally
[group('release')]
release-local:
@sbt publishLocal
17 changes: 16 additions & 1 deletion project/ExtraCommands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,23 @@ import com.github.sbt.jni.plugins.JniJavah.autoImport.javah

object ExtraCommands {

lazy val cleanHeaders =
taskKey[Unit]("Removes all previously generated headers")

lazy val commandAliases: Seq[Setting[_]] = Seq(
addCommandAlias("genHeaders", "javah")
addCommandAlias("genHeaders", ";cleanHeaders; javah")
).flatten

lazy val commands: Seq[Setting[_]] = Seq(
cleanHeaders := {
import scala.reflect.io.Directory

val headerDir = (javah / target).value
val directory = new Directory(headerDir)

directory.deleteRecursively()
sLog.value.info(s"Removed headers directory $headerDir")
}
)

}
5 changes: 5 additions & 0 deletions project/GeneralSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ object GeneralSettings {
}
)

lazy val settings: Seq[Setting[_]] = Seq(
name := "scala-polars",
nativeRoot := baseDirectory.value.toPath.resolveSibling("native").toFile
)

}
Loading