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