Git Product home page Git Product logo

Comments (9)

Emilgardis avatar Emilgardis commented on May 22, 2024 1

@tniessen short answer is no, cross wouldnt help with a more elegant solution, the solution would be equally applicable with or without cross. I dont think your specific example here is related to what this issue is about, but feel free to open a new issue with more information and maybe we can work something out

from cross.

Emilgardis avatar Emilgardis commented on May 22, 2024

Can we solve this problem in our images?

Should we add -I/usr/include in all our BINDGEN_EXTRA_CLANG_ARGS_<target>s maybe? One risk I see with this is that we introduce contamination, where the header files could potentially be different for the host architecture and the target architecture. How does clang prioritize the include dirs, right to left?

from cross.

Emilgardis avatar Emilgardis commented on May 22, 2024

BINDGEN_EXTRA_CLANG_ARGS_<target>=--sysroot=$CROSS_SYSROOT -I/usr/include -v

gives

#include <...> search starts here:
 /usr/include
 /usr/include/clang/10.0.0/include
 $CROSS_SYSROOT/include

clang says

For C++ inputs, if there are multiple -I options, these directories are searched in the order they are given before the standard system directories are searched.

BINDGEN_EXTRA_CLANG_ARGS_<target>=--sysroot=$CROSS_SYSROOT -nostdinc -I$CROSS_SYSROOT/include -I/usr/include works, but disables the std, there's no way to reenable it... we need -ibuiltininc (available on clang-11 and up) I think but that also doesn't to enable the clang includes

#include <...> search starts here:
 $CROSS_SYSROOT/include
 /usr/include

**edit

-idirafter/usr/include is exactly what we want

aarch64-unknown-linux-gnu example

# Cross.toml
[target.aarch64-unknown-linux-gnu.env]
passthrough = ["""BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_gnu=--sysroot=/usr/aarch64-linux-gnu -idirafter/usr/include"""]

gives

#include <...> search starts here:
 /usr/lib/llvm-11/lib/clang/10.0.0/include
 /usr/aarch64-linux-gnu/include
 /usr/include

I've updated the first post from using -I/usr/include to be -idirafter/usr/include

from cross.

Emilgardis avatar Emilgardis commented on May 22, 2024

Should we add -I/usr/include in all our BINDGEN_EXTRA_CLANG_ARGS_<target>s maybe? One risk I see with this is that we introduce contamination, where the header files could potentially be different for the host architecture and the target architecture. How does clang prioritize the include dirs, right to left?

I think -idirafter/usr/include is the way to do this, I don't see much hindering us from adding this to our images

from cross.

Emilgardis avatar Emilgardis commented on May 22, 2024

Some more investigating, pkg-config strips -I/usr/include as it's a system include path, setting PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 resolves this, I've modified the code to reflect this. I think this is wanted behaviour for the pkg_config crate

root@8f4378f92f97:/# PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config libssl --cflags --libs
-I/usr/include -L/usr/lib/aarch64-linux-gnu -lssl
root@8f4378f92f97:/# pkg-config libssl --cflags --libs
-L/usr/lib/aarch64-linux-gnu -lssl

from cross.

Emilgardis avatar Emilgardis commented on May 22, 2024

Another issue, should we really use PKG_CONFIG_PATH? From what I can gather, the expected thing to do is to use aarch64-linux-gnu-pkg-config, which discovers the path automatically. It also curiously omits -I/usr/include, very interesting...

from cross.

ydirson avatar ydirson commented on May 22, 2024

Some (if not most?) *-dev packages on ubuntu dist only include headers in /usr/include, this means that the BINDGEN_EXTRA_CLANG_ARGS_<target>=--sysroot=$CROSS_SYSROOT

I'm not entirely sure of the problem this issue is about, since not all containers use the same approach. Since you mention using Ubuntu's -dev packages, I assume you're talking about containers for targets using dpkg's foreign-architecture support, but then it seems to be the sysroot is just / so there should be no problem to start with. So I'm basically confused :)

from cross.

Emilgardis avatar Emilgardis commented on May 22, 2024

Maybe I'm the one that is confused, we set the env var in #707

I was under the impression that it was needed, but maybe it wasn't needed for every target, and only needed for android

from cross.

tniessen avatar tniessen commented on May 22, 2024

bindgen can't properly find these headers if the *-sys-crate doesn't use pkg-config probing

@Emilgardis In my case, I'm using bindgen with some C header files that do not belong to any pre-installed library, so as far as I know, I cannot reasonably use pkg-config. However, with default configuration only, this results in errors such as fatal error: 'stddef.h' file not found. (The reason is that the Rust crate needs to be aware of the memory layout of some C data structures, but it does not actually link against any C library.)

This works just fine with the default toolchain/target, but cross-compiling without cross requires manual modifications of the include path. Is there a more elegant solution now that I'm trying to use cross?

from cross.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.