Skip to content

Commit

Permalink
Complete Nix compatibility, remove native Windows target
Browse files Browse the repository at this point in the history
  • Loading branch information
toasterofbread committed Jun 23, 2024
1 parent e4d990d commit 6c9b9ca
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ class AppIndicatorImpl(name: String, icon_path: List<String>): TrayIndicator {
private val menu: KJnaTypedPointer<_GtkMenu>
private var main_loop: KJnaTypedPointer<_GMainLoop>? = null

private val library: LibAppIndicator = LibAppIndicator()
private val library: LibAppIndicator

init {
try {
KJnaUtils.setLocale(
1, // LC_NUMERIC
"C"
)
}
catch (e: Throwable) {
RuntimeException("WARNING: Unable to set LC_NUMERIC locale", e).printStackTrace()
}

library = LibAppIndicator()
}

override fun show() {
library.app_indicator_set_menu(indicator, menu)
Expand Down
11 changes: 0 additions & 11 deletions app/src/commonMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import dev.toastbits.spms.client.cli.CommandLineClient
import dev.toastbits.spms.client.player.PlayerClient
import dev.toastbits.spms.server.SpMsCommand
import dev.toastbits.kjna.runtime.KJnaTypedPointer
import dev.toastbits.kjna.runtime.KJnaUtils
import kotlin.system.exitProcess
import kotlinx.coroutines.*
import gen.libmpv.LibMpv
Expand All @@ -16,16 +15,6 @@ fun String.toRed() =
"\u001b[31m$this\u001b[0m"

fun main(args: Array<String>) {
try {
KJnaUtils.setLocale(
1, // LC_NUMERIC
"C"
)
}
catch (e: Throwable) {
RuntimeException("WARNING: Unable to set LC_NUMERIC locale, some interops may not work", e).printStackTrace()
}

try {
val command: Command = SpMsCommand().subcommands(listOfNotNull(CommandLineClient.get(), PlayerClient.get()))
command.main(args)
Expand Down
44 changes: 44 additions & 0 deletions flake.lock

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

30 changes: 16 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,46 @@

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
custom_nixpkgs.url = "github:toasterofbread/nixpkgs/2fce494a8413016b5630cb593ffb9a0a1867274a";
custom_nixpkgs.url = "github:toasterofbread/nixpkgs/4df73973bda897522847e03e0820067c053bccad";
};

outputs = { self, nixpkgs, custom_nixpkgs, ... }:
let
system = "x86_64-linux";
x86_system = "x86_64-linux";
arm_system = "aarch64-linux";
in
{
devShells."${system}".default =
devShells."${x86_system}".default =
let
pkgs = import nixpkgs {
inherit system;
system = x86_system;
};
arm_pkgs = import nixpkgs {
system = arm_system;
};
custom_pkgs = import custom_nixpkgs {
inherit system;
system = x86_system;
};
in
pkgs.mkShell {
packages = with pkgs; [
fish
jdk21
jdk22
pkg-config
cmake
jextract
(custom_pkgs.zeromq-kotlin-native.override { enableDrafts = true; })
mpv
libayatana-appindicator
arm_pkgs.libayatana-appindicator
gtk3
curl
(custom_pkgs.kotlin-native-toolchain-env.override { x86 = true; })
git
(custom_pkgs.zeromq-kotlin-native.override { enableDrafts = true; })
(custom_pkgs.kotlin-native-toolchain-env.override { x86_64 = true; aarch64 = true; })

# Runtime
patchelf
glibc
glibc_multi
libgcc.lib
];

Expand All @@ -55,16 +59,14 @@
lib_paths_str=$(IFS=:; echo "''${lib_paths[*]}")
export LD_LIBRARY_PATH="$lib_paths_str:$LD_LIBRARY_PATH"
# Add glibc/include to C_INCLUDE_PATH
export C_INCLUDE_PATH="${pkgs.glibc.dev}/include:$C_INCLUDE_PATH"
echo "Using KJna development environment"
echo "JAVA_HOME=$JAVA_HOME"
# Add glibc and glibc_multi to C_INCLUDE_PATH
export C_INCLUDE_PATH="${pkgs.glibc.dev}/include:${pkgs.glibc_multi.dev}/include:$C_INCLUDE_PATH"
export KONAN_DATA_DIR=$(pwd)/.konan
mkdir -p $KONAN_DATA_DIR
cp -asfT ${custom_pkgs.kotlin-native-toolchain-env} $KONAN_DATA_DIR
chmod -R u+w $KONAN_DATA_DIR
mkdir $KONAN_DATA_DIR/bin
export PATH="$KONAN_DATA_DIR/bin:$PATH"
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ enum class Platform {

companion object {
val supported: List<Platform> = listOf(
JVM, LINUX_X86, LINUX_ARM64, WINDOWS
JVM, LINUX_X86, LINUX_ARM64
)

fun byName(name: String, arch: Arch): Platform =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kjna.struct.mpv_event
import kjna.enum.mpv_format
import dev.toastbits.kjna.runtime.KJnaTypedPointer
import dev.toastbits.kjna.runtime.KJnaMemScope
import dev.toastbits.kjna.runtime.KJnaUtils

abstract class LibMpvClient(
val libmpv: LibMpv,
Expand All @@ -20,6 +21,16 @@ abstract class LibMpvClient(
protected val ctx: KJnaTypedPointer<mpv_handle>

init {
try {
KJnaUtils.setLocale(
1, // LC_NUMERIC
"C"
)
}
catch (e: Throwable) {
RuntimeException("WARNING: Unable to set LC_NUMERIC locale", e).printStackTrace()
}

ctx = libmpv.mpv_create()
?: throw NullPointerException("Creating mpv client failed")

Expand Down

0 comments on commit 6c9b9ca

Please sign in to comment.