1
Fork 0

Make nix build slightly less broken

This commit is contained in:
prescientmoon 2025-02-11 07:04:39 +01:00
parent 489568650a
commit ac6cad7848
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
24 changed files with 33 additions and 48 deletions

View file

@ -1,6 +1,4 @@
{
lib,
pkg-config,
makeWrapper,
@ -16,20 +14,18 @@
private-config,
}:
let
src = lib.cleanSource ../.;
rustPlatform = makeRustPlatform {
cargo = rust-toolchain;
rustc = rust-toolchain;
};
in
rustPlatform.buildRustPackage {
inherit src;
pname = "shimmeringmoon";
version = "unstable-2025-02-11";
src = ../.;
SHIMMERING_FONTS_DIR = shimmering-fonts;
SHIMMERING_FONT_DIR = shimmering-fonts;
SHIMMERING_CC_DIR = cc-data;
SHIMMERING_PRIVATE_CONFIG_DIR = private-config;
nativeBuildInputs = [
pkg-config
@ -37,20 +33,16 @@ rustPlatform.buildRustPackage {
makeWrapper
];
preBuild = ''
export SHIMMERING_SOURCE_DIR="$src"
'';
# TODO: is this supposed to be here???
# LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
buildInputs = [
freetype
fontconfig
sqlite
openssl
src # Idk if putting this here is correct, but it is required at runtime...
];
# TODO: do I need to add this
# LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
cargoLock = {
lockFile = ../Cargo.lock;
outputHashes = {
@ -63,6 +55,14 @@ rustPlatform.buildRustPackage {
# Disable all tests
doCheck = false;
postBuild = ''
for file in $out/bin/*; do
wrapProgram $file \
--set SHIMMERING_CC_DIR "${cc-data}" \
--set SHIMMERING_PRIVATE_CONFIG_DIR ${private-config}
done
'';
meta = {
description = "Arcaea score management toolchain";
homepage = "https://git.moonythm.dev/prescientmoon/shimmeringmoon";

View file

@ -21,11 +21,11 @@ struct NotecountEntry {
notecount: u32,
}
fn get_notecount_records(paths: &ShimmeringPaths) -> anyhow::Result<Vec<NotecountEntry>> {
pub const NOTECOUNT_DATA: &[u8] = include_bytes!("notecounts.csv");
fn get_notecount_records() -> anyhow::Result<Vec<NotecountEntry>> {
let mut entries = Vec::new();
let mut reader = csv::Reader::from_reader(std::io::BufReader::new(std::fs::File::open(
paths.notecount_path(),
)?));
let mut reader = csv::Reader::from_reader(std::io::Cursor::new(NOTECOUNT_DATA));
for result in reader.records() {
let record = result?;
@ -167,8 +167,7 @@ pub fn import_songlist(
paths: &ShimmeringPaths,
conn: &mut rusqlite::Connection,
) -> anyhow::Result<()> {
let notecount_records =
get_notecount_records(paths).context("Failed to read notecount records")?;
let notecount_records = get_notecount_records().context("Failed to read notecount records")?;
let ptt_entries = get_ptt_entries(paths).context("Failed to read ptt entries")?;
let transaction = conn.transaction()?;

View file

@ -45,12 +45,7 @@ pub static UNI_FONT: RefCell<Font> = get_font!("unifont.otf");
// {{{ Asset art helpers
macro_rules! get_asset {
($name: ident, $file:expr) => {
get_asset!(
$name,
$file,
concat!(env!("SHIMMERING_SOURCE_DIR"), "/assets"),
|d: DynamicImage| d
);
get_asset!($name, $file, "assets", |d: DynamicImage| d);
};
($name: ident, $file:expr, $dir: expr, $f:expr) => {
pub static $name: LazyLock<RgbaImage> = LazyLock::new(move || {

View file

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View file

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View file

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View file

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View file

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View file

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

View file

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 4 KiB

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View file

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View file

Before

Width:  |  Height:  |  Size: 752 B

After

Width:  |  Height:  |  Size: 752 B

View file

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View file

Before

Width:  |  Height:  |  Size: 5 KiB

After

Width:  |  Height:  |  Size: 5 KiB

View file

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 47 KiB

View file

@ -150,7 +150,7 @@ async fn friend_code_impl<C: MessageContext>(
ctx: &mut C,
target_user: poise::serenity_prelude::User,
) -> Result<(), TaggedError> {
let user = User::from_context(ctx)?;
User::from_context(ctx)?;
let target = User::by_discord_id(ctx.data(), target_user.id)?;

View file

@ -6,8 +6,8 @@ use r2d2_sqlite::SqliteConnectionManager;
use rusqlite_migration::Migrations;
use std::sync::LazyLock;
use crate::arcaea::import_charts::import_songlist;
use crate::context::hash::hash_files;
use crate::arcaea::import_charts::{import_songlist, NOTECOUNT_DATA};
use crate::context::hash::{hash_bytes, hash_files};
use crate::context::paths::ShimmeringPaths;
use crate::context::process_jackets::process_jackets;
// }}}
@ -35,7 +35,7 @@ pub fn connect_db(paths: &ShimmeringPaths) -> anyhow::Result<SqlitePool> {
let current_raw_jackets_hash = hash_files(&paths.raw_jackets_path())?;
let current_songlist_hash = hash_files(&paths.songlist_path())?;
let current_cc_data_hash = hash_files(&paths.cc_data_path())?;
let current_notecount_hash = hash_files(&paths.notecount_path())?;
let current_notecount_hash = hash_bytes(NOTECOUNT_DATA);
let (prev_raw_jackets_hash, prev_songlist_hash, prev_cc_data_hash, prev_notecount_hash) = conn
.query_row("SELECT * FROM metadata", (), |row| {

View file

@ -22,3 +22,11 @@ pub fn hash_files(path: &std::path::Path) -> anyhow::Result<String> {
let string = base16ct::lower::encode_string(&res);
Ok(string)
}
pub fn hash_bytes(bytes: &[u8]) -> String {
let mut hasher = Sha256::default();
hasher.update(bytes);
let res = hasher.finalize();
let string = base16ct::lower::encode_string(&res);
string
}

View file

@ -39,9 +39,6 @@ pub struct ShimmeringPaths {
/// This directory contains logs and other debugging info.
log_dir: PathBuf,
/// This location the source-code resides at
source_dir: PathBuf,
}
impl ShimmeringPaths {
@ -52,7 +49,6 @@ impl ShimmeringPaths {
data_dir: get_env_dir_path("SHIMMERING_DATA_DIR", Some("STATE_DIRECTORY"))?,
log_dir: get_env_dir_path("SHIMMERING_LOG_DIR", Some("LOGS_DIRECTORY"))?,
private_config_dir: get_env_dir_path("SHIMMERING_PRIVATE_CONFIG_DIR", None)?,
source_dir: PathBuf::from_str(env!("SHIMMERING_SOURCE_DIR")).unwrap(),
};
Ok(res)
@ -86,18 +82,6 @@ impl ShimmeringPaths {
self.private_config_dir.join("songlist.json")
}
pub fn scripts_dir(&self) -> PathBuf {
self.source_dir.join("scripts")
}
pub fn config_dir(&self) -> PathBuf {
self.source_dir.join("config")
}
pub fn notecount_path(&self) -> PathBuf {
self.config_dir().join("notecounts.csv")
}
pub fn cc_data_path(&self) -> PathBuf {
PathBuf::from_str(concat!(env!("SHIMMERING_CC_DIR"), "/ptt.json")).unwrap()
}

View file

@ -21,7 +21,7 @@ fn should_save_debug_images() -> bool {
#[inline]
fn get_log_dir() -> PathBuf {
get_env_dir_path("SHIMMERING_LOG_DIR", "LOGS_DIRECTORY").unwrap()
get_env_dir_path("SHIMMERING_LOG_DIR", Some("LOGS_DIRECTORY")).unwrap()
}
#[inline]

View file

@ -100,8 +100,7 @@ impl UIMeasurements {
let mut measurements = Vec::new();
let mut measurement = UIMeasurement::default();
const CONTENTS: &str =
include_str!(concat!(env!("SHIMMERING_SOURCE_DIR"), "/config/ui.txt"));
const CONTENTS: &str = include_str!("ui.txt");
// {{{ Parse measurement file
for (i, line) in CONTENTS.split('\n').enumerate() {