diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-03-23 20:52:55 +0100 |
|---|---|---|
| committer | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-04-05 00:31:21 +0200 |
| commit | ef32d65ac1852da581ac75d20f903dbcb2d0b5cd (patch) | |
| tree | 98cdb79c471babd906368d23171fe10168c18062 /src | |
| parent | dae5942e2ad1ac59f6217ad0f8e0bd630d0b4747 (diff) | |
Use meson as a build system
Diffstat (limited to 'src')
| -rw-r--r-- | src/constants.rs | 4 | ||||
| -rw-r--r-- | src/i18n.rs | 8 | ||||
| -rw-r--r-- | src/info.rs | 2 | ||||
| -rw-r--r-- | src/info.rs.in | 2 | ||||
| -rw-r--r-- | src/main.rs | 7 | ||||
| -rw-r--r-- | src/meson.build | 49 | ||||
| -rw-r--r-- | src/preferences/storage.rs | 4 |
7 files changed, 62 insertions, 14 deletions
diff --git a/src/constants.rs b/src/constants.rs index f4b7836..c2e0eb6 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -23,10 +23,6 @@ pub const ZOOM_STEP: f64 = 0.1; pub const FILE_EXTENSION: &str = "wmap"; pub const MIME_TYPE: &str = "application/vnd.wmap"; -// Application -pub const APP_NAME: &str = "Map"; -pub const APP_ID: &str = "systems.tranquil.Map"; - // Window defaults pub const DEFAULT_WINDOW_WIDTH: i32 = 300; pub const DEFAULT_WINDOW_HEIGHT: i32 = 100; diff --git a/src/i18n.rs b/src/i18n.rs index 35955a1..03c30c3 100644 --- a/src/i18n.rs +++ b/src/i18n.rs @@ -16,11 +16,9 @@ //! Internationalization support using gettext. +use crate::info; use gettextrs::{LocaleCategory, bindtextdomain, setlocale, textdomain}; -/// The gettext domain for the application. -pub const GETTEXT_DOMAIN: &str = "systems.tranquil.Map"; - /// Initializes the localization system. pub fn init() { setlocale(LocaleCategory::LcAll, ""); @@ -38,12 +36,12 @@ pub fn init() { for dir in &locale_dirs { if std::path::Path::new(dir).exists() { - let _ = bindtextdomain(GETTEXT_DOMAIN, *dir); + let _ = bindtextdomain(info::GETTEXT_DOMAIN, *dir); break; } } - textdomain(GETTEXT_DOMAIN).ok(); + textdomain(info::GETTEXT_DOMAIN).ok(); } /// Macro for translating strings at runtime. diff --git a/src/info.rs b/src/info.rs new file mode 100644 index 0000000..1c2a22f --- /dev/null +++ b/src/info.rs @@ -0,0 +1,2 @@ +pub const APP_ID: &str = "systems.tranquil.Map"; +pub const GETTEXT_DOMAIN: &str = "systems.tranquil.Map"; diff --git a/src/info.rs.in b/src/info.rs.in new file mode 100644 index 0000000..835d5a2 --- /dev/null +++ b/src/info.rs.in @@ -0,0 +1,2 @@ +pub const APP_ID: &str = @APP_ID@; +pub const GETTEXT_DOMAIN: &str = @GETTEXT_DOMAIN@; diff --git a/src/main.rs b/src/main.rs index 344a30d..e40681f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ mod dialogs; mod file_registry; mod handlers; mod i18n; +mod info; mod preferences; mod stages; @@ -176,9 +177,9 @@ impl AppModel { .unwrap_or(&default_name); if self.modified { - format!("{}* - {}", filename, constants::APP_NAME) + format!("{}* - {}", filename, tr!("application.name")) } else { - format!("{} - {}", filename, constants::APP_NAME) + format!("{} - {}", filename, tr!("application.name")) } } @@ -639,7 +640,7 @@ fn main() { .find(|t| t.is_default) .map(|t| t.content.clone()); - let application = RelmApp::new(constants::APP_ID); + let application = RelmApp::new(info::APP_ID); application.run::<AppModel>(AppInit { zoom: 1.0, orientation: gtk::Orientation::Horizontal, diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..6ce0ee9 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,49 @@ +source_configuration = configuration_data() +source_configuration.set_quoted('APP_ID', application_id) +source_configuration.set_quoted('GETTEXT_DOMAIN', gettext_domain) +configure_file( + input: 'info.rs.in', + output: '@BASENAME@', + configuration: source_configuration +) + +run_command( + 'cp', + meson.project_build_root() / 'src' / 'info.rs', + meson.project_source_root() / 'src' / 'info.rs', + check: true, +) + +cargo_options = ['--manifest-path', meson.project_source_root() / 'Cargo.toml'] +cargo_options += ['--target-dir', meson.project_build_root() / 'src'] +cargo_env = ['CARGO_HOME=' + meson.project_build_root() / 'cargo-home'] + +if get_option('profile') == 'default' + cargo_options += ['--release'] + rust_target = 'release' + message('Building in release mode') +else + rust_target = 'debug' + message('Building in debug mode') +endif + +custom_target( + 'cargo-build', + build_by_default: true, + build_always_stale: true, + output: meson.project_name(), + console: true, + install: true, + install_dir: bindir, + command: [ + 'env', + cargo_env, + cargo, + 'build', + cargo_options, + '&&', + 'cp', + 'src' / rust_target / meson.project_name(), + '@OUTPUT@', + ], +) diff --git a/src/preferences/storage.rs b/src/preferences/storage.rs index b61266b..6d8f199 100644 --- a/src/preferences/storage.rs +++ b/src/preferences/storage.rs @@ -17,7 +17,7 @@ use std::fs; use std::path::PathBuf; -use crate::constants; +use crate::info; use super::models::{UserPreferences, UserPreferencesJson}; @@ -25,7 +25,7 @@ use super::models::{UserPreferences, UserPreferencesJson}; pub fn config_dir() -> PathBuf { dirs::config_dir() .unwrap_or_else(|| PathBuf::from(".")) - .join(constants::APP_ID) + .join(info::APP_ID) } /// Returns the preferences file path |