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

Building crates needing C++ fails #27

Open
rjkroege opened this issue Aug 24, 2023 · 4 comments
Open

Building crates needing C++ fails #27

rjkroege opened this issue Aug 24, 2023 · 4 comments
Labels
bug Something isn't working darwin help wanted Extra attention is needed linux musl

Comments

@rjkroege
Copy link
Contributor

When I use the builder, crates that contain Rust-compiled C++ code fail to link. Example:

...much spew...
  = note: ld: archive has no table of contents file '/root/src/difft/target/aarch64-apple-darwin/release/build/difftastic-abae5b1432a24d5f/out/libtree-sitter-ada.a' for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
...much spew...

AFAIK: lib tree-sitter-ada.a is built from C++ code by the difftastic crate.

This is working as intended? Or am I being an idiot?

@joseluisq
Copy link
Owner

Can you share how are you compiling difftastic actually?

@rjkroege
Copy link
Contributor Author

Using environment from the Dockerfile. I will note in passing that it failed for all of aarch64-apple-darwin, x86_64-apple-darwin, armv7-unknown-linux-musleabihf, x86_64-unknown-linux-musl. My exact build commands differed in each case. I'll use aarch64-apple-darwin as an example:

CC=aarch64-apple-darwin22.2-clang \
CXX=aarch64-apple-darwin22.2-clang++ \
cargo build \
	--release \
	--target aarch64-apple-darwin

I see from the spew that the C++ compiler has executed because it generated many compilation warnings.

The behaviour for x86_64-unknown-linux-musl differs (still doesn't work but different errors.) FWIW: I built like so:

CC=musl-gcc \
CXX=musl-g++ \
cargo build \
	--release \
	--target x86_64-unknown-linux-musl

It also failed in the link phase in a way that suggests a mismatch between libstdc++ (conceivably compiled against Gnu) and must. At least, thatI's what I think is happening. But see the "am I being an idiot?" in the original issue. 🙂

Here's the error:

  = note: /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/12/libstdc++.a(stdexcept.o): in function `std::logic_error::~logic_error()':
          (.text._ZNSt11logic_errorD2Ev+0x43): undefined reference to `__libc_single_threaded'
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

Maybe I need to add a full musl cross gcc to the Docker (something like richfelker/musl-cross-make: Simple makefile-based build for musl cross compiler) to build difftastic on Linux?

@joseluisq joseluisq added bug Something isn't working musl darwin linux labels Aug 27, 2023
@joseluisq
Copy link
Owner

About musl, we probably have to do some clever stuff such as sysroot musl and add the necessary symlinks similar to cross.
But definitely, this will need some work to be able to statically link libstdc++ when targeting musl.

And regarding Darwin, for me looks like a mismatch issue but I have no clue about it at the moment, so I will try to figure it out.

But in general, there are interesting ideas in the cross project (which BTW difftastic is using for the musl target).
So feel free to help.

@joseluisq joseluisq added the help wanted Extra attention is needed label Aug 27, 2023
@rjkroege
Copy link
Contributor Author

Since I want this to work... I'll see if I can make this work better over the next few weeks and update the bug with anything that I figure out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working darwin help wanted Extra attention is needed linux musl
Projects
None yet
Development

No branches or pull requests

2 participants