Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ mkdir -p build && cd build
../tools/configure --target=sdlapp --type=N --lcdwidth=320 --lcdheight=240 --prefix=$HOME/.local
make zig
```

Or with Nix:
```sh
nix develop
mkdir -p build && cd build
../tools/configure --target=sdlapp --type=N --lcdwidth=320 --lcdheight=240 --prefix=$HOME/.local
make zig
```
4 changes: 4 additions & 0 deletions apps/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@

/*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */

extern int hello(int x);

static void init(void);
/* main(), and various functions called by main() and init() may be
* be INIT_ATTR. These functions must not be called after the final call
Expand Down Expand Up @@ -194,6 +196,8 @@ int main(void)
usb_start_monitoring();
#endif

hello(2024);

#if !defined(DISABLE_ACTION_REMAP) && defined(CORE_KEYREMAP_FILE)
if (file_exists(CORE_KEYREMAP_FILE))
{
Expand Down
44 changes: 44 additions & 0 deletions apps/plugins/helloworldzig.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 Björn Stenberg
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/

/* welcome to the example rockbox plugin */

/* mandatory include for all plugins */
#include "plugin.h"

extern int32_t hello(void);

/* this is the plugin entry point */
enum plugin_status plugin_start(const void* parameter)
{
/* if you don't use the parameter, you can do like
this to avoid the compiler warning about it */
(void)parameter;

/* "rb->" marks a plugin api call. Rockbox offers many of its built-in
* functions to plugins */
/* now go ahead and have fun! */
// rb->splash(HZ*2, "Hello world!");
hello();

/* tell Rockbox that we have completed successfully */
return PLUGIN_OK;
}
22 changes: 18 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ pub fn build(b: *std.Build) !void {
// step when running `zig build`).
b.installArtifact(exe);

const hello = b.addStaticLibrary(.{
.name = "hello",
.root_source_file = b.path("src/hello_world.zig"),
.target = target,
.optimize = optimize,
});

b.installArtifact(hello);
defineCMacros(hello);
addIncludePaths(hello);
hello.linkLibC();

// This *creates* a Run step in the build graph, to be executed when another
// step is evaluated that depends on it. The next line below will establish
// such a dependency.
Expand Down Expand Up @@ -159,8 +171,6 @@ pub fn build(b: *std.Build) !void {
defineCMacros(libfirmware);
addIncludePaths(libfirmware);

libfirmware.linkSystemLibrary("usb");

const libspeex_voice = b.addStaticLibrary(.{
.name = "speex-voice",
.target = target,
Expand Down Expand Up @@ -1567,6 +1577,9 @@ pub fn build(b: *std.Build) !void {
defineCMacros(libpluginbitmaps);
addPluginIncludePaths(libpluginbitmaps);

defineCMacros(lib);
addIncludePaths(lib);

const chopper = try build_plugin(b, .{
.name = "chopper",
.target = target,
Expand Down Expand Up @@ -2922,6 +2935,7 @@ pub fn build(b: *std.Build) !void {
defineCMacros(exe);
addIncludePaths(exe);

exe.linkLibrary(hello);
exe.linkLibrary(libfirmware);
exe.linkLibrary(libspeex_voice);
exe.linkLibrary(librbcodec);
Expand All @@ -2942,8 +2956,8 @@ fn build_tools(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bu
build_convbdf(b, target, optimize);
build_codepages(b, target, optimize);
build_voicefont(b, target, optimize);
build_usb_benchmark(b, target, optimize);
build_convttf(b, target, optimize);
// build_usb_benchmark(b, target, optimize);
// build_convttf(b, target, optimize);
build_mk500boot(b, target, optimize);
}

Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
.version = "0.1.0",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
95 changes: 95 additions & 0 deletions flake.lock

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

106 changes: 106 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
description = "Rockbox Zig project flake";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
zig2nix.url = "github:Cloudef/zig2nix";
};

outputs = { zig2nix, nixpkgs, ... }: let
flake-utils = zig2nix.inputs.flake-utils;
in (flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
};

inherit (pkgs) lib;
# Zig flake helper
# Check the flake.nix in zig2nix project for more options:
# <https://github.com/Cloudef/zig2nix/blob/master/flake.nix>
env = zig2nix.outputs.zig-env.${system} { zig = pkgs.zig; };
system-triple = env.lib.zigTripleFromString system;
in with builtins; with env.lib; with env.pkgs.lib; rec {
# nix build .#target.{zig-target}
# e.g. nix build .#target.x86_64-linux-gnu
packages.target = genAttrs allTargetTriples (target: env.packageForTarget target ({
src = cleanSource ./.;

nativeBuildInputs = with env.pkgs; [];
buildInputs = with env.pkgsForTarget target; [
pkgs.zig
pkgs.SDL_compat
pkgs.freetype
pkgs.gnumake
pkgs.pkg-config
pkgs.gcc
pkgs.zlib
];

# Smaller binaries and avoids shipping glibc.
zigPreferMusl = false;

# This disables LD_LIBRARY_PATH mangling, binary patching etc...
# The package won't be usable inside nix.
zigDisableWrap = false;
} // optionalAttrs (!pathExists ./build.zig.zon) {
pname = "rockbox-zig";
version = "0.1.0";
}));

# nix build .
packages.default = packages.target.${system-triple}.override {
# Prefer nix friendly settings.
zigPreferMusl = false;
zigDisableWrap = false;
};

# For bundling with nix bundle for running outside of nix
# example: https://github.com/ralismark/nix-appimage
apps.bundle.target = genAttrs allTargetTriples (target: let
pkg = packages.target.${target};
in {
type = "app";
program = "${pkg}/bin/default";
});

# default bundle
apps.bundle.default = apps.bundle.target.${system-triple};

# nix run .
apps.default = env.app [] "zig build run -- \"$@\"";

# nix run .#build
apps.build = env.app [] "zig build \"$@\"";

# nix run .#test
apps.test = env.app [] "zig build test -- \"$@\"";

# nix run .#docs
apps.docs = env.app [] "zig build docs -- \"$@\"";

# nix run .#deps
apps.deps = env.showExternalDeps;

# nix run .#zon2json
apps.zon2json = env.app [env.zon2json] "zon2json \"$@\"";

# nix run .#zon2json-lock
apps.zon2json-lock = env.app [env.zon2json-lock] "zon2json-lock \"$@\"";

# nix run .#zon2nix
apps.zon2nix = env.app [env.zon2nix] "zon2nix \"$@\"";

# nix develop
devShells.default = env.mkShell {
nativeBuildInputs = with env.pkgs; [
pkgs.zig
pkgs.SDL_compat
pkgs.freetype
pkgs.gnumake
pkgs.pkg-config
pkgs.gcc
pkgs.zlib
];
};
}));
}
10 changes: 10 additions & 0 deletions src/hello_world.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const std = @import("std");
const rockbox = @import("./root.zig");

export fn hello(x: i32) i32 {
_ = rockbox.playback.audioNextTrack();
_ = rockbox.playback.audioCurrentTrack();
const status = rockbox.playback.audioStatus();
std.debug.print("Hello, World! {} {}\n", .{ x, status });
return 0;
}
15 changes: 15 additions & 0 deletions src/rockbox/browse.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pub fn rockboxBrowse() void {}

pub fn treeGetContext() void {}

pub fn treeGetEntries() void {}

pub fn treeGetEntryAt() void {}

pub fn setCurrentFile() void {}

pub fn setDirfilter() void {}

pub fn onplayShowPlaylistMenu() void {}

pub fn browseId3() void {}
13 changes: 13 additions & 0 deletions src/rockbox/dir.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub fn opendir() void {}

pub fn closedir() void {}

pub fn readdir() void {}

pub fn mkdir() void {}

pub fn rmdir() void {}

pub fn dirExists() void {}

pub fn dirGetInfo() void {}
Loading