8000 fix: handle guest programs that depends on ring by leruaa · Pull Request #2185 · succinctlabs/sp1 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: handle guest programs that depends on ring #2185

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

Merged
merged 3 commits into from
Apr 8, 2025

Conversation

leruaa
Copy link
Contributor
@leruaa leruaa commented Mar 28, 2025

Motivation

Until now it wasn't possible to build programs that depends on ring. Linking is failing with:

[sp1]    cargo:warning=In file included from /home/aurel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include/ring-core/base.h:26,
[sp1]    cargo:warning=                 from /home/aurel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include/ring-core/mem.h:18,
[sp1]    cargo:warning=                 from /home/aurel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/curve25519/curve25519.c:22:
[sp1]    cargo:warning=/home/aurel/.sp1/riscv/riscv32im-linux-x86_64/lib/gcc/riscv32-unknown-elf/11.2.0/include/stdint.h:9:16: fatal error: stdint.h: No such file or directory
[sp1]    cargo:warning=    9 | # include_next <stdint.h>
[sp1]    cargo:warning=      |                ^~~~~~~~~~
[sp1]    cargo:warning=compilation terminated.

Solution

I've been able to successfully build a program by doing the following:

  • Updating the C++ toolchain to the latest 2024.01.05 version
  • Adding CFLAGS=-D__ILP32__ to cargo build to avoid this error

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@nhtyy
Copy link
Collaborator
nhtyy commented Mar 28, 2025

Can you fix the diff in sp1up pls

@leruaa
Copy link
Contributor Author
leruaa commented Mar 31, 2025

@nhtyy Done

@nhtyy nhtyy force-pushed the aurelien/fix-ring-linking branch from d8902b4 to 1126234 Compare April 2, 2025 20:53
Copy link
Contributor
@ratankaliani ratankaliani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some documentation for the purpose of the -D__ILP32___ flag for future dev?

Otherwise, LGTM.

@leruaa leruaa force-pushed the aurelien/fix-ring-linking branch from 1126234 to 88993f3 Compare April 7, 2025 20:14
@leruaa leruaa merged commit f88cdea into dev Apr 8, 2025
@leruaa leruaa deleted the aurelien/fix-ring-linking branch April 8, 2025 19:09
@liuchengxu
Copy link
Contributor

@leruaa When I update sp1 from 4.1.7 to 4.2.0, the ring dep fails to compile unfortunately. Removing CFLAGS works again. Any clue?

The error message from our CI (a private repo):

  [sp1]  warning: ring@0.17.14: In file included from /usr/include/features.h:526,
  [sp1]  warning: ring@0.17.14:                  from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33,
  [sp1]  warning: ring@0.17.14:                  from /usr/include/stdint.h:26,
  [sp1]  warning: ring@0.17.14:                  from /usr/lib/gcc/x86_64-linux-gnu/13/include/stdint.h:9,
  [sp1]  warning: ring@0.17.14:                  from /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include/ring-core/base.h:26,
  [sp1]  warning: ring@0.17.14:                  from /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include/ring-core/mem.h:18,
  [sp1]  warning: ring@0.17.14:                  from /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/curve25519/curve25519.c:22:
  [sp1]  warning: ring@0.17.14: /usr/include/x86_64-linux-gnu/gnu/stubs.h:13:11: fatal error: gnu/stubs-x32.h: No such file or directory
  [sp1]  warning: ring@0.17.14:    13 | # include <gnu/stubs-x32.h>
  [sp1]  warning: ring@0.17.14:       |           ^~~~~~~~~~~~~~~~~
  [sp1]  warning: ring@0.17.14: compilation terminated.
  [sp1]  error: failed to run custom build command for `ring v0.17.14`
  [sp1]  
  [sp1]  Caused by:
  [sp1]    process didn't exit successfully: `/home/runner/work/bitvm-bridge/bitvm-bridge/target/elf-compilation/release/build/ring-bfd9e851d07acdc8/build-script-build` (exit status: 1)
  [sp1]    --- stdout
  [sp1]    cargo:rerun-if-env-changed=CARGO_MANIFEST_DIR
  [sp1]    cargo:rerun-if-env-changed=CARGO_PKG_NAME
  [sp1]    cargo:rerun-if-env-changed=CARGO_PKG_VERSION_MAJOR
  [sp1]    cargo:rerun-if-env-changed=CARGO_PKG_VERSION_MINOR
  [sp1]    cargo:rerun-if-env-changed=CARGO_PKG_VERSION_PATCH
  [sp1]    cargo:rerun-if-env-changed=CARGO_PKG_VERSION_PRE
  [sp1]    cargo:rerun-if-env-changed=CARGO_MANIFEST_LINKS
  [sp1]    cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  [sp1]    cargo:rerun-if-env-changed=OUT_DIR
  [sp1]    cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH
  [sp1]    cargo:rerun-if-env-changed=CARGO_CFG_TARGET_OS
  [sp1]    cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ENV
  [sp1]    cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ENDIAN
  [sp1]    OPT_LEVEL = Some(0)
  [sp1]    OUT_DIR = Some(/home/runner/work/bitvm-bridge/bitvm-bridge/target/elf-compilation/release/build/ring-d84aca094461efb3/out)
  [sp1]    TARGET = Some(x86_64-unknown-linux-gnu)
  [sp1]    HOST = Some(x86_64-unknown-linux-gnu)
  [sp1]    cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  [sp1]    CC_x86_64-unknown-linux-gnu = None
  [sp1]    cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  [sp1]    CC_x86_64_unknown_linux_gnu = None
  [sp1]    cargo:rerun-if-env-changed=HOST_CC
  [sp1]    HOST_CC = None
  [sp1]    cargo:rerun-if-env-changed=CC
  [sp1]    CC = None
  [sp1]    cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  [sp1]    RUSTC_WRAPPER = None
  [sp1]    cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  [sp1]    CRATE_CC_NO_DEFAULTS = None
  [sp1]    DEBUG = Some(false)
  [sp1]    CARGO_CFG_TARGET_FEATURE = Some(fxsr,sse,sse2,x87)
  [sp1]    cargo:rerun-if-env-changed=CFLAGS
  [sp1]    CFLAGS = Some(-D__ILP32__)
  [sp1]    cargo:rerun-if-env-changed=CC_SHELL_ESCAPED_FLAGS
  [sp1]    CC_SHELL_ESCAPED_FLAGS = None
  [sp1]    cargo:rerun-if-env-changed=HOST_CFLAGS
  [sp1]    HOST_CFLAGS = None
  [sp1]    cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  [sp1]    CFLAGS_x86_64_unknown_linux_gnu = None
  [sp1]    cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  [sp1]    CFLAGS_x86_64-unknown-linux-gnu = None
  [sp1]    CARGO_ENCODED_RUSTFLAGS = Some()
  [sp1]    cargo:warning=In file included from /usr/include/features.h:526,
  [sp1]    cargo:warning=                 from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33,
  [sp1]    cargo:warning=                 from /usr/include/stdint.h:26,
  [sp1]    cargo:warning=                 from /usr/lib/gcc/x86_64-linux-gnu/13/include/stdint.h:9,
  [sp1]    cargo:warning=                 from /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include/ring-core/base.h:26,
  [sp1]    cargo:warning=                 from /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include/ring-core/mem.h:18,
  [sp1]    cargo:warning=                 from /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/curve25519/curve25519.c:22:
  [sp1]    cargo:warning=/usr/include/x86_64-linux-gnu/gnu/stubs.h:13:11: fatal error: gnu/stubs-x32.h: No such file or directory
  [sp1]    cargo:warning=   13 | # include <gnu/stubs-x32.h>
  [sp1]    cargo:warning=      |           ^~~~~~~~~~~~~~~~~
  [sp1]    cargo:warning=compilation terminated.
  [sp1]  
  [sp1]    --- stderr
  [sp1]  
  [sp1]  
  [sp1]    error occurred in cc-rs: command did not execute successfully (status code exit status: 1): LC_ALL="C" "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "/home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/include" "-I" "/home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/pregenerated" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-g3" "-DNDEBUG" "-D__ILP32__" "-o" "/home/runner/work/bitvm-bridge/bitvm-bridge/target/elf-compilation/release/build/ring-d84aca094461efb3/out/25ac62e5b3c53843-curve25519.o" "-c" "/home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ring-0.17.14/crypto/curve25519/curve25519.c"
  [sp1]  
  [sp1]  
  [sp1]  warning: build failed, waiting for other jobs to finish...

@leruaa
Copy link
Contributor Author
leruaa commented Apr 28, 2025

The error doesn't remind me of anything. What did you remove exaclty to make it work?

@liuchengxu
Copy link
Contributor

Removing the env CFLAGS works for me.

diff --git a/crates/build/src/command/local.rs b/crates/build/src/command/local.rs
index 62230fa7..7813d6eb 100644
--- a/crates/build/src/command/local.rs
+++ b/crates/build/src/command/local.rs
@@ -29,7 +29,7 @@ pub(crate) fn create_local_command(
 
     // the following flag is added to avoid build failure on ring:
     // https://github.com/briansmith/ring/blob/bcf68dd27a071ff1947b6327d4c6bde526e24b60/include/ring-core/target.h#L47
-    command.env("CFLAGS", "-D__ILP32__");
+    // command.env("CFLAGS", "-D__ILP32__");
 
     let parsed_version = {
         let output = Command::new("rustc")

@leruaa
Copy link
Contributor Author
leruaa commented Apr 28, 2025

On what machine run your CI?

@liuchengxu
Copy link
Contributor

You mean OS? It's ubuntu-24.04.

@liuchengxu
Copy link
Contributor

Hey @leruaa, any update here? Should I create a dedicated issue for this?

@leruaa
Copy link
Contributor Author
leruaa commented May 6, 2025

Yes please, it will be easier to track

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.

4 participants
0