Skip to content

Commit 55d3995

Browse files
committed
Initial commit
0 parents  commit 55d3995

6 files changed

Lines changed: 211 additions & 0 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
zig-version: ["0.14.0"]
18+
os: [ubuntu-latest, macos-latest, windows-latest]
19+
runs-on: ${{ matrix.os }}
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Zig
25+
uses: mlugg/setup-zig@v1
26+
with:
27+
version: ${{ matrix.zig-version }}
28+
29+
- name: Check Formatting
30+
run: zig fmt --ast-check --check .
31+
32+
- name: Build
33+
run: zig build --summary all

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (Expat)
2+
3+
Copyright (c) contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

LICENSE-LIBCHDR

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright Romain Tisserand
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
* Neither the name of the <organization> nor the
12+
names of its contributors may be used to endorse or promote products
13+
derived from this software without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
19+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[![CI](https://github.com/allyourcodebase/libchdr/actions/workflows/ci.yaml/badge.svg)](https://github.com/allyourcodebase/libchdr/actions)
2+
3+
# libchdr
4+
5+
This is [libchdr](ttps://github.com/rtissera/libchdr), packaged for [Zig](https://ziglang.org/).
6+
7+
## Installation
8+
9+
First, update your `build.zig.zon`:
10+
11+
```
12+
# Initialize a `zig build` project if you haven't already
13+
zig init
14+
zig fetch --save git+https://github.com/allyourcodebase/libchdr.git
15+
```
16+
17+
You can then import `libchdr` in your `build.zig` with:
18+
19+
```zig
20+
const bzip_dependency = b.dependency("libchdr", .{
21+
.target = target,
22+
.optimize = optimize,
23+
});
24+
your_exe.linkLibrary(bzip_dependency.artifact("chdr"));
25+
```
26+

build.zig

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = b.standardOptimizeOption(.{});
6+
7+
const upstream = b.dependency("upstream", .{});
8+
9+
const zstd_dependency = b.dependency("zstd", .{
10+
.target = target,
11+
.optimize = optimize,
12+
});
13+
const zlib_dependency = b.dependency("zlib", .{
14+
.target = target,
15+
.optimize = optimize,
16+
});
17+
18+
// use vendored lzma
19+
const lzma_lib = b.addStaticLibrary(.{
20+
.target = target,
21+
.optimize = optimize,
22+
.name = "lzma",
23+
});
24+
25+
lzma_lib.addCSourceFiles(.{
26+
.root = upstream.path("deps/lzma-24.05/src"),
27+
.files = &.{
28+
"Alloc.c",
29+
"Bra.c",
30+
"Bra86.c",
31+
"BraIA64.c",
32+
"CpuArch.c",
33+
"Delta.c",
34+
"LzFind.c",
35+
"Lzma86Dec.c",
36+
"LzmaDec.c",
37+
"LzmaEnc.c",
38+
"Sort.c",
39+
},
40+
.flags = &.{
41+
"-DZ7_ST",
42+
},
43+
});
44+
lzma_lib.linkLibC();
45+
lzma_lib.addIncludePath(upstream.path("deps/lzma-24.05/include"));
46+
lzma_lib.installHeadersDirectory(upstream.path("deps/lzma-24.05/include"), "", .{});
47+
48+
const lib = b.addStaticLibrary(.{
49+
.target = target,
50+
.optimize = optimize,
51+
.name = "chdr",
52+
});
53+
54+
lib.addCSourceFiles(.{
55+
.root = upstream.path("src"),
56+
.files = &.{
57+
"libchdr_bitstream.c",
58+
"libchdr_cdrom.c",
59+
"libchdr_chd.c",
60+
"libchdr_flac.c",
61+
"libchdr_huffman.c",
62+
},
63+
});
64+
lib.linkLibC();
65+
66+
lib.addIncludePath(upstream.path("include"));
67+
lib.installHeadersDirectory(upstream.path("include/libchdr"), "libchdr", .{});
68+
69+
lib.linkLibrary(lzma_lib);
70+
if (b.systemIntegrationOption("zlib", .{})) {
71+
lib.linkSystemLibrary("zlib");
72+
} else {
73+
lib.linkLibrary(zlib_dependency.artifact("z"));
74+
}
75+
if (b.systemIntegrationOption("zstd", .{})) {
76+
lib.linkSystemLibrary("zstd");
77+
} else {
78+
lib.linkLibrary(zstd_dependency.artifact("zstd"));
79+
}
80+
81+
b.installArtifact(lib);
82+
}

build.zig.zon

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.{
2+
.name = .libchdr,
3+
.version = "0.0.0",
4+
.fingerprint = 0xcdbeff9682105928,
5+
.minimum_zig_version = "0.14.0",
6+
.dependencies = .{
7+
.upstream = .{
8+
.url = "git+https://github.com/rtissera/libchdr#8bba7745d758627258b315997a860039244cedaf",
9+
.hash = "N-V-__8AAFHk0QADIJ2L4BjuFmIWmb5uZ0NzJavMOvQbwOXM",
10+
},
11+
.zstd = .{
12+
.url = "git+https://github.com/allyourcodebase/zstd.git?ref=1.5.7#01327d49cbc56dc24c20a167bb0055d7fc23de84",
13+
.hash = "zstd-1.5.7-KEItkJ8vAAC5_rRlKmLflYQ-eKXbAIQBWZNmmJtS18q0",
14+
},
15+
.zlib = .{
16+
.url = "https://github.com/allyourcodebase/zlib/archive/refs/tags/1.3.1.tar.gz",
17+
.hash = "zlib-1.3.1-AAAAACEMAAA0qyoSrfgBb_p25ItL4yRf_TBRk-26TYMF",
18+
},
19+
},
20+
21+
.paths = .{
22+
"build.zig",
23+
"build.zig.zon",
24+
},
25+
}

0 commit comments

Comments
 (0)