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 compile errors if c_int is not i32 on some platforms #68

Closed
wants to merge 1 commit into from
Closed

Fix compile errors if c_int is not i32 on some platforms #68

wants to merge 1 commit into from

Conversation

bytedream
Copy link

@bytedream bytedream commented Jul 10, 2024

The error type of littlefs is c_int. On most platforms this equals to i32 and the littlefs2 crate also asserts that, but there are some platforms (like AVR) where c_int is i16 and compiling will result in an error. This PR adds support for those platforms where c_int is i16.

Example build instructions for Atmega328p

Prerequisites (for debian; can be directly used in the rust docker image; workdir must be the root of the littlefs2 crate):

# install avr compiler
apt update
apt install -y gcc-avr avr-libc clang

# the nightly compiler is required
rustup toolchain install --profile minimal --component=rust-src nightly

# target configuration for the atmega328p chip. there also is a avr-unknown-gnu-atmega328 target, but manually defining a file is much more easy than using it
cat <<EOT > avr-atmega328p.json
{
  "arch": "avr",
  "atomic-cas": false,
  "cpu": "atmega328p",
  "data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
  "eh-frame-header": false,
  "exe-suffix": ".elf",
  "late-link-args": {
    "gcc": [
      "-lgcc"
    ]
  },
  "linker": "avr-gcc",
  "llvm-target": "avr-unknown-unknown",
  "max-atomic-width": 8,
  "no-default-libraries": false,
  "pre-link-args": {
    "gcc": [
      "-mmcu=atmega328p"
    ]
  },
  "relocation-model": "static",
  "target-c-int-width": "16",
  "target-pointer-width": "16"
}
EOT

# apply patch described in https://github.com/trussed-dev/littlefs2/issues/30#issuecomment-1472190645
echo 'delog = { version = "0.1.6", git = "https://github.com/LechevSpace/delog.git", rev = "e83f3fd" }' >> Cargo.toml
cargo update

Compile:

cargo +nightly build -Z build-std=core --target=./avr-atmega328p.json --release

@robin-nitrokey
Copy link
Member

Thanks for the PR! We’ve refactored the error type in #67 and I think I already fixed some of the problems as part of it. I’ll have another look at the remaining changes.

@robin-nitrokey
Copy link
Member

@bytedream Please review #69 and check if it fixes your build.

@bytedream
Copy link
Author

@robin-nitrokey yes this fixes it, thank you

@bytedream bytedream closed this Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants