Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user/c2rust: new package #3122

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions user/c2rust/patches/tomllib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff -ruN a/scripts/query_toml.py b/scripts/query_toml.py
--- a/scripts/query_toml.py 2024-08-30 15:13:52.000000000 +0200
+++ b/scripts/query_toml.py 2024-10-29 10:35:11.831126267 +0100
@@ -3,11 +3,12 @@
from argparse import ArgumentParser
from pathlib import Path
from typing import Any, Iterable
-import toml
+import tomllib


def query_toml(path: Path, query: Iterable[str]) -> Any:
- result = toml.load(path)
+ with open(path, "rb") as f:
+ result = tomllib.load(f)
for field in query:
if isinstance(result, list):
field = int(field)
66 changes: 66 additions & 0 deletions user/c2rust/patches/use-system-tinycbor.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Patch-Source: https://gitlab.alpinelinux.org/alpine/aports/-/blob/a21369ad7a02256c0120b756e0757cd30b449888/testing/c2rust/0002-use-system-tinycbor.patch

Use system's tinycbor instead of vendoring it in
diff -rupN a/c2rust-ast-exporter/build.rs b/c2rust-ast-exporter/build.rs
--- a/c2rust-ast-exporter/build.rs 2023-05-22 22:14:35.000000000 +0200
+++ b/c2rust-ast-exporter/build.rs 2024-01-06 22:54:06.039088094 +0100
@@ -142,7 +142,7 @@ fn build_native(llvm_info: &LLVMInfo) {
};

// Statically link against 'clangAstExporter' which requires 'tinycbor'
- println!("cargo:rustc-link-lib=static=tinycbor");
+ println!("cargo:rustc-link-lib=dylib=tinycbor");
println!("cargo:rustc-link-lib=static=clangAstExporter");

println!("cargo:rustc-link-search=native={}", llvm_lib_dir);
diff -rupN a/c2rust-ast-exporter/src/CMakeLists.txt b/c2rust-ast-exporter/src/CMakeLists.txt
--- a/c2rust-ast-exporter/src/CMakeLists.txt 2023-05-22 22:14:35.000000000 +0200
+++ b/c2rust-ast-exporter/src/CMakeLists.txt 2024-01-06 22:55:39.124799597 +0100
@@ -5,14 +5,9 @@ project(ASTExporter)
# TinyCBOR #
#################################################

-set(TINYCBOR_REPO "https://github.com/intel/tinycbor.git" CACHE STRING "tinycbor git repo URL")
-
-# v0.6.3 tag, but using the commit hash instead (of the tarball hash) for integrity checks
-# unlike a .tar.gz MD5 hash, this SHA-1 commit hash should stay stable regardless of compression/archiving
-# (GitHub has changed this), and still retains the integrity check
-set(TINYCBOR_TAG "d393c16f3eb30d0c47e6f9d92db62272f0ec4dc7" CACHE STRING "tinycbor git tag/branch/commit hash")
-
-set(TINYCBOR_PREFIX "${CMAKE_BINARY_DIR}/tinycbor" CACHE STRING "tinycbor install prefix")
+include(FindPkgConfig)
+pkg_search_module(TINYCBOR REQUIRED tinycbor)
+include_directories(${TINYCBOR_INCLUDE_DIRS})

if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
set(MAKE "gmake")
@@ -20,29 +15,6 @@ else()
set(MAKE "make")
endif()

