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

Issues building libtock-c with Nix #352

Closed
lschuermann opened this issue Oct 31, 2023 · 3 comments
Closed

Issues building libtock-c with Nix #352

lschuermann opened this issue Oct 31, 2023 · 3 comments

Comments

@lschuermann
Copy link
Member

lschuermann commented Oct 31, 2023

I got this error on some examples when running examples/build_all.sh in a nix-shell.

can't link soft-float modules with double-float modules

I went spelunking in issues which ended up here tock/tock#1246. I was able to do a workaround (sources 1, 2). This is not a permanent fix, but I monkey patched --enable-multilib to get things to work locally. I see there is some stuff noted in the readme, but the build_all script should just work with no intervention.

Diff with everything I did to get things to work

diff --git a/Configuration.mk b/Configuration.mk
index 4e71e02..0f6b327 100644
--- a/Configuration.mk
+++ b/Configuration.mk
@@ -129,7 +129,7 @@ ifndef ELF2TAB_EXISTS
   ELF2TAB_VERSION := $(shell $(SHELL) -c "$(ELF2TAB) --version | cut -d ' ' -f 2")
   UPGRADE_ELF2TAB := $(shell $(SHELL) -c "printf '%s\n%s\n' '$(ELF2TAB_REQUIRED_VERSION)' '$(ELF2TAB_VERSION)' | sort --check=quiet --version-sort || echo yes")
   ifeq ($(UPGRADE_ELF2TAB),yes)
-    $(error Failed to automatically update elf2tab, please update manually elf2tab to >= $(ELF2TAB_REQUIRED_VERSION))
+#     $(error Failed to automatically update elf2tab, please update manually elf2tab to >= $(ELF2TAB_REQUIRED_VERSION))
   endif
 endif
 
diff --git a/shell.nix b/shell.nix
index 640361c..da78c32 100644
--- a/shell.nix
+++ b/shell.nix
@@ -54,6 +54,7 @@ in
       gcc-arm-embedded
       python3Full
       tockloader
+      uncrustify
     ] ++ (lib.optionals withUnfreePkgs [
       segger-jlink
       tockloader.nrf-command-line-tools
@@ -70,7 +71,7 @@ in
             "--without-headers"
             "--disable-shared"
             "--disable-libssp"
-            "--disable-multilib"
+            "--enable-multilib"
             "--with-newlib"
           ];
           gcc_cv_libc_provides_ssp = "yes";
diff --git a/tools/uncrustify/uncrustify.sh b/tools/uncrustify/uncrustify.sh
index 285e0fd..6f69665 100755
--- a/tools/uncrustify/uncrustify.sh
+++ b/tools/uncrustify/uncrustify.sh
@@ -17,9 +17,7 @@ if ! command -v uncrustify >/dev/null; then
 else
   # Validate uncrustify version
   VERSION=$(uncrustify --version | egrep -o '0.[0-9]+[.0-9]*')
-  if [[ "$VERSION" != $UNCRUSTIFY_VERSION ]]; then
-    do_install=true
-  fi
+
 fi
 
 # install uncrustify if it's missing

With this, everything builds except for ./tests/mpu_stack_growth which I saw is a problematic test, so I did not debug it.
The error itself is just an infinite recursion warning.

Error output

main.c: In function 'grow_stack':
main.c:26:13: error: infinite recursion detected [-Werror=infinite-recursion]
   26 | static void grow_stack(void) {
      |             ^~~~~~~~~~

Other notes

Why do none of the Nix user Tock maintainers post their nix configs? It took me hours to scour scant NixOS documentation to see I need to set this to fix udev issues.

# enable udev rules from packages
services.udev.packages = [
      pkgs.segger-jlink
];

Similarly for this libtock-c shell.nix, I had to further edit it to allow unfree and accept jlink EULA. Why can't these lines be included and commented out (like this but commented)?

Originally posted by @Samir-Rashid in #349 (comment)

@lschuermann
Copy link
Member Author

+      uncrustify

Orthogonal change, but looks good to me. You'll want to revert the uncommenting of the elf2tab and uncrustify update mechanisms. They don't work on NixOS but may work on other distributions. I have a snippet which prompts the user whether the Makefile should attempt to install elf2tab before doing so, which I can try to dig up from my pile of git branches.

I got this error on some examples when running examples/build_all.sh in a nix-shell.

can't link soft-float modules with double-float modules

tock/tock#1246 concerns ARM Cortex-M only, not RISC-V. The changes you're proposing only affect the custom-built RISC-V toolchain which shell.nix defines in this repo. I spent weeks coming up with those compiler flags, and apart from an issue with rv32i (no extensions) RISC-V targets, they seemed to work file for a long time. This led to a bunch of discussions with upstream Nixpkgs maintainers, both offline and here: NixOS/nixpkgs#178140. Truth be told, there was a lot of guesswork involved in coming up with the newlib configuration flags, so it is possible that enable-multilib is required. If things still compile, I'll happily accept those changes.

However, hopefully #346 will alleviate the need to compile a custom toolchain entirely. IIRC we just have to sort out some licensing & artifact distribution questions there.

Why do none of the Nix user Tock maintainers post their nix configs?

I cannot speak for others, but I've leaked secrets in my once-public config more often than I'd like to admit. I once had the goal of having a CI-checked NixOS VM with all toolchains pre-installed, but that's (a) work and (b) pretty exotic. I built a HashiCorp Packer VM for the last Tock tutorial, but I'm unsure how well this continues to work in the future. Building this was painful.

Similarly for this libtock-c shell.nix, I had to further edit it to allow unfree and accept jlink EULA. Why can't these lines be included and commented out (like this but commented)?

Reiterating my comment from tock/tock#3727: J-Link is only used by a subset of our boards, and generally also requires installation steps on other platforms. I'm unsure whether we should and can ship instructions for installing the (proprietary) toolchains for every board on every OS. What we most certainly don't want to do is vendor unfree packages / accept EULAs etc. for the user. That being said, adding comments or OS-specific install instructions somewhere can't hurt for sure!

@Samir-Rashid
Copy link
Contributor

This issue is stale. Please close.

@lschuermann
Copy link
Member Author

@Samir-Rashid Correct, thanks!

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

No branches or pull requests

2 participants