Skip to content

v0.21.0

Latest

Choose a tag to compare

@kkysen kkysen released this 08 Oct 22:39
· 397 commits to master since this release
93471e6

Major Changes

Portable Types

In #1266, we added support for transpiling portable integer types like size_t and uint64_t. Previously, these were translated in a platform-dependent way, as C defines these portable types as typedefs of the platform-dependent primitive types like int and long.
Now we special case these portable integer types and make sure to translate them as the equivalent Rust portable types, so size_t becomes usize and uint64_t becomes u64, for example.

These still often go through multiple typedefs in C, which become multiple type aliases in Rust, so the definitions are not always textually identical in Rust, but the underlying types should always be portable now.

Const Macros

We previously had an unstable and often broken --translate-const-macros option, which translated const/object-like C macros as Rust consts. This has now been significantly improved and --translate-const-macros conservative is enabled by default. The option has been split into none, conservative, and experimental, so we still allow the previous more experimental translations under experimental, but conservative should generally work and thus is enabled by default. However, some const macros are not yet translatable, like macros referencing other variables, functions, etc., which conservative skips, while some const macros can never be properly translated as a Rust const, such as when it references a variable that is not yet defined. We're still working on improving these cases so that more const macros can be successfully translated, but the current version should capture most usages in the wild. For tmux, 98% of const macro definitions and expansions are successfully translated, for example.

One area in particular we're still working on is the combination of const macros and portable types. The features don't yet work together seamlessly, with const macro types using the old non-portable types and then casting to the portable type at use sites.

SrcLoc Sorting

On stable, sorting now panics when a non-total order is discovered, which was the case in fn compare_src_locs. We had previously tried to fix this, and fixed it in a bunch of cases, but it was still cropping up sometimes, like when transpiling libxml2.

We've now fixed the root cause of incorrect SrcLoc::fileids when we calculate #include paths. Besides fixing any panics, this should improve the sorting of items, which was sometimes buggy before, likely due to this.

cmake 4.0 Support

#1214 adds support for cmake 4.0 by increasing the minimum to cmake 3.5. This should fix any installation issues due to using a new cmake.

LLVM/Clang Support

