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

Fix patch for amalgamated main.rs file #2

Open
wants to merge 4 commits into
base: amalgamate
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
16 changes: 11 additions & 5 deletions amalgamate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ const skippedFiles = new Set([
async function amalgamate({ redefinitions }) {
// console.log(redefinitions);

let seen = new Set();

const commands = JSON.parse((await fsp.readFile("compile_commands.json")).toString())
.map(({ directory, file, output, command, arguments: args }) => {
.flatMap(({ directory, file, output, command, arguments: args }) => {
const relativePath = pathLib.relative(".", file);

if (seen.has(relativePath)) {
return [];
}
seen.add(relativePath);

args = args ?? command.split(/ +/g);
command = args.join(" ");

Expand Down Expand Up @@ -100,14 +107,13 @@ async function amalgamate({ redefinitions }) {
const flagsWithoutDefines = flags.filter(flag => !flag.startsWith(definePrefix));

const includeLines = () => [
...defines().map(({ name, value }) => `#define ${name} ${value}`),
...defines().map(({ name, value }) => `#undef ${name}\n#define ${name} ${value}`),
`#include "${relativePath}"`,
...defines().reverse().map(({ name }) => `#undef ${name}`),
];

const namespace = relativePath.replace(/\W/g, '_');

return {
return [{
directory,
file,
relativePath,
Expand All @@ -120,7 +126,7 @@ async function amalgamate({ redefinitions }) {
flagsWithoutDefines,
includeLines,
namespace,
};
}];
})
// Exclude unit tests as that compiles things twice, leading to redefinition errors.
.filter(e => !e.defines().find(define => define.name === "_UNIT_TEST_"))
Expand Down
17 changes: 14 additions & 3 deletions amalgamate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,21 @@ rm -rf ${rust_dir}.old
mv ${rust_dir} ${rust_dir}.old
cargo new ${rust_dir}
(cd "${rust_dir}"
cargo add libc
cargo add c2rust-bitfields
cargo add memoffset
cargo add f128

# Pin external dependencies so upstream updates don't break our build
cargo add autocfg@=1.2.0
cargo add cc@=1.0.90
cargo add f128@=0.2.9
cargo add f128_input@=0.2.1
cargo add f128_internal@=0.2.2
cargo add libc@=0.2.153
cargo add memoffset@=0.9.1
cargo add num-traits@=0.2.18
cargo add proc-macro2@=1.0.79
cargo add quote@=1.0.35
cargo add syn@=1.0.109
cargo add unicode-ident@=1.0.12

# mv ../${rust_dir}.old/build.rs . # Don't need it.
mv ../${rust_dir}.old/rust-toolchain.toml .
Expand Down
9 changes: 9 additions & 0 deletions cfs_rust_amalgamated/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions cfs_rust_amalgamated/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ name = "cfs_rust_amalgamated"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
autocfg = "=1.2.0"
c2rust-bitfields = "0.18.0"
f128 = "0.2.9"
libc = "0.2.153"
memoffset = "0.9.1"
cc = "=1.0.90"
f128 = "=0.2.9"
f128_input = "=0.2.1"
f128_internal = "=0.2.2"
libc = "=0.2.153"
memoffset = "=0.9.1"
num-traits = "=0.2.18"
proc-macro2 = "=1.0.79"
quote = "=1.0.35"
syn = "=1.0.109"
unicode-ident = "=1.0.12"
2 changes: 1 addition & 1 deletion cfs_rust_amalgamated/src/main.rs.diff
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ index 464f673..d111cd0 100644
}
- Alignment = &mut (*(0 as *mut C2RustUnnamed_25)).Align as *mut CFE_ES_PoolAlign_t as cpuaddr;
+ Alignment = core::mem::align_of::<CFE_ES_PoolAlign_t>() as _;
if Alignment < 4 as libc::c_int as libc::c_ulong {
if Alignment < 4 as libc::c_int as size_t {
Alignment = 4 as libc::c_int as size_t;
}
@@ -50800,10 +50800,9 @@ pub unsafe extern "C" fn CFE_PSP_ExceptionSigHandler(
Expand Down