Hi,

a short status update:

On 2023-05-05 06:01, Tim Orling wrote:


On Thu, May 4, 2023 at 5:00 AM Peter Bergin <[email protected]> wrote:


    On 2023-05-04 11:00, Alexander Kanavin wrote:
    > On Thu, 4 May 2023 at 10:41, Peter Bergin
    <[email protected]> wrote:
    >
    >> At
    >>
    
https://github.com/pyca/cryptography/blob/f816b457494e010b655cd7fdcd30e3446f86a703/src/rust/build.rs#L46
    >> the path to python includes is defined by calling 'python3 -c
    "import
    >> sysconfig; print(sysconfig.get_path('include'))"' (but from inside
    >> rust). With print-debugging this seems to return the bad string
    >> '/usr/include/python3.11' which is then passed to cc::Build
    >>
    >> I executed this in recipe context:
    >>
    >> do_compile:prepend() {
    >>       which python3
    >>       python3 -c "import sysconfig;
    print(sysconfig.get_path('include'))"
    >> }
    >>
    >> and then I got the correct return value:
    >>
    >> |
    >>
    
/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/recipe-sysroot-native/usr/bin/python3-native/python3
    >> |
    >>
    
/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/recipe-sysroot-native/usr/include/python3.11
    > This is pointing to the native sysroot in a target build, so it is
    > most likely not actually correct. I believe 'inherit
    > python3targetconfig' may help, as it substitutes most places where
    > native python gets queried by components with target-specific
    values.
    >
    > Alex
    >
    The bad thing is that the build.rs <http://build.rs> script is
    running python script to
    figure out the path to the headers. I'm not sure we can use target
    python exe in the build steps without running qemu instance or
    something
    which seems overkill in this case. We have the information about
    python
    include path for the target in the variable PYTHON_INCLUDE_DIR.

    With this patch the compilation will find Python.h:

    $ git diff src/rust/build.rs <http://build.rs>
    diff --git a/src/rust/build.rs <http://build.rs>
    b/src/rust/build.rs <http://build.rs>
    index 01177ac..7dc13fe 100644
    --- a/src/rust/build.rs <http://build.rs>
    +++ b/src/rust/build.rs <http://build.rs>
    @@ -43,11 +43,8 @@ fn main() {
          )
          .unwrap();
    println!("cargo:rustc-cfg=python_implementation=\"{}\"", python_impl);
    -    let python_include = run_python_script(
    -        &python,
    -        "import sysconfig; print(sysconfig.get_path('include'),
    end='')",
    -    )
    -    .unwrap();
    +    let python_include = env::var("PYTHON_INCLUDE_DIR").unwrap();
    +
          let openssl_include =
    std::env::var_os("DEP_OPENSSL_INCLUDE").expect("unable to find
    openssl include path");
          let openssl_c = Path::new(&out_dir).join("_openssl.c");


This patch at least got `python3-cryptography-native` to build to completion.

And I was also able to build python3-cryptography for 'qemuarm64'. Opened an issue at https://github.com/pyca/cryptography/issues/8867 to see if it is something to be fixed upstream.


    But it fails later in the linking step.

    
.....linux/python3-cryptography/40.0.2-r0/recipe-sysroot/usr/lib/rustlib/x86_64-poky-linux-gnu/lib"

    "-L"
    
"/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/python3-cryptography-40.0.2/target/x86_64-poky-linux-gnu/release/build/cryptography-rust-aa00e39a952c07ee/out"

    "-L"
    
"/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/recipe-sysroot/usr/lib"

    "-L"
    
"/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/recipe-sysroot-native/usr/lib/rustlib/x86_64-poky-linux-gnu/lib"

    "-Wl,-Bstatic" "-l_openssl.a"
    
"/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/recipe-sysroot/usr/lib/rustlib/x86_64-poky-linux-gnu/lib/libcompiler_builtins-45df5d471f0d20d0.rlib"

    "-Wl,-Bdynamic" "-lssl" "-lcrypto" "-lgcc_s" "-lutil" "-lrt"
    "-lpthread"
    "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L"
    
"/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/recipe-sysroot-native/usr/lib/rustlib/x86_64-poky-linux-gnu/lib"

    "-o"
    
"/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/python3-cryptography-40.0.2/target/x86_64-poky-linux-gnu/release/deps/libcryptography_rust.so"

    "-Wl,--gc-sections" "-shared" "-Wl,-O1" "-nodefaultlibs"
       = note:
    
/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/recipe-sysroot-native/usr/bin/x86_64-poky-linux/../../libexec/x86_64-poky-linux/gcc/x86_64-poky-linux/12.2.0/ld:

    
/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/python3-cryptography-40.0.2/target/x86_64-poky-linux-gnu/release/build/cryptography-rust-aa00e39a952c07ee/out/lib_openssl.a.a(9bdf47a443b7a07f-_openssl.o):

    warning: relocation against `_Py_NoneStruct' in read-only section
    `.text'
    
/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/recipe-sysroot-native/usr/bin/x86_64-poky-linux/../../libexec/x86_64-poky-linux/gcc/x86_64-poky-linux/12.2.0/ld:

    
/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/python3-cryptography-40.0.2/target/x86_64-poky-linux-gnu/release/build/cryptography-rust-aa00e39a952c07ee/out/lib_openssl.a.a(9bdf47a443b7a07f-_openssl.o):

    relocation R_X86_64_PC32 against undefined symbol `_Py_NoneStruct'
    can
    not be used when making a shared object; recompile with -fPIC
    
/work/yocto/poky/build/tmp/work/core2-64-poky-linux/python3-cryptography/40.0.2-r0/recipe-sysroot-native/usr/bin/x86_64-poky-linux/../../libexec/x86_64-poky-linux/gcc/x86_64-poky-linux/12.2.0/ld:

    final link failed: bad value
               collect2: error: ld returned 1 exit status


As I was able to complete a build for 'qemuarm64' but it fails on 'qemux86_64' I am now trying to find differences....  Help appreciated! I have compared on the level of rust and how cargo is called and I can not find any difference apart from '-target [x86|aarch]64-poky-linux-gnu'.

My thoughts is that it can have to do with the binding to openssl and how it is built. Found an old issue (https://www.openembedded.org/pipermail/openembedded-core/2016-December/130334.html) with similar error message. But I'm not sure how it is related and neither how openssl integrates in to the build, I guess it is through openssl-sys. Any ideas around this are welcome. Is there a difference in '-fPIC' between x86_64 and arm64?

/Peter

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#180973): 
https://lists.openembedded.org/g/openembedded-core/message/180973
Mute This Topic: https://lists.openembedded.org/mt/98667212/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to