Misc. Bug Fixes

  • (#1265) Handle all cases of extra braces in string initializers.
  • (#1340) Remove extraneous :: separators in paths with arguments (e.g. ::core::mem::size_of::<libc::c_int>::()).
  • (#1359) Store alloca vector at function-level scope, matching C.
  • (#1360) Avoid mutable transmutes (UB) for string literals (mem::transmute::<[u8; N], [c_char; N]>(*b"") instead of *mem::transmute::<&[u8; N], &mut [c_char; N]>(b"")).
  • (#1361) Support anonymous struct/union/enums within structs and unions.
  • (#1374) Inline asm fixes for ioq3.

Misc. Improvements

  • (#1221, #1222, #1229, #1381) Prefer core:: over libc:: and std::, fixing --emit-no-std.
  • (#1218) Prefer [x; N] over [x, ..., x].
  • (#1344) Skip redundant expressions for ++ and -- (i += 1; i; vs. i += 1;).
  • (#1373) use libc only when needed.

New Instrinsics Added

Changelog

  • docs/readme: Update bear arguments by @javierhonduco in #1206
  • GH Actions: bump tagged versions of actions/cache by @brk in #1212
  • build: support cmake 4.0 by @chenrui333 in #1214
  • CI updates (Ubuntu 22, LLVM 15, pinned once_cell) by @folkertdev in #1219
  • Remove some libc dependencies. by @nnethercote in #1221
  • Fixes to rust-toolchain.toml handling by @joshtriplett in #1225
  • Reduce libc usage in c2rust-transpile by @nnethercote in #1222
  • Remove more unnecessary libc usage by @nnethercote in #1229
  • Make test_translator.py tests pass on LLVM 19 by @nnethercote in #1230
  • Support __float128, which shows up in clang headers on some systems by @joshtriplett in #1235
  • Allow running multiple transpiles in parallel by @jameysharp in #1241
  • transpile: remove invalid Punct::new(' ') in fn convert_asm and update proc-macro2 by @kkysen in #1244
  • Move Linux CI from Azure Pipelines to GitHub Actions by @joshtriplett in #1232
  • Bump bindgen to be able to handle CXCursor_LinkageSpec in LLVM18+ by @spastorino in #1243
  • Fix getBitWidthValue compilation error on LLVM 20+ by @shirok1 in #1248
  • Introduce some snapshot tests of c2rust-transpile by @jameysharp in #1246
  • transpile: some snapshot test fixes by @kkysen in #1258
  • Support C11 atomics required by dav1d by @thedataking in #814
  • transpile: impl __builtin_ia32_pause and __builtin_arm_yield by @thedataking in #1263
  • Various small cleanups by @fw-immunant in #1267
  • More driveby cleanups by @fw-immunant in #1268
  • transpile: Add SIMD intrinsic __builtin_ia32_vperm2f128_pd256/_mm256_permute2f128_pd by @Kriskras99 in #1129
  • transpile: fix doc tests on aarch64 (c_char is unsigned there) by @kkysen in #1255
  • transpile: impl __builtin_rotateright* as core::intrinsics::rotate_right by @kkysen in #1259
  • transpile: emit .rotate_{left,right} instead of core::intrinsics::rotate_{left,right} by @kkysen in #1260
  • Add tests/requirements.txt dependencies into nix python environment by @Chobbes in #1269
  • ci: allow reusing testsuite workflow by @fw-immunant in #1272
  • Allow platform-dependent snapshot test results by @fw-immunant in #1270
  • transpile: operators: resolve type when checking for unsignedness by @fw-immunant in #1273
  • fix compilation error on clang/llvm 21 by @bungcip in #1274
  • ci: switch python to use uv by @kkysen in #1276
  • ci: move macOS azure-pipelines.yml to GitHub Actions with a matrix by @kkysen in #1275
  • ci: add arch to the matrix for clarity by @kkysen in #1284
  • Fix skipping of Paren expressions in typed AST iterators by @fw-immunant in #1286
  • ci: run on both Ubuntu 22.04 and ubuntu-latest by @fw-immunant in #1288
  • Revert "transpile: snapshot: build to stdout rather than creating+deleting rlib" by @kkysen in #1287
  • ci: reorder some steps to cache more (rustup) and run fast checks earlier by @kkysen in #1289
  • transpile: handle all cases of extra braces in string initializers by @kkysen in #1265
  • transpile: do not allow f128::new in const contexts by @fw-immunant in #1294
  • A couple testing tweaks by @fw-immunant in #928
  • test_translator: remove #![feature(nll)], stabilized in 1.63 by @kkysen in #1290
  • scripts: restore provision_mac.sh (removed in #1275) and remove docker scripts by @kkysen in #1299
  • transpile: save platform-specific .rs files, too by @kkysen in #1291
  • ci: test on aarch64 macOS by @kkysen in #1280
  • transpile: add arch-specific snapshots by @kkysen in #1293
  • transpile: revert __builtin_ia32_pause/__builtin_arm_yield to emit _mm_pause and __yield instead of cross-platform spin_loop by @kkysen in #1292
  • Upgrade to Syn 2 by @bungcip in #1271
  • ci: use awalsh128/cache-apt-pkgs-action@latest to cache apt install by @kkysen in #1277
  • Remove snapshot .rs files by @fw-immunant in #1300
  • transpile: use a repeat expression for arrays with a single zero initializer by @folkertdev in #1218
  • transpile: syntax highlight *transpile*.c.snaps as Rust by @kkysen in #1301
  • transpile: add docs and some renames/refactors for code related to macros by @kkysen in #1303
  • Translate C integer types to portable Rust types by @fw-immunant in #1266
  • transpile: tests: snapshots: hard-code nightly toolchain for now by @kkysen in #1310
  • tests: fix out-of-bounds UB in test_casts.rs and cast_funptr.c by @kkysen in #1309
  • transpile: add macros.c snapshot by @kkysen in #1304
  • transpile: add --translate-const-macros conservative by @kkysen in #1305
  • Revert "transpile: make --translate-{const,fn}-macros conservative the default for the CLI, too" by @kkysen in #1313
  • ci: run c2rust-testsuite on all PRs, not just those into master by @kkysen in #1312
  • transpile: fix some mistakes in macros.c snapshot by @kkysen in #1314
  • Apply clippy fixes to stable crates by @brk in #1308
  • Add libzstd-dev to internal testsuite dependencies by @thedataking in #1318
  • transpile: update fn convert_expr docs and remove unused code by @kkysen in #1323
  • transpile: insert casts at const macro expansion sites to their portable override_tys by @kkysen in #1322
  • readme: add known uses of c2rust transpile by @kkysen in #1327
  • transpile: remove unused function in builder by @bungcip in #1316
  • ci: remove x86_64 macOS by @kkysen in #1337
  • transpile: some doc improvements from #1306 by @kkysen in #1336
  • transpile: make TypedAstContext::macro_{invocations,expansions,expansion_test} into IndexMaps instead of HashMaps by @kkysen in #1334
  • transpile: refactor single_attr and call_attr to just use mk().meta_namevalue() and mk().meta_path() instead of creating structure itself by @bungcip in #1343
  • ci: don't install cmake on macOS as it's already installed by @kkysen in #1351
  • Remove extraneous separator from paths with arguments by @brk in #1340
  • transpile: unconditionally make consts use unsafe blocks for --translate-const-macros conservative by @kkysen in #1335
  • properly handle ASTEntryTag::TagStaticAssertDecl conversion by @bungcip in #1342
  • transpile: expand --translate-const-macros conservative to a lot more CExprKinds by @kkysen in #1306
  • Dont write unused unary expr when operator is increment/decrement by @bungcip in #1344
  • scripts/test_translator.py: restore '[ OK ]' prints by @fw-immunant in #1358
  • Change VisitEnumDecl to TraverseDecl by @bungcip in #1357
  • Run rustfmt on the tests by @Rua in #1363
  • transpile: expand --translate-const-macros conservative to handle statements by @kkysen in #1338
  • transpile: add support for CTypeKind::UnaryTypes in --translate-const-macros conservative by @kkysen in #1346
  • transpile: support CastKind::ArrayToPointerDecays in --translate-const-macros conservative by @kkysen in #1349
  • transpile: some simplifications before adding override_tys to const macros by @kkysen in #1370
  • Include libc dependency only when needed by @Rua in #1373
  • Avoid unsafe in const macro translations except where necessary by @fw-immunant in #1339
  • Ensure crate name is a valid identifier by @Rua in #1375
  • Store alloca vectors in top function scope by @Rua in #1359
  • Avoid mutable transmute in string literals by @Rua in #1360
  • Fix inline assembly translation in ioq3 by @fw-immunant in #1374
  • transpile: tests: snapshots: fix vm_x86.c snapshot test by @fw-immunant in #1378
  • transpile: update insta to 1.43.2 for the fix to INSTA_GLOB_FILTER so that the snapshot file is correctly resolved by @kkysen in #1377
  • transpile: const macros: strip implicit casts from macro expansion sites by @fw-immunant in #1311
  • transpile: support anonymous struct/union/enums within structs and unions by @bungcip in #1361
  • cleanup AST builder functionality by @bungcip in #1350
  • pdg: use mutex around cargo runs to avoid file race conditions by @kkysen in #1380
  • transpile: use core::ffi::c_* instead of std::ffi::c_* by @kkysen in #1381
  • transpile: update records.c snapshot test to include #1381 after #1361 merged by @kkysen in #1383
  • ci: enable libxml2 by @kkysen in #1385
  • transpile: const macros: skip DeclRefs by @kkysen in #1387
  • ci: don't cache apt pkgs for c2rust-testsuite since dpkg-query doesn't work correctly by @kkysen in #1389
  • disable warning from clang in snapshot test by @bungcip in #1393
  • ci: run testsuite python2 transpilation by @fw-immunant in #1384
  • transpile: separate top-level decl converting and emitting by @kkysen in #1371
  • transpile: some docs/refactoring improvements made while fixing SrcLoc sorting by @kkysen in #1401
  • transpile: actually fix SrcLoc sorting by fixing include path fileids by @kkysen in #1400
  • Prepare for 0.21.0 release by @kkysen in #1402

New Contributors

Also, many thanks to @Rua and @bungcip for helping us fix a ton of bugs!

Full Changelog: v0.20.0...v0.21.0