From 9da587b4da77c221220e0faa62dca1d7f3f9c0f3 Mon Sep 17 00:00:00 2001 From: Chris <590569+chriskilding@users.noreply.github.com> Date: Wed, 20 Sep 2023 20:05:23 +0100 Subject: [PATCH 1/2] Add Cargo buildsystem --- src/builder-module.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/builder-module.c b/src/builder-module.c index bce91b7f..0c3cb424 100644 --- a/src/builder-module.c +++ b/src/builder-module.c @@ -1515,8 +1515,10 @@ builder_module_build_helper (BuilderModule *self, const char *make_cmd = NULL; const char *test_arg = NULL; - gboolean autotools = FALSE, cmake = FALSE, cmake_ninja = FALSE, meson = FALSE, simple = FALSE, qmake = FALSE; + gboolean autotools = FALSE, cmake = FALSE, cmake_ninja = FALSE, meson = FALSE, simple = FALSE, qmake = FALSE, cargo = FALSE; g_autoptr(GFile) configure_file = NULL; + g_autoptr(GFile) cargo_file = NULL; + g_autoptr(GFile) cargo_lock_file = NULL; g_autoptr(GFile) build_dir = NULL; g_autofree char *build_dir_relative = NULL; gboolean has_configure = FALSE; @@ -1585,6 +1587,8 @@ builder_module_build_helper (BuilderModule *self, simple = TRUE; else if (!strcmp (self->buildsystem, "qmake")) qmake = TRUE; + else if (!strcmp (self->buildsystem, "cargo")) + cargo = TRUE; else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "module %s: Invalid buildsystem: \"%s\"", @@ -1634,6 +1638,22 @@ builder_module_build_helper (BuilderModule *self, return FALSE; } } + else if (cargo) + { + cargo_file = find_file_with_extension (source_subdir, "Cargo.toml"); + if (cargo_file == NULL) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "module: %s: Can't find Cargo.toml", self->name); + return FALSE; + } + + cargo_lock_file = find_file_with_extension (source_subdir, "Cargo.lock"); + if (cargo_lock_file == NULL) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "module: %s: Can't find Cargo.lock", self->name); + return FALSE; + } + } else if (autotools) { configure_file = g_file_get_child (source_subdir, "configure"); @@ -1741,6 +1761,10 @@ builder_module_build_helper (BuilderModule *self, configure_cmd = "meson"; configure_final_arg = g_strdup (".."); } + else if (cargo) + { + // nothing to do - Cargo does not have a configure step + } else { configure_cmd = "../configure"; From 048fc7a9cc4e2637dab1ba2fc011969249d0f966 Mon Sep 17 00:00:00 2001 From: Chris <590569+chriskilding@users.noreply.github.com> Date: Fri, 22 Sep 2023 19:53:07 +0100 Subject: [PATCH 2/2] (WIP) Add Cargo test cases, add cargo check step --- src/builder-module.c | 5 +++++ tests/test-cargo-without-lockfile/Cargo.toml | 6 ++++++ tests/test-cargo-without-lockfile/README.md | 5 +++++ tests/test-cargo-without-lockfile/src/main.rs | 3 +++ tests/test-cargo/Cargo.lock | 7 +++++++ tests/test-cargo/Cargo.toml | 6 ++++++ tests/test-cargo/README.md | 5 +++++ tests/test-cargo/example.yaml | 10 ++++++++++ tests/test-cargo/src/main.rs | 3 +++ 9 files changed, 50 insertions(+) create mode 100644 tests/test-cargo-without-lockfile/Cargo.toml create mode 100644 tests/test-cargo-without-lockfile/README.md create mode 100644 tests/test-cargo-without-lockfile/src/main.rs create mode 100644 tests/test-cargo/Cargo.lock create mode 100644 tests/test-cargo/Cargo.toml create mode 100644 tests/test-cargo/README.md create mode 100644 tests/test-cargo/example.yaml create mode 100644 tests/test-cargo/src/main.rs diff --git a/src/builder-module.c b/src/builder-module.c index 0c3cb424..1af8ce55 100644 --- a/src/builder-module.c +++ b/src/builder-module.c @@ -1896,6 +1896,11 @@ builder_module_build_helper (BuilderModule *self, } else if (simple) make_cmd = NULL; + else if (cargo) + { + make_cmd = "cargo"; + test_arg = "check"; + } else { make_cmd = "make"; diff --git a/tests/test-cargo-without-lockfile/Cargo.toml b/tests/test-cargo-without-lockfile/Cargo.toml new file mode 100644 index 00000000..77a1cefe --- /dev/null +++ b/tests/test-cargo-without-lockfile/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "hello_cargo" +version = "0.1.0" +edition = "2021" + +[dependencies] \ No newline at end of file diff --git a/tests/test-cargo-without-lockfile/README.md b/tests/test-cargo-without-lockfile/README.md new file mode 100644 index 00000000..616f27ab --- /dev/null +++ b/tests/test-cargo-without-lockfile/README.md @@ -0,0 +1,5 @@ +# test-cargo-without-lockfile + +This is an example of a Cargo project with no Cargo.lock file. + +In this case, flatpak-builder should fail, and tell the user to generate the Cargo.lock file first. diff --git a/tests/test-cargo-without-lockfile/src/main.rs b/tests/test-cargo-without-lockfile/src/main.rs new file mode 100644 index 00000000..9151cbdf --- /dev/null +++ b/tests/test-cargo-without-lockfile/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}) diff --git a/tests/test-cargo/Cargo.lock b/tests/test-cargo/Cargo.lock new file mode 100644 index 00000000..dd1d0bba --- /dev/null +++ b/tests/test-cargo/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "hello_cargo" +version = "0.1.0" diff --git a/tests/test-cargo/Cargo.toml b/tests/test-cargo/Cargo.toml new file mode 100644 index 00000000..77a1cefe --- /dev/null +++ b/tests/test-cargo/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "hello_cargo" +version = "0.1.0" +edition = "2021" + +[dependencies] \ No newline at end of file diff --git a/tests/test-cargo/README.md b/tests/test-cargo/README.md new file mode 100644 index 00000000..4972d1b4 --- /dev/null +++ b/tests/test-cargo/README.md @@ -0,0 +1,5 @@ +# test-cargo + +This is an example of a valid Cargo project (with a Cargo.lock file). + +In this case, flatpak-builder should succeed. diff --git a/tests/test-cargo/example.yaml b/tests/test-cargo/example.yaml new file mode 100644 index 00000000..71ed636d --- /dev/null +++ b/tests/test-cargo/example.yaml @@ -0,0 +1,10 @@ +app-id: example +runtime: org.test.Platform +sdk: org.test.Sdk +command: test-cargo +modules: + - name: app + buildsystem: cargo + sources: + - type: dir + path: . diff --git a/tests/test-cargo/src/main.rs b/tests/test-cargo/src/main.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/tests/test-cargo/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}