[gnome-builder] plugins/meson-templates/rust: Handles pre-existing source files nicely with Cargo
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/meson-templates/rust: Handles pre-existing source files nicely with Cargo
- Date: Tue, 16 Aug 2022 19:12:00 +0000 (UTC)
commit 674b6e0c8c4f02a3710040462d54dcd624297469
Author: William Roy <wroy proton me>
Date: Fri Aug 12 19:20:45 2022 -0400
plugins/meson-templates/rust: Handles pre-existing source files nicely with Cargo
Signed-off-by: William Roy <wroy proton me>
.../meson-templates/gbp-meson-template-provider.c | 2 --
.../meson-templates/meson-templates.gresource.xml | 1 -
.../meson-templates/resources/build-aux/cargo.sh | 24 -----------------
src/plugins/meson-templates/resources/meson.build | 6 -----
.../meson-templates/resources/src/Cargo-gtk4.toml | 2 +-
.../meson-templates/resources/src/meson-cli.build | 31 +++++++++++++---------
.../resources/src/meson-rs-gtk4.build | 30 ++++++++++-----------
7 files changed, 33 insertions(+), 63 deletions(-)
---
diff --git a/src/plugins/meson-templates/gbp-meson-template-provider.c
b/src/plugins/meson-templates/gbp-meson-template-provider.c
index a58d14ccd..4d8a66508 100644
--- a/src/plugins/meson-templates/gbp-meson-template-provider.c
+++ b/src/plugins/meson-templates/gbp-meson-template-provider.c
@@ -93,7 +93,6 @@ static GbpMesonTemplateExpansion gtk4_expansions[] = {
{ "src/window-gtk4.ui", "src/window.ui", IDE_STRV_INIT ("Python") },
/* Rust */
- { "build-aux/cargo.sh", "build-aux/cargo.sh", IDE_STRV_INIT ("Rust") },
{ "src/Cargo-gtk4.toml", "Cargo.toml", IDE_STRV_INIT ("Rust") },
{ "src/Cargo.lock", "Cargo.lock", IDE_STRV_INIT ("Rust") },
{ "src/application-gtk4.rs", "src/application.rs", IDE_STRV_INIT ("Rust") },
@@ -149,7 +148,6 @@ static GbpMesonTemplateExpansion cli_expansions[] = {
{ "src/Cargo.lock", "Cargo.lock", IDE_STRV_INIT ("Rust") },
{ "src/Cargo-cli.toml", "Cargo.toml", IDE_STRV_INIT ("Rust") },
{ "src/main-cli.rs", "src/main.rs", IDE_STRV_INIT ("Rust") },
- { "build-aux/cargo.sh", "build-aux/cargo.sh", IDE_STRV_INIT ("Rust") },
/* Vala */
{ "src/meson-cli.build", "src/meson.build", IDE_STRV_INIT ("Vala") },
diff --git a/src/plugins/meson-templates/meson-templates.gresource.xml
b/src/plugins/meson-templates/meson-templates.gresource.xml
index 32bb3853d..b1e95747f 100644
--- a/src/plugins/meson-templates/meson-templates.gresource.xml
+++ b/src/plugins/meson-templates/meson-templates.gresource.xml
@@ -43,7 +43,6 @@
<file compressed="true">resources/src/Cargo.lock</file>
<file compressed="true">resources/src/Cargo-gtk4.toml</file>
<file compressed="true">resources/src/Cargo-cli.toml</file>
- <file compressed="true">resources/build-aux/cargo.sh</file>
<file compressed="true">resources/meson.build</file>
<file compressed="true">resources/src/meson-cli.build</file>
<file compressed="true">resources/src/meson-py-cli.build</file>
diff --git a/src/plugins/meson-templates/resources/meson.build
b/src/plugins/meson-templates/resources/meson.build
index def9f1832..4027a17f0 100644
--- a/src/plugins/meson-templates/resources/meson.build
+++ b/src/plugins/meson-templates/resources/meson.build
@@ -93,12 +93,6 @@ foreach arg: test_c_args
endforeach
add_project_arguments(project_c_args, language: 'c')
{{end}}
-{{if language == "rust"}}
-cargo_sources = files(
- 'Cargo.toml',
- 'Cargo.lock',
-)
-{{end}}
{{if enable_gnome}}
subdir('data')
diff --git a/src/plugins/meson-templates/resources/src/Cargo-gtk4.toml
b/src/plugins/meson-templates/resources/src/Cargo-gtk4.toml
index b692b2b41..72e0103d9 100644
--- a/src/plugins/meson-templates/resources/src/Cargo-gtk4.toml
+++ b/src/plugins/meson-templates/resources/src/Cargo-gtk4.toml
@@ -5,7 +5,7 @@ edition = "2021"
[dependencies]
gettext-rs = { version = "0.7", features = ["gettext-system"] }
-gtk = { version = "0.4.7", package = "gtk4" }
+gtk = { version = "0.4.8", package = "gtk4" }
{{if is_adwaita}}
[dependencies.adw]
diff --git a/src/plugins/meson-templates/resources/src/meson-cli.build
b/src/plugins/meson-templates/resources/src/meson-cli.build
index 6e4983397..18210b68c 100644
--- a/src/plugins/meson-templates/resources/src/meson-cli.build
+++ b/src/plugins/meson-templates/resources/src/meson-cli.build
@@ -1,3 +1,4 @@
+{{if language != "rust"}}
{{name_}}_sources = [
{{if language == "c"}}
'main.c',
@@ -5,9 +6,6 @@
'main.cpp',
{{else if language == "vala"}}
'main.vala',
-{{else if language == "rust"}}
- cargo_sources,
- 'main.rs',
{{end}}
]
@@ -20,29 +18,36 @@
{{end}}
]
-{{if language != "rust"}}
executable('{{name}}', {{name_}}_sources,
{{if language == "vala"}} vala_args: '--target-glib=2.58',{{end}}
dependencies: {{name_}}_deps,
install: true,
)
+
{{else}}
-cargo_script = find_program(join_paths(meson.project_source_root(), 'build-aux/cargo.sh'))
-cargo_release = custom_target(
+cargo_bin = find_program('cargo')
+cargo_opt = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ]
+cargo_opt += [ '--target-dir', meson.project_build_root() / 'src' ]
+cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
+
+if get_option('buildtype') == 'release'
+ cargo_options += [ '--release' ]
+ rust_target = 'release'
+else
+ rust_target = 'debug'
+endif
+
+cargo_build = custom_target(
'cargo-build',
build_by_default: true,
- input: {{name_}}_sources,
output: meson.project_name(),
console: true,
install: true,
install_dir: get_option('bindir'),
command: [
- cargo_script,
- meson.project_build_root(),
- meson.project_source_root(),
- '@OUTPUT@',
- get_option('buildtype'),
- meson.project_name(),
+ 'env', cargo_env,
+ cargo_bin, 'build',
+ cargo_opt, '&&', 'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@',
]
)
{{end}}
diff --git a/src/plugins/meson-templates/resources/src/meson-rs-gtk4.build
b/src/plugins/meson-templates/resources/src/meson-rs-gtk4.build
index d47d2bd22..4892c3db5 100644
--- a/src/plugins/meson-templates/resources/src/meson-rs-gtk4.build
+++ b/src/plugins/meson-templates/resources/src/meson-rs-gtk4.build
@@ -28,30 +28,28 @@ run_command(
check: true
)
-rust_sources = files(
- 'application.rs',
- 'config.rs',
- 'main.rs',
- 'window.rs',
-)
+cargo_bin = find_program('cargo')
+cargo_opt = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ]
+cargo_opt += [ '--target-dir', meson.project_build_root() / 'src' ]
+cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
-sources = [cargo_sources, rust_sources]
+if get_option('buildtype') == 'release'
+ cargo_options += [ '--release' ]
+ rust_target = 'release'
+else
+ rust_target = 'debug'
+endif
-cargo_script = find_program(join_paths(meson.project_source_root(), 'build-aux/cargo.sh'))
-cargo_release = custom_target(
+cargo_build = custom_target(
'cargo-build',
build_by_default: true,
- input: sources,
output: meson.project_name(),
console: true,
install: true,
install_dir: get_option('bindir'),
command: [
- cargo_script,
- meson.project_build_root(),
- meson.project_source_root(),
- '@OUTPUT@',
- get_option('buildtype'),
- meson.project_name(),
+ 'env', cargo_env,
+ cargo_bin, 'build',
+ cargo_opt, '&&', 'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@',
]
)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]