diff --git a/.gitignore b/.gitignore index 5da0ad8..51b5537 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/.cargo \ No newline at end of file +/.cargo +/_build \ No newline at end of file diff --git a/README.md b/README.md index 82e93e1..cf51377 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,13 @@ sudo docker cp $(CONTAINER_ID):/root/lemoa/target/release/lemoa . Once the build is done, there will be an executable `lemoa` binary file in your current directory, executing it starts Lemoa :tada:. +# Building with meson +``` +meson _build +ninja -C _build +sudo ninja -C _build install +``` + # License Lemoa is licensed under the [**GNU General Public License**](https://www.gnu.org/licenses/gpl.html): You can use, study and share it as you want. diff --git a/build-aux/com.lemmy-gtk.lemoa.json b/build-aux/com.lemmy-gtk.lemoa.json new file mode 100644 index 0000000..9e737c6 --- /dev/null +++ b/build-aux/com.lemmy-gtk.lemoa.json @@ -0,0 +1,55 @@ +{ + "id": "com.lemmy-gtk.lemoa", + "runtime": "org.gnome.Platform", + "runtime-version": "42", + "sdk": "org.gnome.Sdk", + "sdk-extensions": [ + "org.freedesktop.Sdk.Extension.rust-stable", + "org.freedesktop.Sdk.Extension.llvm14" + ], + "command": "lemoa", + "finish-args": [ + "--share=ipc", + "--socket=fallback-x11", + "--socket=wayland", + "--device=dri", + "--env=RUST_LOG=gtk_rust_template=debug", + "--env=G_MESSAGES_DEBUG=none", + "--env=RUST_BACKTRACE=1" + ], + "build-options": { + "append-path": "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm14/bin", + "build-args": [ + "--share=network" + ], + "env": { + "CARGO_REGISTRIES_CRATES_IO_PROTOCOL": "sparse", + "CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER": "clang", + "CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS": "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold", + "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER": "clang", + "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS": "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold" + }, + "test-args": [ + "--socket=x11", + "--share=network" + ] + }, + "modules": [ + { + "name": "lemoa", + "buildsystem": "meson", + "run-tests": true, + "config-opts": [ + "-Dprofile=development" + ], + "sources": [ + { + "type": "dir", + "path": "../" + } + ] + } + ] +} + + diff --git a/build-aux/dist-vendor.sh b/build-aux/dist-vendor.sh new file mode 100644 index 0000000..a5fb12f --- /dev/null +++ b/build-aux/dist-vendor.sh @@ -0,0 +1,11 @@ +#!/bin/bash +export DIST="$1" +export SOURCE_ROOT="$2" + +cd "$SOURCE_ROOT" +mkdir "$DIST"/.cargo +cargo vendor | sed 's/^directory = ".*"/directory = "vendor"/g' > $DIST/.cargo/config +# Move vendor into dist tarball directory +mv vendor "$DIST" + + diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..a223b24 --- /dev/null +++ b/meson.build @@ -0,0 +1,43 @@ +project( + 'lemoa', + 'rust', + version: '0.1.0', + meson_version: '>= 0.59', + license: 'GPL-3.0', +) + +gnome = import('gnome') + +application_id = 'com.lemmy-gtk.lemoa' + +dependency('glib-2.0', version: '>= 2.66') +dependency('gio-2.0', version: '>= 2.66') +dependency('gtk4', version: '>= 4.0.0') + +glib_compile_resources = find_program('glib-compile-resources', required: true) +glib_compile_schemas = find_program('glib-compile-schemas', required: true) +desktop_file_validate = find_program('desktop-file-validate', required: false) +cargo = find_program('cargo', required: true) + +version = meson.project_version() + +prefix = get_option('prefix') +bindir = prefix / get_option('bindir') + +datadir = prefix / get_option('datadir') +pkgdatadir = datadir / meson.project_name() + +meson.add_dist_script( + 'build-aux/dist-vendor.sh', + meson.project_build_root() / 'meson-dist' / meson.project_name() + '-' + version, + meson.project_source_root() +) + +subdir('src') + +gnome.post_install( + gtk_update_icon_cache: true, + glib_compile_schemas: true, + update_desktop_database: true, +) + diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..929bc3a --- /dev/null +++ b/src/config.rs @@ -0,0 +1,8 @@ +pub const APP_ID: &str = "com.lemmy-gtk.lemoa"; +pub const GETTEXT_PACKAGE: &str = ; +pub const LOCALEDIR: &str = ; +pub const PKGDATADIR: &str = "/usr/local/share/lemoa"; +pub const PROFILE: &str = ; +pub const RESOURCES_FILE: &str = concat!("/usr/local/share/lemoa", "/resources.gresource"); +pub const VERSION: &str = "0.1.0"; + diff --git a/src/config.rs.in b/src/config.rs.in new file mode 100644 index 0000000..185e82b --- /dev/null +++ b/src/config.rs.in @@ -0,0 +1,8 @@ +pub const APP_ID: &str = @APP_ID@; +pub const GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@; +pub const LOCALEDIR: &str = @LOCALEDIR@; +pub const PKGDATADIR: &str = @PKGDATADIR@; +pub const PROFILE: &str = @PROFILE@; +pub const RESOURCES_FILE: &str = concat!(@PKGDATADIR@, "/resources.gresource"); +pub const VERSION: &str = @VERSION@; + diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..af45b8f --- /dev/null +++ b/src/meson.build @@ -0,0 +1,44 @@ +# Configuration file +conf = configuration_data() +conf.set_quoted('APP_ID', application_id) +conf.set_quoted('PKGDATADIR', pkgdatadir) +conf.set_quoted('VERSION', version) + +configure_file( + input: 'config.rs.in', + output: 'config.rs', + configuration: conf +) + +run_command( + 'cp', + join_paths(meson.project_build_root(), 'src', 'config.rs'), + join_paths(meson.project_source_root(), 'src', 'config.rs'), + check: true +) + +# Setup cargo +cargo = find_program('cargo') +cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ] +cargo_options = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ] +cargo_options += [ '--target-dir', meson.project_build_root() / 'target' ] +cargo_options += [ '--release' ] + +cargo_release = 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', 'target' / 'release' / meson.project_name(), '@OUTPUT@', + ] +) +