Skip to content

Commit 9d4bbcd

Browse files
committed
phira{,-unwrapped,-free}: init at 0.6.7
1 parent 6cfed02 commit 9d4bbcd

7 files changed

Lines changed: 342 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
lib,
3+
stdenvNoCC,
4+
phira,
5+
phira-unwrapped,
6+
imagemagick,
7+
ubuntu-classic,
8+
}:
9+
10+
phira.override {
11+
overrideAssets = stdenvNoCC.mkDerivation {
12+
pname = "phira-assets";
13+
version = phira.version;
14+
15+
nativeBuildInputs = [ imagemagick ];
16+
17+
dontUnpack = true;
18+
19+
installPhase = ''
20+
runHook preInstall
21+
22+
mkdir -p $out
23+
cp -r ${phira-unwrapped.src}/assets $out
24+
chmod -R +w $out/assets
25+
26+
magick -size 4000x2000 canvas:'rgb(128,162,206)' $out/assets/background.jpg
27+
cp ${ubuntu-classic}/share/fonts/truetype/ubuntu/Ubuntu-R.ttf $out/assets/font.ttf
28+
29+
runHook postInstall
30+
'';
31+
};
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff --git a/prpr/src/core.rs b/prpr/src/core.rs
2+
index 7f9d4db..33c44bb 100644
3+
--- a/prpr/src/core.rs
4+
+++ b/prpr/src/core.rs
5+
@@ -68,6 +68,14 @@ thread_local! {
6+
}
7+
8+
pub fn init_assets() {
9+
+ if let Ok(root_path) = std::env::var("PHIRA_ROOT") {
10+
+ let path = std::path::Path::new(&root_path);
11+
+ if path.exists() {
12+
+ std::env::set_current_dir(path).unwrap();
13+
+ set_pc_assets_folder("assets");
14+
+ return;
15+
+ }
16+
+ }
17+
if let Ok(mut exe) = std::env::current_exe() {
18+
while exe.pop() {
19+
if exe.join("assets").exists() {
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
diff --git a/prpr-avc/Cargo.toml b/prpr-avc/Cargo.toml
2+
index 257c575..bf35b10 100644
3+
--- a/prpr-avc/Cargo.toml
4+
+++ b/prpr-avc/Cargo.toml
5+
@@ -9,3 +9,6 @@ edition = "2021"
6+
sasa = { git = "https://github.com/Mivik/sasa", default-features = false }
7+
thiserror = "1.0.56"
8+
tracing = "0.1.37"
9+
+
10+
+[build-dependencies]
11+
+pkg-config = "0.3"
12+
diff --git a/prpr-avc/build.rs b/prpr-avc/build.rs
13+
index 961b032..6d0b714 100644
14+
--- a/prpr-avc/build.rs
15+
+++ b/prpr-avc/build.rs
16+
@@ -1,10 +1,7 @@
17+
use std::path::Path;
18+
19+
fn main() {
20+
- let libs_dir = std::env::var("PRPR_AVC_LIBS").unwrap_or_else(|_| format!("{}/static-lib", std::env::var("CARGO_MANIFEST_DIR").unwrap()));
21+
- let libs_path = Path::new(&libs_dir).join(std::env::var("TARGET").unwrap());
22+
- let libs_path = libs_path.display();
23+
- println!("cargo:rustc-link-search={libs_path}");
24+
- println!("cargo:rustc-link-lib=z");
25+
- println!("cargo:rerun-if-changed={libs_path}");
26+
+ for lib in ["libavformat", "libavcodec", "libavutil", "libswscale", "libswresample"] {
27+
+ let _ = pkg_config::Config::new().statik(false).probe(lib);
28+
+ }
29+
}
30+
diff --git a/prpr-avc/src/ffi.rs b/prpr-avc/src/ffi.rs
31+
index 8218ef3..a2c7f6a 100644
32+
--- a/prpr-avc/src/ffi.rs
33+
+++ b/prpr-avc/src/ffi.rs
34+
@@ -6,7 +6,6 @@ pub const AV_SAMPLE_FMT_FLT: AVSampleFormat = 3;
35+
36+
pub const AV_ROUND_UP: AVRounding = 0;
37+
38+
-#[link(name = "avformat", kind = "static")]
39+
extern "C" {
40+
pub fn avformat_alloc_context() -> *mut AVFormatContext;
41+
pub fn avformat_free_context(s: *mut AVFormatContext);
42+
@@ -20,7 +19,6 @@ extern "C" {
43+
pub fn av_read_frame(s: *mut AVFormatContext, pkt: *mut AVPacket) -> ::std::os::raw::c_int;
44+
}
45+
46+
-#[link(name = "avutil", kind = "static")]
47+
extern "C" {
48+
pub fn av_strerror(errnum: ::std::os::raw::c_int, errbuf: *mut ::std::os::raw::c_char, errbuf_size: usize) -> ::std::os::raw::c_int;
49+
pub fn av_frame_alloc() -> *mut AVFrame;
50+
@@ -29,7 +27,6 @@ extern "C" {
51+
pub fn av_rescale_rnd(a: i64, b: i64, c: i64, r: AVRounding) -> i64;
52+
}
53+
54+
-#[link(name = "avcodec", kind = "static")]
55+
extern "C" {
56+
pub fn avcodec_find_decoder(id: AVCodecID) -> *mut AVCodec;
57+
pub fn avcodec_alloc_context3(codec: *const AVCodec) -> *mut AVCodecContext;
58+
@@ -43,7 +40,6 @@ extern "C" {
59+
pub fn avcodec_default_get_format(s: *mut AVCodecContext, fmt: *const AVPixelFormat) -> AVPixelFormat;
60+
}
61+
62+
-#[link(name = "swscale", kind = "static")]
63+
extern "C" {
64+
pub fn sws_getContext(
65+
srcW: ::std::os::raw::c_int,
66+
@@ -68,10 +64,9 @@ extern "C" {
67+
) -> ::std::os::raw::c_int;
68+
}
69+
70+
-#[link(name = "swresample", kind = "static")]
71+
extern "C" {
72+
- pub fn swr_alloc_set_opts(
73+
- s: *mut SwrContext,
74+
+ pub fn swr_alloc_set_opts2(
75+
+ ps: *mut *mut SwrContext,
76+
out_ch_layout: i64,
77+
out_sample_fmt: AVSampleFormat,
78+
out_sample_rate: ::std::os::raw::c_int,
79+
@@ -80,7 +75,7 @@ extern "C" {
80+
in_sample_rate: ::std::os::raw::c_int,
81+
log_offset: ::std::os::raw::c_int,
82+
log_ctx: *mut ::std::os::raw::c_void,
83+
- ) -> *mut SwrContext;
84+
+ ) -> ::std::os::raw::c_int;
85+
pub fn swr_init(s: *mut SwrContext) -> ::std::os::raw::c_int;
86+
pub fn swr_get_delay(s: *const SwrContext, base: ::std::os::raw::c_int) -> i64;
87+
pub fn swr_convert(
88+
diff --git a/prpr-avc/src/swr.rs b/prpr-avc/src/swr.rs
89+
index 7288a51..c00b874 100644
90+
--- a/prpr-avc/src/swr.rs
91+
+++ b/prpr-avc/src/swr.rs
92+
@@ -5,8 +5,9 @@ pub struct SwrContext(OwnedPtr<ffi::SwrContext>);
93+
impl SwrContext {
94+
pub fn new(in_format: &AudioStreamFormat, out_format: &AudioStreamFormat) -> Result<Self> {
95+
unsafe {
96+
- OwnedPtr::new(ffi::swr_alloc_set_opts(
97+
- null_mut(),
98+
+ let mut raw: *mut ffi::SwrContext = null_mut();
99+
+ let ret = ffi::swr_alloc_set_opts2(
100+
+ &mut raw,
101+
out_format.channel_layout as _,
102+
out_format.sample_fmt,
103+
out_format.sample_rate,
104+
@@ -15,9 +16,12 @@ impl SwrContext {
105+
in_format.sample_rate,
106+
0,
107+
null_mut(),
108+
- ))
109+
- .map(|ctx| Self(ctx))
110+
- .ok_or(Error::AllocationFailed)
111+
+ );
112+
+ if ret < 0 || raw.is_null() {
113+
+ Err(Error::AllocationFailed)
114+
+ } else {
115+
+ OwnedPtr::new(raw).map(|ctx| Self(ctx)).ok_or(Error::AllocationFailed)
116+
+ }
117+
}
118+
}
119+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
lib,
3+
stdenv,
4+
fetchFromGitHub,
5+
makeDesktopItem,
6+
copyDesktopItems,
7+
rustPlatform,
8+
pkg-config,
9+
perl,
10+
ffmpeg,
11+
alsa-lib,
12+
gtk3,
13+
}:
14+
15+
rustPlatform.buildRustPackage (finalAttrs: {
16+
pname = "phira-unwrapped";
17+
version = "0.6.7";
18+
19+
src = fetchFromGitHub {
20+
owner = "TeamFlos";
21+
repo = "phira";
22+
tag = "v${finalAttrs.version}";
23+
hash = "sha256-4WIvLfKeh+quu7dHKMlUKt+NQnui2/txlFYZoU3voPA=";
24+
};
25+
26+
nativeBuildInputs = [
27+
pkg-config
28+
perl
29+
copyDesktopItems
30+
]
31+
++ lib.optionals stdenv.hostPlatform.isDarwin [
32+
rustPlatform.bindgenHook # for crate coreaudio-sys
33+
];
34+
35+
buildInputs = [
36+
ffmpeg
37+
]
38+
++ lib.optionals stdenv.hostPlatform.isLinux [
39+
alsa-lib # for crate alsa-sys
40+
gtk3 # for crate gtk-sys
41+
];
42+
43+
patches = [
44+
# use dynamically linked ffmpeg instead of expecting static lib
45+
./ffmpeg.patch
46+
47+
# error[E0554]: `#![feature]` may not be used on the stable release channel
48+
./stable-features.patch
49+
50+
# missing macro from tracing crate
51+
./tracing.patch
52+
53+
# allow using env var to specify location of assets and data
54+
./assets.patch
55+
];
56+
57+
cargoHash = "sha256-6mRb3M56G20fA+px1cZyrGpel0v54qoVAQK2ZgTzkmI=";
58+
59+
# The developer put assets necessary for this test in gitignore, so it cannot run.
60+
checkFlags = [ "--skip test_parse_chart" ];
61+
62+
desktopItems = [
63+
(makeDesktopItem {
64+
name = "phira";
65+
desktopName = "Phira";
66+
exec = "phira-main";
67+
icon = "phira";
68+
comment = finalAttrs.meta.description;
69+
categories = [ "Game" ];
70+
})
71+
];
72+
73+
postInstall = ''
74+
install -Dm644 assets/icon.png $out/share/icons/hicolor/128x128/apps/phira.png
75+
'';
76+
77+
meta = {
78+
description = "Rhythm game with custom charts and multiplayer";
79+
homepage = "https://github.com/TeamFlos/phira";
80+
license = lib.licenses.gpl3Only;
81+
maintainers = with lib.maintainers; [ ulysseszhan ];
82+
changelog = "https://github.com/TeamFlos/phira/releases/tag/v${finalAttrs.version}";
83+
platforms = lib.platforms.unix;
84+
mainProgram = "phira-main";
85+
};
86+
87+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
diff --git a/prpr/src/lib.rs b/prpr/src/lib.rs
2+
index 15a139f..6b4e469 100644
3+
--- a/prpr/src/lib.rs
4+
+++ b/prpr/src/lib.rs
5+
@@ -1,5 +1,3 @@
6+
-#![feature(local_key_cell_methods)]
7+
-
8+
pub mod bin;
9+
pub mod config;
10+
pub mod core;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/phira-monitor/Cargo.toml b/phira-monitor/Cargo.toml
2+
index 722a022..899b7db 100644
3+
--- a/phira-monitor/Cargo.toml
4+
+++ b/phira-monitor/Cargo.toml
5+
@@ -15,6 +15,7 @@ serde = { version = "*", features = ["derive"] }
6+
serde_yaml = "*"
7+
tokio = { workspace = true }
8+
uuid = { version = "1.4.0", features = ["v4"] }
9+
+tracing = "0.1"
10+
11+
phira-mp-client = { git = "https://github.com/TeamFlos/phira-mp" }
12+
phira-mp-common = { git = "https://github.com/TeamFlos/phira-mp" }
13+
diff --git a/phira-monitor/src/main.rs b/phira-monitor/src/main.rs
14+
index 61bcfba..a4bf8af 100644
15+
--- a/phira-monitor/src/main.rs
16+
+++ b/phira-monitor/src/main.rs
17+
@@ -14,6 +14,7 @@ use prpr::{
18+
use scene::MainScene;
19+
use serde::Deserialize;
20+
use std::fs::File;
21+
+use tracing::warn;
22+
23+
mod dir {
24+
use anyhow::Result;

pkgs/by-name/ph/phira/package.nix

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
lib,
3+
stdenv,
4+
symlinkJoin,
5+
fetchzip,
6+
phira-unwrapped,
7+
makeWrapper,
8+
libGL,
9+
# A derivation or a path that contains a dir `assets`.
10+
overrideAssets ? fetchzip {
11+
url = "https://github.com/TeamFlos/phira/releases/download/v${phira-unwrapped.version}/Phira-windows-v${phira-unwrapped.version}.zip";
12+
hash = "sha256-kgmIIIzg+wxyspQTyW1GucW0RVPfBhIRlK5DEGXK1Qs=";
13+
stripRoot = false;
14+
meta.license = lib.licenses.unfree;
15+
},
16+
}:
17+
18+
symlinkJoin {
19+
pname = "phira";
20+
version = phira-unwrapped.version;
21+
22+
paths = [ phira-unwrapped ];
23+
24+
nativeBuildInputs = [ makeWrapper ];
25+
26+
postBuild = ''
27+
phira_root=$out/share/phira
28+
mkdir -p $phira_root
29+
cp -r ${overrideAssets}/assets $phira_root
30+
31+
wrapper_options=(
32+
${lib.optionalString stdenv.hostPlatform.isLinux "--suffix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ libGL ]}"}
33+
--run '
34+
export PHIRA_ROOT=''${PHIRA_ROOT-"''${XDG_DATA_HOME-"$HOME/.local/share"}/phira"}
35+
if [[ ! -d "$PHIRA_ROOT/assets" ]]; then
36+
mkdir -p "$PHIRA_ROOT"
37+
cp -r "'$phira_root/assets'" "$PHIRA_ROOT"
38+
chmod -R +w "$PHIRA_ROOT/assets"
39+
fi
40+
'
41+
)
42+
43+
wrapProgram $out/bin/phira-main "''${wrapper_options[@]}"
44+
wrapProgram $out/bin/phira-monitor "''${wrapper_options[@]}"
45+
'';
46+
47+
passthru.assets = overrideAssets;
48+
49+
meta = phira-unwrapped.meta;
50+
51+
}

0 commit comments

Comments
 (0)