This commit is contained in:
Valeria Fadeeva 2024-10-23 11:55:01 +05:00
parent 3b5af9e3c2
commit 0790a6f84c
7 changed files with 65 additions and 49 deletions

25
Cargo.lock generated
View File

@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 4
[[package]] [[package]]
name = "addr2line" name = "addr2line"
@ -28,9 +28,9 @@ dependencies = [
[[package]] [[package]]
name = "alpm" name = "alpm"
version = "3.0.5" version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "310ec5dc25b236ee96bebf975af2d2de85e61001a7c39a0a7436a414ff3f6490" checksum = "c02d4b4d6bc861451437cdbd7feb35385874ff4cc449ace8e793fe8c30533240"
dependencies = [ dependencies = [
"alpm-sys", "alpm-sys",
"bitflags 2.5.0", "bitflags 2.5.0",
@ -38,23 +38,29 @@ dependencies = [
[[package]] [[package]]
name = "alpm-sys" name = "alpm-sys"
version = "3.0.0" version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08a17e0cf15a06d4b86e30c606ee8808ad791300f3bd5e364c30360354b010bd" checksum = "ad5eb56a41bf4f036c600aa1ddff354971926dd8ea29a3fb6589c6c375bf918b"
dependencies = [ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]] [[package]]
name = "alpm-utils" name = "alpm-utils"
version = "3.0.2" version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1a65e48b9a950d1297b865a436733d496b6cdd966133a02fdadc6127dfe37e7" checksum = "7a56cf9221faa08b5a59a9f429cc5338d8e77e22e1d7fe7d3179fc5c3acf7fc3"
dependencies = [ dependencies = [
"alpm", "alpm",
"pacmanconf", "pacmanconf",
] ]
[[package]]
name = "anyhow"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8"
[[package]] [[package]]
name = "arc-swap" name = "arc-swap"
version = "1.7.1" version = "1.7.1"
@ -1006,6 +1012,7 @@ version = "0.10.1"
dependencies = [ dependencies = [
"alpm", "alpm",
"alpm-utils", "alpm-utils",
"anyhow",
"gdk", "gdk",
"gdk-pixbuf", "gdk-pixbuf",
"gio", "gio",
@ -1173,9 +1180,9 @@ dependencies = [
[[package]] [[package]]
name = "pacmanconf" name = "pacmanconf"
version = "2.1.0" version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31d9811f947c6ffc56eeafb789dfad44a7ea7cc383ac3bc6c9b23cd27100bbb1" checksum = "5be1f202256ab200a4fdaaad0988015987876b0aa336ca7a7e685080bab58a40"
dependencies = [ dependencies = [
"cini", "cini",
] ]

View File

@ -6,9 +6,9 @@ license = "GPLv3"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
alpm = { default-features = false, version = "3" } alpm = { default-features = false, version = "4" }
alpm-utils = { features = ["conf"], default-features = false, version = "3" } alpm-utils = { features = ["conf"], default-features = false, version = "4" }
pacmanconf = "2" pacmanconf = "3"
subprocess = "0.2" subprocess = "0.2"
once_cell = { default-features = false, version = "1.19" } once_cell = { default-features = false, version = "1.19" }
@ -26,6 +26,9 @@ reqwest = { version = "0.11", features = ["blocking"] }
unic-langid = "0.9" unic-langid = "0.9"
phf = { version = "0.11", features = ["macros"], default-features = false } phf = { version = "0.11", features = ["macros"], default-features = false }
[build-dependencies]
anyhow = "1"
[profile.release] [profile.release]
strip = "symbols" strip = "symbols"
panic = "abort" panic = "abort"

View File

@ -1,3 +1,4 @@
use std::io::Write;
use std::process::{self, Command}; use std::process::{self, Command};
use std::{env, fs}; use std::{env, fs};
@ -12,7 +13,7 @@ fn main() {
let out_dir = env::var("OUT_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap();
let status = Command::new("glib-compile-resources") let status = Command::new("glib-compile-resources")
.arg(&format!("--target={}/melawy-welcome.gresource", out_dir)) .arg(format!("--target={}/melawy-welcome.gresource", out_dir))
.arg("melawy-welcome.gresource.xml") .arg("melawy-welcome.gresource.xml")
.status() .status()
.unwrap(); .unwrap();
@ -21,4 +22,38 @@ fn main() {
eprintln!("glib-compile-resources failed with exit status {}", status); eprintln!("glib-compile-resources failed with exit status {}", status);
process::exit(1); process::exit(1);
} }
println!("cargo:rerun-if-changed=src/config.rs.in");
println!("cargo:rerun-if-changed=src/config.rs");
gen_config().expect("Failed to gen config.rs");
}
fn gen_config() -> anyhow::Result<()> {
let base_id = "org.melawy.welcome";
let version = env::var("CARGO_PKG_VERSION")?;
let (profile, version_suffix, app_id) = if env::var("PROFILE")? == "debug" {
let profile = "Devel";
let vcs_tag = get_vcs_tag()?;
let version_suffix =
if vcs_tag.is_empty() { "-devel".to_string() } else { format!("-{vcs_tag}") };
(profile.to_owned(), version_suffix, format!("{base_id}.{profile}"))
} else {
(String::new(), String::new(), base_id.to_owned())
};
let final_config = fs::read_to_string("src/config.rs.in")?
.replace("@APP_ID@", &format!("\"{app_id}\""))
.replace("@PROFILE@", &format!("\"{profile}\""))
.replace("@VERSION@", &format!("\"{version}{version_suffix}\""));
let mut file = fs::File::create("src/config.rs")?;
file.write_all(final_config.as_bytes())?;
Ok(())
}
fn get_vcs_tag() -> anyhow::Result<String> {
let output = Command::new("git").args(["rev-parse", "--short", "HEAD"]).output()?;
Ok(String::from_utf8(output.stdout)?)
} }

View File

@ -16,16 +16,10 @@ dependency('glib-2.0', version: '>= 2.66')
dependency('gio-2.0', version: '>= 2.66') dependency('gio-2.0', version: '>= 2.66')
dependency('gtk+-3.0', version: '>= 3.24.33') dependency('gtk+-3.0', version: '>= 3.24.33')
desktop_file_validate = find_program('desktop-file-validate', required: false)
appstream_util = find_program('appstream-util', required: false)
cargo = find_program('cargo', required: true) cargo = find_program('cargo', required: true)
cargo_script = find_program('build-aux/cargo.py') cargo_script = find_program('build-aux/cargo.py')
version = meson.project_version() version = meson.project_version()
version_array = version.split('.')
major_version = version_array[0].to_int()
minor_version = version_array[1].to_int()
version_micro = version_array[2].to_int()
prefix = get_option('prefix') prefix = get_option('prefix')
bindir = prefix / get_option('bindir') bindir = prefix / get_option('bindir')
@ -37,16 +31,9 @@ iconsdir = datadir / 'icons'
if get_option('profile') == 'development' if get_option('profile') == 'development'
profile = 'Devel' profile = 'Devel'
vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD').stdout().strip()
if vcs_tag == ''
version_suffix = '-devel'
else
version_suffix = '-@0@'.format(vcs_tag)
endif
application_id = '@0@.@1@'.format(base_id, profile) application_id = '@0@.@1@'.format(base_id, profile)
else else
profile = '' profile = ''
version_suffix = ''
application_id = base_id application_id = base_id
endif endif

View File

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
git add . && git commit -m "Update" && git push git add . && git commit -m "Update"
git push
echo "Ready" echo "Ready"

View File

@ -1,13 +1,13 @@
use crate::config::{APP_ID, PKGDATADIR, VERSION};
use crate::widgets::MainWindow;
use std::path::Path;
use gtk::gio; use gtk::gio;
use gtk::glib::{self, clone, WeakRef}; use gtk::glib::{self, clone, WeakRef};
use gtk::prelude::*; use gtk::prelude::*;
use gtk::subclass::prelude::*; use gtk::subclass::prelude::*;
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use std::path::Path;
use crate::config::{APP_ID, PKGDATADIR, VERSION};
use crate::widgets::MainWindow;
/* /*
mod imp { mod imp {
use super::*; use super::*;

View File

@ -1,20 +1,3 @@
global_conf = configuration_data()
global_conf.set_quoted('APP_ID', application_id)
global_conf.set_quoted('PROFILE', profile)
global_conf.set_quoted('VERSION', version + version_suffix)
config = configure_file(
input: 'config.rs.in',
output: 'config.rs',
configuration: global_conf
)
# Copy the config.rs output to the source directory.
run_command(
'cp',
meson.project_build_root() / 'src' / 'config.rs',
meson.project_source_root() / 'src' / 'config.rs',
check: true
)
manifest_path = meson.project_source_root() / 'Cargo.toml' manifest_path = meson.project_source_root() / 'Cargo.toml'
cargo_home = meson.project_build_root() / 'cargo-home' cargo_home = meson.project_build_root() / 'cargo-home'
cargo_target_dir = meson.project_build_root() / 'src' cargo_target_dir = meson.project_build_root() / 'src'