Loading pkgs/by-name/ph/phira-free/package.nix 0 → 100644 +32 −0 Original line number Diff line number Diff line { lib, stdenvNoCC, phira, phira-unwrapped, imagemagick, ubuntu-classic, }: phira.override { overrideAssets = stdenvNoCC.mkDerivation { pname = "phira-assets"; version = phira.version; nativeBuildInputs = [ imagemagick ]; dontUnpack = true; installPhase = '' runHook preInstall mkdir -p $out cp -r ${phira-unwrapped.src}/assets $out chmod -R +w $out/assets magick -size 4000x2000 canvas:'rgb(128,162,206)' $out/assets/background.jpg cp ${ubuntu-classic}/share/fonts/truetype/ubuntu/Ubuntu-R.ttf $out/assets/font.ttf runHook postInstall ''; }; } pkgs/by-name/ph/phira-unwrapped/assets.patch 0 → 100644 +19 −0 Original line number Diff line number Diff line diff --git a/prpr/src/core.rs b/prpr/src/core.rs index 7f9d4db..33c44bb 100644 --- a/prpr/src/core.rs +++ b/prpr/src/core.rs @@ -68,6 +68,14 @@ thread_local! { } pub fn init_assets() { + if let Ok(root_path) = std::env::var("PHIRA_ROOT") { + let path = std::path::Path::new(&root_path); + if path.exists() { + std::env::set_current_dir(path).unwrap(); + set_pc_assets_folder("assets"); + return; + } + } if let Ok(mut exe) = std::env::current_exe() { while exe.pop() { if exe.join("assets").exists() { pkgs/by-name/ph/phira-unwrapped/ffmpeg.patch 0 → 100644 +119 −0 Original line number Diff line number Diff line diff --git a/prpr-avc/Cargo.toml b/prpr-avc/Cargo.toml index 257c575..bf35b10 100644 --- a/prpr-avc/Cargo.toml +++ b/prpr-avc/Cargo.toml @@ -9,3 +9,6 @@ edition = "2021" sasa = { git = "https://github.com/Mivik/sasa", default-features = false } thiserror = "1.0.56" tracing = "0.1.37" + +[build-dependencies] +pkg-config = "0.3" diff --git a/prpr-avc/build.rs b/prpr-avc/build.rs index 961b032..6d0b714 100644 --- a/prpr-avc/build.rs +++ b/prpr-avc/build.rs @@ -1,10 +1,7 @@ use std::path::Path; fn main() { - let libs_dir = std::env::var("PRPR_AVC_LIBS").unwrap_or_else(|_| format!("{}/static-lib", std::env::var("CARGO_MANIFEST_DIR").unwrap())); - let libs_path = Path::new(&libs_dir).join(std::env::var("TARGET").unwrap()); - let libs_path = libs_path.display(); - println!("cargo:rustc-link-search={libs_path}"); - println!("cargo:rustc-link-lib=z"); - println!("cargo:rerun-if-changed={libs_path}"); + for lib in ["libavformat", "libavcodec", "libavutil", "libswscale", "libswresample"] { + let _ = pkg_config::Config::new().statik(false).probe(lib); + } } diff --git a/prpr-avc/src/ffi.rs b/prpr-avc/src/ffi.rs index 8218ef3..a2c7f6a 100644 --- a/prpr-avc/src/ffi.rs +++ b/prpr-avc/src/ffi.rs @@ -6,7 +6,6 @@ pub const AV_SAMPLE_FMT_FLT: AVSampleFormat = 3; pub const AV_ROUND_UP: AVRounding = 0; -#[link(name = "avformat", kind = "static")] extern "C" { pub fn avformat_alloc_context() -> *mut AVFormatContext; pub fn avformat_free_context(s: *mut AVFormatContext); @@ -20,7 +19,6 @@ extern "C" { pub fn av_read_frame(s: *mut AVFormatContext, pkt: *mut AVPacket) -> ::std::os::raw::c_int; } -#[link(name = "avutil", kind = "static")] extern "C" { 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; pub fn av_frame_alloc() -> *mut AVFrame; @@ -29,7 +27,6 @@ extern "C" { pub fn av_rescale_rnd(a: i64, b: i64, c: i64, r: AVRounding) -> i64; } -#[link(name = "avcodec", kind = "static")] extern "C" { pub fn avcodec_find_decoder(id: AVCodecID) -> *mut AVCodec; pub fn avcodec_alloc_context3(codec: *const AVCodec) -> *mut AVCodecContext; @@ -43,7 +40,6 @@ extern "C" { pub fn avcodec_default_get_format(s: *mut AVCodecContext, fmt: *const AVPixelFormat) -> AVPixelFormat; } -#[link(name = "swscale", kind = "static")] extern "C" { pub fn sws_getContext( srcW: ::std::os::raw::c_int, @@ -68,10 +64,9 @@ extern "C" { ) -> ::std::os::raw::c_int; } -#[link(name = "swresample", kind = "static")] extern "C" { - pub fn swr_alloc_set_opts( - s: *mut SwrContext, + pub fn swr_alloc_set_opts2( + ps: *mut *mut SwrContext, out_ch_layout: i64, out_sample_fmt: AVSampleFormat, out_sample_rate: ::std::os::raw::c_int, @@ -80,7 +75,7 @@ extern "C" { in_sample_rate: ::std::os::raw::c_int, log_offset: ::std::os::raw::c_int, log_ctx: *mut ::std::os::raw::c_void, - ) -> *mut SwrContext; + ) -> ::std::os::raw::c_int; pub fn swr_init(s: *mut SwrContext) -> ::std::os::raw::c_int; pub fn swr_get_delay(s: *const SwrContext, base: ::std::os::raw::c_int) -> i64; pub fn swr_convert( diff --git a/prpr-avc/src/swr.rs b/prpr-avc/src/swr.rs index 7288a51..c00b874 100644 --- a/prpr-avc/src/swr.rs +++ b/prpr-avc/src/swr.rs @@ -5,8 +5,9 @@ pub struct SwrContext(OwnedPtr<ffi::SwrContext>); impl SwrContext { pub fn new(in_format: &AudioStreamFormat, out_format: &AudioStreamFormat) -> Result<Self> { unsafe { - OwnedPtr::new(ffi::swr_alloc_set_opts( - null_mut(), + let mut raw: *mut ffi::SwrContext = null_mut(); + let ret = ffi::swr_alloc_set_opts2( + &mut raw, out_format.channel_layout as _, out_format.sample_fmt, out_format.sample_rate, @@ -15,9 +16,12 @@ impl SwrContext { in_format.sample_rate, 0, null_mut(), - )) - .map(|ctx| Self(ctx)) - .ok_or(Error::AllocationFailed) + ); + if ret < 0 || raw.is_null() { + Err(Error::AllocationFailed) + } else { + OwnedPtr::new(raw).map(|ctx| Self(ctx)).ok_or(Error::AllocationFailed) + } } } pkgs/by-name/ph/phira-unwrapped/package.nix 0 → 100644 +87 −0 Original line number Diff line number Diff line { lib, stdenv, fetchFromGitHub, makeDesktopItem, copyDesktopItems, rustPlatform, pkg-config, perl, ffmpeg, alsa-lib, gtk3, }: rustPlatform.buildRustPackage (finalAttrs: { pname = "phira-unwrapped"; version = "0.6.7"; src = fetchFromGitHub { owner = "TeamFlos"; repo = "phira"; tag = "v${finalAttrs.version}"; hash = "sha256-4WIvLfKeh+quu7dHKMlUKt+NQnui2/txlFYZoU3voPA="; }; nativeBuildInputs = [ pkg-config perl copyDesktopItems ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ rustPlatform.bindgenHook # for crate coreaudio-sys ]; buildInputs = [ ffmpeg ] ++ lib.optionals stdenv.hostPlatform.isLinux [ alsa-lib # for crate alsa-sys gtk3 # for crate gtk-sys ]; patches = [ # use dynamically linked ffmpeg instead of expecting static lib ./ffmpeg.patch # error[E0554]: `#![feature]` may not be used on the stable release channel ./stable-features.patch # missing macro from tracing crate ./tracing.patch # allow using env var to specify location of assets and data ./assets.patch ]; cargoHash = "sha256-6mRb3M56G20fA+px1cZyrGpel0v54qoVAQK2ZgTzkmI="; # The developer put assets necessary for this test in gitignore, so it cannot run. checkFlags = [ "--skip test_parse_chart" ]; desktopItems = [ (makeDesktopItem { name = "phira"; desktopName = "Phira"; exec = "phira-main"; icon = "phira"; comment = finalAttrs.meta.description; categories = [ "Game" ]; }) ]; postInstall = '' install -Dm644 assets/icon.png $out/share/icons/hicolor/128x128/apps/phira.png ''; meta = { description = "Rhythm game with custom charts and multiplayer"; homepage = "https://github.com/TeamFlos/phira"; license = lib.licenses.gpl3Only; maintainers = with lib.maintainers; [ ulysseszhan ]; changelog = "https://github.com/TeamFlos/phira/releases/tag/v${finalAttrs.version}"; platforms = lib.platforms.unix; mainProgram = "phira-main"; }; }) pkgs/by-name/ph/phira-unwrapped/stable-features.patch 0 → 100644 +10 −0 Original line number Diff line number Diff line diff --git a/prpr/src/lib.rs b/prpr/src/lib.rs index 15a139f..6b4e469 100644 --- a/prpr/src/lib.rs +++ b/prpr/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(local_key_cell_methods)] - pub mod bin; pub mod config; pub mod core; Loading
pkgs/by-name/ph/phira-free/package.nix 0 → 100644 +32 −0 Original line number Diff line number Diff line { lib, stdenvNoCC, phira, phira-unwrapped, imagemagick, ubuntu-classic, }: phira.override { overrideAssets = stdenvNoCC.mkDerivation { pname = "phira-assets"; version = phira.version; nativeBuildInputs = [ imagemagick ]; dontUnpack = true; installPhase = '' runHook preInstall mkdir -p $out cp -r ${phira-unwrapped.src}/assets $out chmod -R +w $out/assets magick -size 4000x2000 canvas:'rgb(128,162,206)' $out/assets/background.jpg cp ${ubuntu-classic}/share/fonts/truetype/ubuntu/Ubuntu-R.ttf $out/assets/font.ttf runHook postInstall ''; }; }
pkgs/by-name/ph/phira-unwrapped/assets.patch 0 → 100644 +19 −0 Original line number Diff line number Diff line diff --git a/prpr/src/core.rs b/prpr/src/core.rs index 7f9d4db..33c44bb 100644 --- a/prpr/src/core.rs +++ b/prpr/src/core.rs @@ -68,6 +68,14 @@ thread_local! { } pub fn init_assets() { + if let Ok(root_path) = std::env::var("PHIRA_ROOT") { + let path = std::path::Path::new(&root_path); + if path.exists() { + std::env::set_current_dir(path).unwrap(); + set_pc_assets_folder("assets"); + return; + } + } if let Ok(mut exe) = std::env::current_exe() { while exe.pop() { if exe.join("assets").exists() {
pkgs/by-name/ph/phira-unwrapped/ffmpeg.patch 0 → 100644 +119 −0 Original line number Diff line number Diff line diff --git a/prpr-avc/Cargo.toml b/prpr-avc/Cargo.toml index 257c575..bf35b10 100644 --- a/prpr-avc/Cargo.toml +++ b/prpr-avc/Cargo.toml @@ -9,3 +9,6 @@ edition = "2021" sasa = { git = "https://github.com/Mivik/sasa", default-features = false } thiserror = "1.0.56" tracing = "0.1.37" + +[build-dependencies] +pkg-config = "0.3" diff --git a/prpr-avc/build.rs b/prpr-avc/build.rs index 961b032..6d0b714 100644 --- a/prpr-avc/build.rs +++ b/prpr-avc/build.rs @@ -1,10 +1,7 @@ use std::path::Path; fn main() { - let libs_dir = std::env::var("PRPR_AVC_LIBS").unwrap_or_else(|_| format!("{}/static-lib", std::env::var("CARGO_MANIFEST_DIR").unwrap())); - let libs_path = Path::new(&libs_dir).join(std::env::var("TARGET").unwrap()); - let libs_path = libs_path.display(); - println!("cargo:rustc-link-search={libs_path}"); - println!("cargo:rustc-link-lib=z"); - println!("cargo:rerun-if-changed={libs_path}"); + for lib in ["libavformat", "libavcodec", "libavutil", "libswscale", "libswresample"] { + let _ = pkg_config::Config::new().statik(false).probe(lib); + } } diff --git a/prpr-avc/src/ffi.rs b/prpr-avc/src/ffi.rs index 8218ef3..a2c7f6a 100644 --- a/prpr-avc/src/ffi.rs +++ b/prpr-avc/src/ffi.rs @@ -6,7 +6,6 @@ pub const AV_SAMPLE_FMT_FLT: AVSampleFormat = 3; pub const AV_ROUND_UP: AVRounding = 0; -#[link(name = "avformat", kind = "static")] extern "C" { pub fn avformat_alloc_context() -> *mut AVFormatContext; pub fn avformat_free_context(s: *mut AVFormatContext); @@ -20,7 +19,6 @@ extern "C" { pub fn av_read_frame(s: *mut AVFormatContext, pkt: *mut AVPacket) -> ::std::os::raw::c_int; } -#[link(name = "avutil", kind = "static")] extern "C" { 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; pub fn av_frame_alloc() -> *mut AVFrame; @@ -29,7 +27,6 @@ extern "C" { pub fn av_rescale_rnd(a: i64, b: i64, c: i64, r: AVRounding) -> i64; } -#[link(name = "avcodec", kind = "static")] extern "C" { pub fn avcodec_find_decoder(id: AVCodecID) -> *mut AVCodec; pub fn avcodec_alloc_context3(codec: *const AVCodec) -> *mut AVCodecContext; @@ -43,7 +40,6 @@ extern "C" { pub fn avcodec_default_get_format(s: *mut AVCodecContext, fmt: *const AVPixelFormat) -> AVPixelFormat; } -#[link(name = "swscale", kind = "static")] extern "C" { pub fn sws_getContext( srcW: ::std::os::raw::c_int, @@ -68,10 +64,9 @@ extern "C" { ) -> ::std::os::raw::c_int; } -#[link(name = "swresample", kind = "static")] extern "C" { - pub fn swr_alloc_set_opts( - s: *mut SwrContext, + pub fn swr_alloc_set_opts2( + ps: *mut *mut SwrContext, out_ch_layout: i64, out_sample_fmt: AVSampleFormat, out_sample_rate: ::std::os::raw::c_int, @@ -80,7 +75,7 @@ extern "C" { in_sample_rate: ::std::os::raw::c_int, log_offset: ::std::os::raw::c_int, log_ctx: *mut ::std::os::raw::c_void, - ) -> *mut SwrContext; + ) -> ::std::os::raw::c_int; pub fn swr_init(s: *mut SwrContext) -> ::std::os::raw::c_int; pub fn swr_get_delay(s: *const SwrContext, base: ::std::os::raw::c_int) -> i64; pub fn swr_convert( diff --git a/prpr-avc/src/swr.rs b/prpr-avc/src/swr.rs index 7288a51..c00b874 100644 --- a/prpr-avc/src/swr.rs +++ b/prpr-avc/src/swr.rs @@ -5,8 +5,9 @@ pub struct SwrContext(OwnedPtr<ffi::SwrContext>); impl SwrContext { pub fn new(in_format: &AudioStreamFormat, out_format: &AudioStreamFormat) -> Result<Self> { unsafe { - OwnedPtr::new(ffi::swr_alloc_set_opts( - null_mut(), + let mut raw: *mut ffi::SwrContext = null_mut(); + let ret = ffi::swr_alloc_set_opts2( + &mut raw, out_format.channel_layout as _, out_format.sample_fmt, out_format.sample_rate, @@ -15,9 +16,12 @@ impl SwrContext { in_format.sample_rate, 0, null_mut(), - )) - .map(|ctx| Self(ctx)) - .ok_or(Error::AllocationFailed) + ); + if ret < 0 || raw.is_null() { + Err(Error::AllocationFailed) + } else { + OwnedPtr::new(raw).map(|ctx| Self(ctx)).ok_or(Error::AllocationFailed) + } } }
pkgs/by-name/ph/phira-unwrapped/package.nix 0 → 100644 +87 −0 Original line number Diff line number Diff line { lib, stdenv, fetchFromGitHub, makeDesktopItem, copyDesktopItems, rustPlatform, pkg-config, perl, ffmpeg, alsa-lib, gtk3, }: rustPlatform.buildRustPackage (finalAttrs: { pname = "phira-unwrapped"; version = "0.6.7"; src = fetchFromGitHub { owner = "TeamFlos"; repo = "phira"; tag = "v${finalAttrs.version}"; hash = "sha256-4WIvLfKeh+quu7dHKMlUKt+NQnui2/txlFYZoU3voPA="; }; nativeBuildInputs = [ pkg-config perl copyDesktopItems ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ rustPlatform.bindgenHook # for crate coreaudio-sys ]; buildInputs = [ ffmpeg ] ++ lib.optionals stdenv.hostPlatform.isLinux [ alsa-lib # for crate alsa-sys gtk3 # for crate gtk-sys ]; patches = [ # use dynamically linked ffmpeg instead of expecting static lib ./ffmpeg.patch # error[E0554]: `#![feature]` may not be used on the stable release channel ./stable-features.patch # missing macro from tracing crate ./tracing.patch # allow using env var to specify location of assets and data ./assets.patch ]; cargoHash = "sha256-6mRb3M56G20fA+px1cZyrGpel0v54qoVAQK2ZgTzkmI="; # The developer put assets necessary for this test in gitignore, so it cannot run. checkFlags = [ "--skip test_parse_chart" ]; desktopItems = [ (makeDesktopItem { name = "phira"; desktopName = "Phira"; exec = "phira-main"; icon = "phira"; comment = finalAttrs.meta.description; categories = [ "Game" ]; }) ]; postInstall = '' install -Dm644 assets/icon.png $out/share/icons/hicolor/128x128/apps/phira.png ''; meta = { description = "Rhythm game with custom charts and multiplayer"; homepage = "https://github.com/TeamFlos/phira"; license = lib.licenses.gpl3Only; maintainers = with lib.maintainers; [ ulysseszhan ]; changelog = "https://github.com/TeamFlos/phira/releases/tag/v${finalAttrs.version}"; platforms = lib.platforms.unix; mainProgram = "phira-main"; }; })
pkgs/by-name/ph/phira-unwrapped/stable-features.patch 0 → 100644 +10 −0 Original line number Diff line number Diff line diff --git a/prpr/src/lib.rs b/prpr/src/lib.rs index 15a139f..6b4e469 100644 --- a/prpr/src/lib.rs +++ b/prpr/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(local_key_cell_methods)] - pub mod bin; pub mod config; pub mod core;