-include(ExternalProject)
-ExternalProject_Add(tinycbor_build
- PREFIX ${TINYCBOR_PREFIX}
- INSTALL_DIR ${CMAKE_BINARY_DIR}
- GIT_REPOSITORY ${TINYCBOR_REPO}
- GIT_TAG ${TINYCBOR_TAG}
- # the fd redirection here fails when the build run inside Cargo.
- # patch from upstream:
- # https://github.com/intel/tinycbor/commit/6176e0a28d7c5ef3a5e9cbd02521999c412de72c
- PATCH_COMMAND patch --forward -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/tinycbor_fix_build.patch || true
- CONFIGURE_COMMAND ${MAKE} .config && cat ${CMAKE_CURRENT_SOURCE_DIR}/tinycbor.config >> .config
- BUILD_COMMAND ${MAKE} --quiet prefix=<INSTALL_DIR> CFLAGS=-fPIC
- INSTALL_COMMAND ${MAKE} --quiet prefix=<INSTALL_DIR> install
- BUILD_IN_SOURCE 1
- BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/lib/libtinycbor.a
-)
-
-include_directories(${CMAKE_BINARY_DIR}/include)
-
-add_library(tinycbor STATIC IMPORTED)
-set_target_properties(tinycbor PROPERTIES IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/lib/libtinycbor.a)
-add_dependencies(tinycbor tinycbor_build)
-
set(AST_EXPORTER_SRCS
AstExporter.cpp
FloatingLexer.cpp
42 changes: 42 additions & 0 deletions user/c2rust/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
pkgname = "c2rust"
pkgver = "0.19.0"
pkgrel = 0
build_style = "cargo"
make_build_args = ["--package", "c2rust"]
hostmakedepends = [
"cargo-auditable",
"clang-tools-extra",
"cmake",
"pkgconf",
]
makedepends = [
"clang-devel",
"clang-devel-static",
"llvm-devel",
"rust-std",
"tinycbor-devel",
]
checkdepends = [
"python",
"python-plumbum",
"python-psutil",
"python-tomli",
]
pkgdesc = "C to Rust migration tool"
maintainer = "Erica Z <zerica@callcc.eu>"
license = "BSD-3-Clause"
url = "https://c2rust.com"
source = (
f"https://github.com/immunant/c2rust/archive/refs/tags/v{pkgver}.tar.gz"
)
sha256 = "912c28e5e289d1a9ef1e0f6c89db97eba19eda58625ca8bdc5b513fdb3c19ba4"
# check: requires nightly
options = ["!check"]


def install(self):
self.install_bin(f"target/{self.profile().triplet}/release/c2rust")
self.install_bin(
f"target/{self.profile().triplet}/release/c2rust-transpile"
)
self.install_license("LICENSE")
40 changes: 40 additions & 0 deletions user/coverage/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
pkgname = "coverage"
pkgver = "7.6.4"
pkgrel = 0
build_style = "python_pep517"
make_check_args = ["-k", "not VirtualenvTest"]
hostmakedepends = [
"python-build",
"python-installer",
"python-setuptools",
]
makedepends = [
"python-devel",
]
checkdepends = [
"python-flaky",
"python-hypothesis",
"python-pytest",
"python-pytest-xdist",
]
depends = [
"python",
self.with_pkgver("python-coverage"),
]
pkgdesc = "Tool for measuring Python code coverage"
maintainer = "Erica Z <zerica@callcc.eu>"
license = "Apache-2.0"
url = "https://coverage.readthedocs.io"
source = f"$(PYPI_SITE)/c/coverage/coverage-{pkgver}.tar.gz"
sha256 = "29fc0f17b1d3fea332f8001d4558f8214af7f1d87a345f3a133c901d60347c73"


def pre_check(self):
# generate some required test files
self.do("python", "igor.py", "zip_mods")


@subpackage("python-coverage")
def _(self):
self.subdesc = "Python module"
return ["usr/lib"]
1 change: 1 addition & 0 deletions user/python-coverage
35 changes: 35 additions & 0 deletions user/python-plumbum/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pkgname = "python-plumbum"
pkgver = "1.9.0"
pkgrel = 0
build_style = "python_pep517"
make_check_args = [
"-k",
# expects a different error message from ls
"not test_iter_lines_error",
]
hostmakedepends = [
"python-build",
"python-hatch_vcs",
"python-hatchling",
"python-installer",
]
checkdepends = [
"bash",
"openssh",
"procps",
"python-psutil",
"python-pytest",
"python-pytest-cov",
"python-pytest-mock",
"python-pytest-timeout",
]
pkgdesc = "Shell script idioms for Python"
maintainer = "Erica Z <zerica@callcc.eu>"
license = "MIT"
url = "https://plumbum.readthedocs.io/en/stable"
source = f"$(PYPI_SITE)/p/plumbum/plumbum-{pkgver}.tar.gz"
sha256 = "e640062b72642c3873bd5bdc3effed75ba4d3c70ef6b6a7b907357a84d909219"


def post_install(self):
self.install_license("LICENSE")
29 changes: 29 additions & 0 deletions user/python-pytest-cov/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pkgname = "python-pytest-cov"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we removed this before because it's always trivial to patch out (just remove --cov from the pytest args)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same goes for the coverage above then transitively

pkgver = "5.0.0"
pkgrel = 0
build_style = "python_pep517"
hostmakedepends = [
"python-build",
"python-installer",
"python-setuptools",
]
checkdepends = [
"python-coverage",
"python-pytest",
]
depends = [
"python-coverage",
"python-pytest",
]
pkgdesc = "Coverage reports for Pytest"
maintainer = "Erica Z <zerica@callcc.eu>"
license = "MIT"
url = "https://github.com/pytest-dev/pytest-cov"
source = f"$(PYPI_SITE)/p/pytest-cov/pytest-cov-{pkgver}.tar.gz"
sha256 = "5837b58e9f6ebd335b0f8060eecce69b662415b16dc503883a02f45dfeb14857"
# ModuleNotFoundError: No module named 'virtualenv'
options = ["!check"]


def post_install(self):
self.install_license("LICENSE")
1 change: 1 addition & 0 deletions user/tinycbor-devel
1 change: 1 addition & 0 deletions user/tinycbor-progs
38 changes: 38 additions & 0 deletions user/tinycbor/patches/allow-qt6.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
From db9f29d4994d1ccb14f4abbfab335c23b5b1bd84 Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@intel.com>
Date: Wed, 1 May 2024 18:01:24 -0700
Subject: [PATCH] CI/Makefile: do allow Qt 6

I don't think we need to worry about Qt 4 any more.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
---
.github/workflows/build.yml | 2 +-
Makefile | 14 --------------
2 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/Makefile b/Makefile
index 26925eee..6df16553 100644
--- a/Makefile
+++ b/Makefile
@@ -65,20 +65,6 @@ VERSION = $(shell cat $(SRCDIR)VERSION)
SOVERSION = $(shell cut -f1-2 -d. $(SRCDIR)VERSION)
PACKAGE = tinycbor-$(VERSION)

-# Check that QMAKE is Qt 5
-ifeq ($(origin QMAKE),file)
- check_qmake = $(strip $(shell $(1) -query QT_VERSION 2>/dev/null | cut -b1))
- ifneq ($(call check_qmake,$(QMAKE)),5)
- QMAKE := qmake -qt5
- ifneq ($(call check_qmake,$(QMAKE)),5)
- QMAKE := qmake-qt5
- ifneq ($(call check_qmake,$(QMAKE)),5)
- QMAKE := @echo >&2 $(MAKEFILE): Cannot find a Qt 5 qmake; false
- endif
- endif
- endif
-endif
-
-include .config

ifeq ($(wildcard .config),)
26 changes: 26 additions & 0 deletions user/tinycbor/patches/disable-c90-test.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 4df5e4f70045730c045a8fefa9aaadb673513f2a Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@intel.com>
Date: Wed, 1 May 2024 18:26:51 -0700
Subject: [PATCH] Tests: disable the C90 test

We don't support this any more.
```
../../src/cbor.h:255:69: error: '_Bool' is a C99 extension [-Werror,-Wc99-extensions]
CBOR_INLINE_API CborError cbor_encode_boolean(CborEncoder *encoder, bool value)
^
```

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
---
tests/tests.pro | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/tests.pro b/tests/tests.pro
index 6036f0f9..627ffbc1 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -1,3 +1,3 @@
TEMPLATE = subdirs
-SUBDIRS = parser encoder c90 cpp tojson
+SUBDIRS = parser encoder cpp tojson
msvc: SUBDIRS -= tojson
31 changes: 31 additions & 0 deletions user/tinycbor/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pkgname = "tinycbor"
pkgver = "0.6.0"
pkgrel = 0
build_style = "makefile"
make_install_args = ["prefix=/usr"]
make_check_args = ["QMAKE=qmake6"]
hostmakedepends = [
"file",
"pkgconf",
]
checkdepends = ["qt6-qtbase-devel"]
pkgdesc = "Concise binary object representation library"
maintainer = "Erica Z <zerica@callcc.eu>"
license = "MIT"
url = "https://github.com/intel/tinycbor"
source = f"{url}/archive/refs/tags/v{pkgver}.tar.gz"
sha256 = "512e2c9fce74f60ef9ed3af59161e905f9e19f30a52e433fc55f39f4c70d27e4"


def post_install(self):
self.install_license("LICENSE")


@subpackage("tinycbor-devel")
def _(self):
return self.default_devel()


@subpackage("tinycbor-progs")
def _(self):
return self.default_progs()