Skip to content

Conversation

kacper-the-programmer
Copy link

No description provided.

@T-Dynamos
Copy link
Contributor

T-Dynamos commented Jan 24, 2024

@Kacper-OS
This won't work, you need to setup rust on host system and then set CARGO_BUILD_TARGET=<arch code>-linux-androideabi as environment variable first
Where arch codes are as follows:

armv7 = armeabi-v7a
aarch64 = arm64-v8a

Setps to setup rust:

curl https://sh.rustup.rs -sSf > rustup.sh
sh rustup.sh -y --default-toolchain "<rust version here>"
export PATH="~/.cargo/bin:${PATH}"
rustup target add "<arch code>-linux-androideabi"

@kacper-the-programmer
Copy link
Author

OK, thanks I will fix this issue

@kacper-the-programmer
Copy link
Author

OK, now what I have to do ?

@T-Dynamos
Copy link
Contributor

T-Dynamos commented Jan 24, 2024

image

from shutil import which
import sh
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
from pythonforandroid.logger import error, shprint
from pythonforandroid.util import current_directory

class PydanticcoreRecipe(CompiledComponentsPythonRecipe):
    version = "2.16.1"
    url = (
        "https://github.com/pydantic/pydantic-core/archive/refs/tags/v{version}.tar.gz"
    )
    depends = ["typing-extensions"]

    def get_recipe_env(self, arch):
        env = super().get_recipe_env(arch)
        env["CARGO_BUILD_TARGET"] = "{}-linux-androideabi".format(
            {
                "arm64-v8a": "aarch64",
                "armeabi-v7a": "armv7",
                "x86_64": "x86_64",
                "x86": "i686",
            }[str(arch)]
        )
        env['PATH'] = (
            '{hostpython_dir}:{old_path}').format(
                hostpython_dir=self.get_recipe(
                    'hostpython3' , self.ctx).get_path_to_python(),
                old_path=env['PATH'])
        return env

    def build_arch(self, arch):
        with current_directory(self.get_build_dir(arch.arch)):
            shprint(
                sh.maturin,
                "build",
                "-i",
                "python3.11",
                _env=self.get_recipe_env(arch)
            )


recipe = PydanticcoreRecipe()

You need to add things in there, I have made basic script.
also don't forgot to add detection if toolchain is installed.

rustup target add armv7-linux-androideabi

Like this...

@T-Dynamos
Copy link
Contributor

T-Dynamos commented Jan 24, 2024

However build still fails:

  --- stderr
  Traceback (most recent call last):
    File "/home/tdynamos/PyJniusTester/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/pydantic-core/armeabi-v7a__ndk_target_21/pydantic-core/generate_self_schema.py", line 17, in <module>
      from typing_extensions import TypedDict, get_args, get_origin, is_typeddict
  ModuleNotFoundError: No module named 'typing_extensions'
  thread 'main' panicked at build.rs:29:9:
  generate_self_schema.py failed with exit status: 1
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
💥 maturin failed===================>   ] 96/105: regex-automata              
  Caused by: Failed to build a native library through cargo
  Caused by: Cargo build finished with "exit status: 101": `env -u CARGO PYO3_CONFIG_FILE="/home/tdynamos/PyJniusTester/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/pydantic-core/armeabi-v7a__ndk_target_21/pydantic-core/target/maturin/pyo3-config-armv7-linux-androideabi-3.11.txt" "cargo" "rustc" "--features" "pyo3/extension-module" "--target" "armv7-linux-androideabi" "--message-format" "json-render-diagnostics" "--manifest-path" "/home/tdynamos/PyJniusTester/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/pydantic-core/armeabi-v7a__ndk_target_21/pydantic-core/Cargo.toml" "--lib" "--crate-type" "cdylib"`


  STDERR:

This is because of typing_extensions is not installed in hostpython. You can easily fix that by minimal patching, add typing_extensions.py from offcial source to build dir.

Edit:
After fixing that there is one more error which also can be fixed easily.

= note: ld: error: unable to find library -llog

Doing something like:

self.install_libs(arch, join(
            arch.ndk_lib_dir,
            'lib{name}.so'.format(name="log"),
        ) )

Before build.

@kacper-the-programmer
Copy link
Author

ok thanks again

@T-Dynamos
Copy link
Contributor

Can be closed as surpassed by #2962

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.

2 participants