-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "remove zig port (from master)"
This reverts commit 6d2342d.
- Loading branch information
Showing
14 changed files
with
253 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
|
||
from cffi import FFI | ||
|
||
from rose.common import RoseError | ||
|
||
try: | ||
so_path = os.environ["ROSE_SO_PATH"] | ||
except KeyError as e: | ||
raise RoseError("ROSE_SO_PATH unset: cannot load underlying Zig library") from e | ||
|
||
ffi = FFI() | ||
lib = ffi.dlopen(so_path) | ||
ffi.cdef(""" | ||
void free_str(void *str); | ||
char *getRelease(); | ||
""") | ||
|
||
|
||
def get_release() -> str: | ||
return ffi.string(ffi.gc(lib.getRelease(), lib.free_str)).decode("utf-8") # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const target = b.standardTargetOptions(.{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
// Dependencies. | ||
const sqlite = b.dependency("sqlite", .{ | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
// TODO: This is really expensive, so uncomment it only when we start using it. | ||
// const ffmpeg = b.dependency("ffmpeg", .{ | ||
// .target = target, | ||
// .optimize = optimize, | ||
// }); | ||
|
||
// Specify the core library module. | ||
const rose = b.addModule("rose", .{ | ||
.root_source_file = b.path("rose/root.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
.imports = &[_]std.Build.Module.Import{ | ||
// .{ .name = "av", .module = ffmpeg.module("av") }, | ||
.{ .name = "sqlite", .module = sqlite.module("sqlite") }, | ||
}, | ||
}); | ||
|
||
// Tests for the core library module. | ||
const test_step = b.step("test", "Run unit tests"); | ||
const unit_tests = b.addTest(.{ | ||
.root_source_file = .{ .path = "rose/root.zig" }, | ||
.target = target, | ||
}); | ||
const run_unit_tests = b.addRunArtifact(unit_tests); | ||
test_step.dependOn(&run_unit_tests.step); | ||
|
||
// Shared library for compatibility with other languages. | ||
const librose = b.addSharedLibrary(.{ | ||
.name = "rose", | ||
.root_source_file = .{ .path = "ffi/root.zig" }, | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
librose.root_module.addImport("rose", rose); | ||
b.installArtifact(librose); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.{ | ||
.name = "rose", | ||
.version = "0.5.0", | ||
.dependencies = .{ | ||
.sqlite = .{ | ||
.url = "https://github.com/vrischmann/zig-sqlite/archive/dc339b7cf3bca82a12c2169231dd247587766781.tar.gz", | ||
.hash = "1220e0961c135c5aa3af77a043dbc5890a18235a157238df0e2882fe84a8c8439c7a", | ||
}, | ||
.ffmpeg = .{ | ||
.url = "https://github.com/andrewrk/ffmpeg/archive/1704e8898ea6217df91e6afc2a2de3f2b82a98d9.tar.gz", | ||
.hash = "122032707cdf94da394e309978146ee33c61a285300eeb916928af376ec1638a95f1", | ||
}, | ||
}, | ||
.paths = .{""}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ callPackage | ||
, stdenv | ||
, zig | ||
, version | ||
}: | ||
|
||
stdenv.mkDerivation { | ||
pname = "rose-zig"; | ||
version = version; | ||
src = ./.; | ||
nativeBuildInputs = [ zig.hook ]; | ||
postPatch = '' | ||
ln -s ${callPackage ./deps.nix { }} $ZIG_GLOBAL_CACHE_DIR/p | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# generated by zon2nix (https://github.com/nix-community/zon2nix) | ||
|
||
{ linkFarm, fetchzip }: | ||
|
||
linkFarm "zig-packages" [ | ||
{ | ||
name = "122004fa7e2ff0b3d472049743358f8fdf065cdf63bc0e5e3d54c6bb8d81d93e40da"; | ||
path = fetchzip { | ||
url = "https://github.com/andrewrk/nasm/archive/b5f62392d56baf6aa02567f28e0da70664609262.tar.gz"; | ||
hash = "sha256-tPBQixxG+phvEfRHeOLHMjY1Ynp7r9zNSgRy4R/ILQM="; | ||
}; | ||
} | ||
{ | ||
name = "1220138f4aba0c01e66b68ed9e1e1e74614c06e4743d88bc58af4f1c3dd0aae5fea7"; | ||
path = fetchzip { | ||
url = "https://github.com/allyourcodebase/zlib/archive/refs/tags/1.3.1-3.tar.gz"; | ||
hash = "sha256-R1tB+ORO3qeV/cNxsp5GqsiOyKUXjaj4Pd1v5AfWYz4="; | ||
}; | ||
} | ||
{ | ||
name = "122032707cdf94da394e309978146ee33c61a285300eeb916928af376ec1638a95f1"; | ||
path = fetchzip { | ||
url = "https://github.com/andrewrk/ffmpeg/archive/1704e8898ea6217df91e6afc2a2de3f2b82a98d9.tar.gz"; | ||
hash = "sha256-6EYu1QT76cJQMW9F41DvXsVLulH1YwGrkhwSV6IsBes="; | ||
}; | ||
} | ||
{ | ||
name = "122074e0bf09c3622780e697c11c6744e763dd63777e480baf2b583ee3ab6a02ff14"; | ||
path = fetchzip { | ||
url = "https://github.com/andrewrk/libvorbis/archive/refs/tags/1.3.8-3.tar.gz"; | ||
hash = "sha256-KHKYT3tmab9qYu8N2iJwm1rS+mU7Cwnn8Jp0cfOdnIg="; | ||
}; | ||
} | ||
{ | ||
name = "12207d353609d95cee9da7891919e6d9582e97b7aa2831bd50f33bf523a582a08547"; | ||
path = fetchzip { | ||
url = "https://github.com/madler/zlib/archive/refs/tags/v1.3.tar.gz"; | ||
hash = "sha256-eUuXV5zfy+fmiMNdWw5QCqDloBkaxy1tgi7by9nYHNA="; | ||
}; | ||
} | ||
{ | ||
name = "1220b3e1fb33317c92f9ead09630f6b4be59e80d0a8780754f8aa4ee7da61cb7b47a"; | ||
path = fetchzip { | ||
url = "https://github.com/andrewrk/libogg/archive/refs/tags/1.3.6-2.tar.gz"; | ||
hash = "sha256-3dFDBo4Af58bW8Gf+sHLigwo8CO2siwzWWtAoYe5opI="; | ||
}; | ||
} | ||
{ | ||
name = "1220bee0fcf98bf6ad75b7bb09ff1f873ca38547a15b1e7a4532d20d94107d8d330a"; | ||
path = fetchzip { | ||
url = "https://github.com/andrewrk/libmp3lame/archive/refs/tags/3.100.1-3.tar.gz"; | ||
hash = "sha256-kMI7JACnIVAdUHp5DUKx2XfKgIb1ftr6x/oYJdsTKyI="; | ||
}; | ||
} | ||
{ | ||
name = "1220e0961c135c5aa3af77a043dbc5890a18235a157238df0e2882fe84a8c8439c7a"; | ||
path = fetchzip { | ||
url = "https://github.com/vrischmann/zig-sqlite/archive/dc339b7cf3bca82a12c2169231dd247587766781.tar.gz"; | ||
hash = "sha256-YouCVidJqhI5+joTSe1aSbnjVC+qVG2aIz6MyibRmQk="; | ||
}; | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const std = @import("std"); | ||
const rose = @import("rose"); | ||
|
||
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
const allocator = gpa.allocator(); | ||
|
||
export fn getRelease() [*:0]const u8 { | ||
const message = rose.getRelease(allocator) catch |err| switch (err) { | ||
error.OutOfMemory => @panic("Out of memory"), | ||
}; | ||
return message.ptr; | ||
} | ||
|
||
export fn free_str(str: [*:0]const u8) void { | ||
const len = std.mem.len(str); | ||
allocator.free(str[0 .. len + 1]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const std = @import("std"); | ||
const sqlite = @import("sqlite"); | ||
const testing = std.testing; | ||
|
||
pub fn getRelease(allocator: std.mem.Allocator) ![:0]const u8 { | ||
return try allocator.dupeZ(u8, "hello"); | ||
} | ||
|
||
pub fn getTrack(allocator: std.mem.Allocator) void { | ||
const db = try sqlite.Db.init(.{ | ||
.mode = sqlite.Db.Mode{ .File = "/home/blissful/.cache/rose/cache.sqlite3" }, | ||
.open_flags = .{ | ||
.write = true, | ||
.create = true, | ||
}, | ||
.threading_mode = .MultiThread, | ||
}); | ||
_ = db; | ||
_ = allocator; | ||
} | ||
|
||
test "basic add functionality" { | ||
const message = try getRelease(testing.allocator); | ||
try testing.expect(std.mem.eql(u8, message, "hello")); | ||
testing.allocator.free(message); | ||
} |