summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Milosavljevic <dannym@friendly-machines.com>2024-12-21 20:01:20 +0100
committerDanny Milosavljevic <dannym@friendly-machines.com>2024-12-21 20:22:52 +0100
commit63041aacbb3e557dc35a2a4181ddd510acace5ec (patch)
tree93f7bd10391e68ba40d478aa88adbee8b20985cd
parent91af94dc9d628a7b62bce62f8a0da6d3234a91dd (diff)
gnu: Add c2rust.
* gnu/packages/c2rust.scm (c2rust): New variable. * gnu/packages/patches/c2rust-ast-exporter-local-search.patch: New file. * gnu/local.mk (dist_patch_DATA): Add reference to it. Change-Id: I9a80c6071a48ab5baed0a83e1c2463f83a6c6b9b
-rw-r--r--gnu/local.mk1
-rw-r--r--gnu/packages/c2rust.scm48
-rw-r--r--gnu/packages/patches/c2rust-ast-exporter-local-search.patch24
3 files changed, 73 insertions, 0 deletions
diff --git a/gnu/local.mk b/gnu/local.mk
index dce1586e668..9950c9f3b61 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1046,6 +1046,7 @@ dist_patch_DATA = \
1046 %D%/packages/patches/byobu-writable-status.patch \ 1046 %D%/packages/patches/byobu-writable-status.patch \
1047 %D%/packages/patches/bubblewrap-fix-locale-in-tests.patch \ 1047 %D%/packages/patches/bubblewrap-fix-locale-in-tests.patch \
1048 %D%/packages/patches/busybox-add-missing-sha-NI-guard.patch \ 1048 %D%/packages/patches/busybox-add-missing-sha-NI-guard.patch \
1049 %D%/packages/patches/c2rust-ast-exporter-local-search.patch \
1049 %D%/packages/patches/cadical-add-shared-library.patch \ 1050 %D%/packages/patches/cadical-add-shared-library.patch \
1050 %D%/packages/patches/calibre-no-updates-dialog.patch \ 1051 %D%/packages/patches/calibre-no-updates-dialog.patch \
1051 %D%/packages/patches/calibre-remove-test-sqlite.patch \ 1052 %D%/packages/patches/calibre-remove-test-sqlite.patch \
diff --git a/gnu/packages/c2rust.scm b/gnu/packages/c2rust.scm
index 8e913414bb6..a4ba8217deb 100644
--- a/gnu/packages/c2rust.scm
+++ b/gnu/packages/c2rust.scm
@@ -249,3 +249,51 @@
249 (synopsis "C2Rust transpiler implementation") 249 (synopsis "C2Rust transpiler implementation")
250 (description "This package provides C2Rust transpiler implementation.") 250 (description "This package provides C2Rust transpiler implementation.")
251 (license license:bsd-3))) 251 (license license:bsd-3)))
252
253(define-public c2rust
254 (package
255 (name "c2rust")
256 (version "0.18.0")
257 (source
258 (origin
259 (method url-fetch)
260 (uri (crate-uri "c2rust" version))
261 (file-name (string-append name "-" version ".tar.gz"))
262 (sha256
263 (base32 "1rg9cvvmh9zw89mz2bpyvqlwbfhzl5dw2hab9z6d5rasr8mir7nh"))))
264 (build-system cargo-build-system)
265 (native-inputs
266 `(("tinycbor-src" ,%tinycbor-source)
267 ("cmake" ,cmake)
268 ("clang" ,clang)))
269 (inputs (list llvm))
270 (arguments
271 `(#:cargo-inputs (("rust-anyhow" ,rust-anyhow-1)
272 ("rust-c2rust-build-paths" ,rust-c2rust-build-paths-0.18)
273 ("rust-c2rust-transpile" ,rust-c2rust-transpile-0.18)
274 ("rust-clap" ,rust-clap-3)
275 ("rust-env-logger" ,rust-env-logger-0.10)
276 ("rust-git-testament" ,rust-git-testament-0.2)
277 ("rust-is-executable" ,rust-is-executable-1)
278 ("rust-log" ,rust-log-0.4)
279 ("rust-regex" ,rust-regex-1)
280 ("rust-shlex" ,rust-shlex-1)
281 ("rust-time-macros" ,rust-time-macros-0.2))
282 #:phases
283 (modify-phases %standard-phases
284 (add-after 'unpack 'patch-deps
285 (lambda _
286 ;; This is incorrect in the release to begin with.
287 (substitute* "Cargo.toml"
288 (("=0.2.6") "=0.2.18"))))
289 (add-before 'build 'patch
290 (lambda* (#:key inputs #:allow-other-keys)
291 ;; The build process will slightly patch the sources.
292 (copy-recursively (assoc-ref inputs "tinycbor-src")
293 "/tmp/tinycbor")
294 (setenv "CMAKE_TINYCBOR_SOURCE_DIR" "/tmp/tinycbor"))))))
295 (home-page "https://c2rust.com/")
296 (synopsis "C to Rust translation, refactoring, and cross-checking")
297 (description
298 "This package provides C to Rust translation, refactoring, and cross-checking.")
299 (license license:bsd-3)))
diff --git a/gnu/packages/patches/c2rust-ast-exporter-local-search.patch b/gnu/packages/patches/c2rust-ast-exporter-local-search.patch
new file mode 100644
index 00000000000..959321a9f7e
--- /dev/null
+++ b/gnu/packages/patches/c2rust-ast-exporter-local-search.patch
@@ -0,0 +1,24 @@
1diff -ru orig/c2rust-ast-exporter-0.18.0/src/CMakeLists.txt c2rust-ast-exporter-0.18.0/src/CMakeLists.txt
2--- orig/c2rust-ast-exporter-0.18.0/src/CMakeLists.txt 2006-07-24 03:21:28.000000000 +0200
3+++ c2rust-ast-exporter-0.18.0/src/CMakeLists.txt 2024-12-21 12:06:27.056455735 +0100
4@@ -24,8 +24,7 @@
5 ExternalProject_Add(tinycbor_build
6 PREFIX ${TINYCBOR_PREFIX}
7 INSTALL_DIR ${CMAKE_BINARY_DIR}
8- GIT_REPOSITORY ${TINYCBOR_REPO}
9- GIT_TAG ${TINYCBOR_TAG}
10+ SOURCE_DIR ${TINYCBOR_SOURCE_DIR}
11 # the fd redirection here fails when the build run inside Cargo.
12 # patch from upstream:
13 # https://github.com/intel/tinycbor/commit/6176e0a28d7c5ef3a5e9cbd02521999c412de72c
14diff -ru orig/c2rust-ast-exporter-0.18.0/build.rs c2rust-ast-exporter-0.18.0/build.rs
15--- orig/c2rust-ast-exporter-0.18.0/build.rs 2024-12-21 19:37:50.004786236 +0100
16+++ c2rust-ast-exporter-0.18.0/build.rs 2024-12-21 19:39:20.188478196 +0100
17@@ -127,6 +127,7 @@
18 // Build libclangAstExporter.a with cmake
19 let dst = Config::new("src")
20 // Where to find LLVM/Clang CMake files
21+ .define("TINYCBOR_SOURCE_DIR", &env!("CMAKE_TINYCBOR_SOURCE_DIR"))
22 .define("LLVM_DIR", &format!("{}/cmake/llvm", llvm_lib_dir))
23 .define("Clang_DIR", &format!("{}/cmake/clang", llvm_lib_dir))
24 // What to build