Skip to content

Scala Native Nix Flakes Nix Devshell Direnv ImageMagick libsndfile

Notifications You must be signed in to change notification settings

igor-ramazanov/scala-native-playground

Repository files navigation

Scala Native Playground

Exploring Scala Native Nix Flakes Nix Devshell Direnv.

The Nix sets up the development environment with:

  1. clang: C/C LLVM compiler https://clang.llvm.org
  2. sn-bindgen: Scala Native bindings generator https://sn-bindgen.indoorvivants.com
  3. imagemagick: magickwand API C for processing images https://imagemagick.org
  4. sndfile: C library for working with WAV audio files https://libsndfile.github.io/libsndfile
  5. jdk: GraalVM Community Edition: https://www.graalvm.org
  6. metals: Scala Metals LSP server: https://scalameta.org/metals
  7. sbt: Scala Built Tool: https://www.scala-sbt.org/index.html
  8. scala-cli: Scala command-line tool: https://scala-cli.virtuslab.org
  9. scala-fix: Scala refactoring and linting tool for Scala: https://scalacenter.github.io/scalafix

The build.sbt points to clang and sn-bindgen binaries provided by the devshell, and defines sn-bindgen bindings.

You can use this repo without nix if all of the above provided by your own environment.

As for nix users, cd into the repository directory and run nix develop to drop into the development environment.
Or, if you have direnv installed, simply cd into the repository directory and do direnv allow.
Now, whenever you cd into the repository directory the development environment will be activated automatically, and erased when you cd out of the repository directory.

sndfile usage

$ sbt sndfile/nativeLink
$ ./modules/sndfile/target/scala-3.5.0-RC2/sndfile ./file.wav

Channels: 2
Format: 65538
Frames: 7623627
Sample rate: 48000
Sections: 1
Seekable: 1
Album: null
Artist: RavioliCode
Comment: https://soundcloud.com/raviolicode/babangida
Copyright: null
Date: 20170223
Genre: Hip-hop & Rap
License: null
Software: Lavf58.76.100
Title: babangida - купол
Tracknumber: null

magickwand usage

$ sbt magickwand/nativeLink
$ ./modules/magickwand/target/scala-3.5.0-RC2/magickwand
# will produce the `./logo-extend.png` image

CI

This repo uses nix based GitHub actions for caching the development environment dependencies, instead of the traditional approach with coursier/setup-action and coursier/cache-action:

  1. https://github.com/DeterminateSystems/nix-installer-action
  2. https://github.com/DeterminateSystems/flake-checker-action
  3. https://github.com/DeterminateSystems/magic-nix-cache-action