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

python-for-android: ImportError: Cannot locate symbol #129

Open
tmarplatt opened this issue Dec 12, 2019 · 6 comments
Open

python-for-android: ImportError: Cannot locate symbol #129

tmarplatt opened this issue Dec 12, 2019 · 6 comments

Comments

@tmarplatt
Copy link

I have cross-compiled, linked and installed a pyd module (which consists of only one exported class) under python-for-android. The goal is to run a kivy GUI frontend to the app's D language backend on Android platforms. (Since ldc now supports ARM targets.)

So I wrote a simple hello world main.py:

import kivy

from kivy.app import App
from kivy.uix.label import Label
# Just import our pyd class
from worldwrapper import WorldWrapper

# Show a "42" centered on screen
class MyApp(App):
    def build(self):
        b = 42
        return Label(text=str(b))

if __name__ == '__main__':
    MyApp().run()

Here's worldwrapper.d:

module worldwrapper;

import pyd.pyd;
import pyd.embedded;

class WorldWrapper
{
	int a = 0;
	int geta()
	{
		return this.a;
	}
}

extern (C) void PydMain()
{
	module_init();

	wrap_class!(WorldWrapper, Property!(WorldWrapper.geta))();
}

Here's the ordinary setup.py (building deimos):

from pyd.support import setup, Extension

projectName = 'worldwrapper'

setup(
    name=projectName,
    version='0.0.1',
    ext_modules=[
        Extension(projectName,
            ['worldwrapper.d'],
            build_deimos = True,
            d_lump = True,
        )
    ],
)

Long story short: I got python-for-android to patch pyd so it passes ldc2 the target parameter -mtriple=armv7a--linux-androideabi. Then it runs python3 setup.py install which cross-compiles and installs the shared library under python-for-android's site-packages.

Here's python-for-android running our patched distutils:

[DEBUG]:   -> running python3 setup.py install -O2 -v --force --root=/home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/tmarpp --install-lib=.
[DEBUG]:   	running install
[DEBUG]:   	running build
[DEBUG]:   	running build_ext
[DEBUG]:   	['-lpthread', '-ldl', '-lutil']
[DEBUG]:   	['-lpthread', '-ldl', '-lutil']
[DEBUG]:   	building 'worldwrapper' extension
[DEBUG]:   	travis_fold:start:pyd_compile-503c14f4-1d25-11ea-a183-080027af58ec
[DEBUG]:   	ldmd2 -relocation-model=pic -c -mtriple=armv7a--linux-androideabi -singleobj -d-version=PydPythonExtension -d-version=Python_2_4_Or_Later -d-version=Python_2_5_Or_Later -d-version=Python_2_6_Or_Later -d-version=Python_2_7_Or_Later -d-version=Python_3_0_Or_Later -d-version=Python_3_1_Or_Later -d-version=Python_3_2_Or_Later -d-version=Python_3_3_Or_Later -d-version=Python_3_4_Or_Later -d-version=Python_3_5_Or_Later -d-version=Python_3_6_Or_Later -d-version=Python_3_7_Or_Later -d-version=Python_Unicode_UCS4 -d-debug -I /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure -of build/temp.linux-x86_64-3.7/infra/temp.o worldwrapper.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/class_wrap.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/ctor_wrap.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/def.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/embedded.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/exception.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/extra.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/func_wrap.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/make_object.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/make_wrapper.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/op_wrap.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/pyd.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/pydobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/references.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/struct_wrap.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/pyd/thread.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/util/conv.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/util/typeinfo.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/util/typelist.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/util/multi_index.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/util/replace.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/abstract_.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/ast.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/boolobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/bufferobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/bytearrayobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/bytesobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/cellobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/ceval.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/classobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/cobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/codecs.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/code.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/compile.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/complexobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/cStringIO.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/datetime.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/descrobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/dictobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/enumobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/errcode.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/eval.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/fileobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/floatobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/frameobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/funcobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/genobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/grammar.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/import_.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/intobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/intrcheck.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/iterobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/listobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/longintrepr.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/longobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/marshal.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/memoryobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/methodobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/modsupport.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/moduleobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/node.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/object.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/objimpl.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/parsetok.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pgenheaders.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pyarena.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pyatomic.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pycapsule.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pydebug.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pyerrors.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pymem.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pyport.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pystate.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pystrcmp.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pystrtod.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/Python.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pythonrun.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/pythread.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/rangeobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/setobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/sliceobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/stringobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/structmember.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/structseq.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/symtable.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/sysmodule.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/timefuncs.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/traceback.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/tupleobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/unicodeobject.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/deimos/python/weakrefobject.d build/temp.linux-x86_64-3.7/infra/pydmain.d /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/pyd/infrastructure/d/python_so_linux_boilerplate.d
[DEBUG]:   	travis_fold:end:pyd_compile-503c14f4-1d25-11ea-a183-080027af58ec
[DEBUG]:   	library_dirs: []
[DEBUG]:   	runtime_library_dirs: []
[DEBUG]:   	libraries: []
[DEBUG]:   	travis_fold:start:pyd_link-5262e2d0-1d25-11ea-a183-080027af58ec
[DEBUG]:   	ldc2 -v -mtriple=armv7a--linux-androideabi -shared -d-debug -of build/lib.linux-x86_64-3.7/worldwrapper.cpython-37m.so build/temp.linux-x86_64-3.7/infra/temp.o
[DEBUG]:   	binary    /home/tmarplatt/pyd/testapp/recipes/pyd-module/ldc/ldc-1.18.0/bin/ldc2
[DEBUG]:   	version   1.18.0 (DMD v2.088.1, LLVM 9.0.0)
[DEBUG]:   	config    /home/tmarplatt/pyd/testapp/recipes/pyd-module/ldc/ldc-1.18.0/etc/ldc2.conf (armv7a-unknown-linux-android)
[DEBUG]:   	predefs   LDC all D_Version2 assert D_ModuleInfo D_Exceptions D_TypeInfo ARM ARM_SoftFP D_HardFloat LittleEndian D_PIC linux Posix Android CRuntime_Bionic LDC_LLVM_900
[DEBUG]:   	GC stats  0M used, 1M free, 1M total
[DEBUG]:   	/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang build/temp.linux-x86_64-3.7/infra/temp.o -shared -o build/lib.linux-x86_64-3.7/worldwrapper.cpython-37m.so -fuse-ld=bfd -Wl,--export-dynamic -v --target=armv7a-unknown-linux-android21 -L/home/tmarplatt/pyd/testapp/recipes/pyd-module/ldc/ldc-1.18.0/bin/../lib-armv7a-32 -lphobos2-ldc -ldruntime-ldc -Wl,--gc-sections -ldl -lm
[DEBUG]:   	Android (5058415 based on r339409) clang version 8.0.2 (https://android.googlesource.com/toolchain/clang 40173bab62ec746213857d083c0e8b0abb568790) (https://android.googlesource.com/toolchain/llvm 7a6618d69e7e8111e1d49dc9e7813767c5ca756a) (based on LLVM 8.0.2svn)
[DEBUG]:   	Target: armv7a-unknown-linux-android21
[DEBUG]:   	Thread model: posix
[DEBUG]:   	InstalledDir: /home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin
[DEBUG]:   	Found candidate GCC installation: /home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x
[DEBUG]:   	Selected GCC installation: /home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x
[DEBUG]:   	Candidate multilib: thumb;@mthumb
[DEBUG]:   	Candidate multilib: armv7-a;@march=armv7-a
[DEBUG]:   	Candidate multilib: armv7-a/thumb;@march=armv7-a@mthumb
[DEBUG]:   	Candidate multilib: .;
[DEBUG]:   	Selected multilib: armv7-a;@march=armv7-a
[DEBUG]:   	 "/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld.bfd" -X --enable-new-dtags --eh-frame-hdr -m armelf_linux_eabi -shared -o build/lib.linux-x86_64-3.7/worldwrapper.cpython-37m.so /home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi/21/crtbegin_so.o -L/home/tmarplatt/pyd/testapp/recipes/pyd-module/ldc/ldc-1.18.0/bin/../lib-armv7a-32 -L/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.2/lib/linux/arm -L/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/armv7-a -L/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/../lib/armv7-a -L/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi/21 -L/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi -L/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/../lib -L/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi/../../lib -L/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/armv7-a -L/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib build/temp.linux-x86_64-3.7/infra/temp.o --export-dynamic -lphobos2-ldc -ldruntime-ldc --gc-sections -ldl -lm -lgcc -ldl -lc -lgcc -ldl /home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi/21/crtend_so.o
[DEBUG]:   	travis_fold:end:pyd_link-5262e2d0-1d25-11ea-a183-080027af58ec
[DEBUG]:   	running install_lib
[DEBUG]:   	copying build/lib.linux-x86_64-3.7/worldwrapper.cpython-37m.so -> /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/tmarpp/.
[DEBUG]:   	running install_egg_info
[DEBUG]:   	Writing /home/tmarplatt/pyd/testapp/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/tmarpp/./worldwrapper-0.0.1-py3.7.egg-info

This is all brilliantly accomplished by extending etc/ldc2.conf with this target configuration:

"armv7a-.*-linux-android":
{
    switches = [
        "-L-Wl,--export-dynamic",
        "-defaultlib=phobos2-ldc,druntime-ldc",
        "-link-defaultlib-shared=false",
        "-linker=bfd",
        "-mcpu=cortex-a8",
        "-gcc=/home/tmarplatt/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang",
        "-Xcc=-v",
        "-Xcc=--target=armv7a-unknown-linux-android21",
    ];
    lib-dirs = [
        "%%ldcbinarypath%%/../lib-armv7a-32",
    ];
};

Notice it's using ldc's prebuilt arm eabi runtime libraries (installed under /lib-armv7a-32) which allow running D code on Android.

The result is a cross-compiled worldwrapper.so:

tmarplatt@tmarplatt:~/pyd/testapp/bin$ file worldwrapper.so 
worldwrapper.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, with debug_info, not stripped
tmarplatt@tmarplatt:~/pyd/testapp/bin$ nm -g worldwrapper.so | grep PydMain
002240e4 T PydMain
tmarplatt@tmarplatt:~/pyd/testapp/bin$ readelf -a worldwrapper.so | grep PyExc
00461bb4  00065415 R_ARM_GLOB_DAT    00000000   PyExc_ValueError
00461f40  000de815 R_ARM_GLOB_DAT    00000000   PyExc_TypeError
00462444  00178a15 R_ARM_GLOB_DAT    00000000   PyExc_SyntaxError
00462934  00213215 R_ARM_GLOB_DAT    00000000   PyExc_RuntimeError
readelf: Warning: local symbol 3 found at index >= .dynsym's sh_info value of 3
readelf: Warning: local symbol 4 found at index >= .dynsym's sh_info value of 3
readelf: Warning: local symbol 5 found at index >= .dynsym's sh_info value of 3
  1620: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND PyExc_ValueError
  3560: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND PyExc_TypeError
  6026: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND PyExc_SyntaxError
  8498: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND PyExc_RuntimeError
 34850: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND PyExc_ValueError
 36790: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND PyExc_TypeError
 39256: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND PyExc_SyntaxError
 41728: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND PyExc_RuntimeError

But I believe I'm running into linking issues, because python crashes with the following error on line 6 in main.py (extract from the Android phone's logcat):
ImportError: dlopen failed: cannot locate symbol "PyExc_ValueError" referenced by "/data/data/org.tmarplatt.testapp.tmarpp/files/app/_python_bundle/site-packages/worldwrapper.so"

What could be going on? Since it's suggested in #43 to use -rdynamic for linking, I added the --export-dynamic flag into ldc's configuration, but it hasn't solved the problem.

If I can work this out I'll be able to contribute with a python-for-android recipe for building pyd-enabled modules. "Recipes" are wrapper scripts for patching, compiling and installing python modules with ARM architecture-specific requirements, which are included in the Android app package.

@ariovistus
Copy link
Owner

your output doesn't look too different from mine (a x86_64 build). I guess since you're referencing it, is Py_ENABLE_SHARED false?

import distutils
x = distutils.sysconfig_get_config_vars()
print (x['Py_ENABLE_SHARED'])
# wow i remembered how to check this

assuming it is true, next thing to naively wonder is what is the output of ldd
eg for me it shows something like

	linux-vdso.so.1 (0x00007fffd21b7000)
	libpython3.7m.so.1.0 => /lib64/libpython3.7m.so.1.0 (0x00007f744ee98000)
	libphobos2.so.0.88 => /lib64/libphobos2.so.0.88 (0x00007f744e66d000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f744e64c000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f744e506000)
	librt.so.1 => /lib64/librt.so.1 (0x00007f744e4fc000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f744e4f6000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f744e4da000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f744e314000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f744f2f2000)
	libutil.so.1 => /lib64/libutil.so.1 (0x00007f744e30f000)

emphasis on the presence of libpython

if it's there, you'll have reached the limits of my expertise on the subject.

@tmarplatt
Copy link
Author

tmarplatt commented Dec 13, 2019

For future reference, the python code that worked for me is

from distutils import sysconfig
x = sysconfig.get_config_vars()
print(x['Py_ENABLE_SHARED'])

Which, yes, returns true (1). And ld is not linking against libpython, so maybe I should add a new linker flag to take care of that.

@tmarplatt
Copy link
Author

After linking against libpython, the error has changed to:
ImportError: dlopen failed: cannot locate symbol "_tlsstart" referenced by "/data/data/org.tmarplatt.testapp.tmarpp/files/app/_python_bundle/site-packages/worldwrapper.so"...

Which is the kind of issue you'd run into when cross-compiling with earlier versions of ldc. In recent versions of ldc, it all just works. You can cross-compile a D program and run it from the Android adb terminal.

So I believe this is related to ldc2 not passing the right target to clang unless specified, which is happening in my build environment (python-for-android / distutils). This line in ldc2.conf should not be necessary to begin with:

"-Xcc=--target=armv7a-unknown-linux-android21"

@ariovistus do you know if distutils might be setting some environment compiler/linker flags on its own? Something that explains ldc misbehaving, or that overrides llvm/clang configuration?

@ariovistus
Copy link
Owner

if memory serves, everything distutils gives a compiler is either an argument to DCompiler.compile or DCompiler.link, or something passed along by DCompiler. shouldn't be too difficult to slip a verbose flag in there if you want to see what ldc is actually passing to the linker

@tmarplatt
Copy link
Author

tmarplatt commented Dec 16, 2019

I've solved the clang issue, and ldc now builds and links without problems.

But it turns out that the tls issue is due to unfulfilled requirements specific to Android binaries: https://wiki.dlang.org/Build_D_for_Android#Changes_for_Android

1. You must use the ld.bfd linker- see the use of -fuse-ld=bfd above- ld.gold won't do. (Done.)
2. You must have a D main function, even for a shared library.
3. The ELF object with the D main function must be passed to the linker first.

About 2), I think I'm going to have to patch pyd to comment out the _Dmain definition under Pydmain.d, and instead declare my own empty main(). And possibly compile it to a separate object file, in order to ensure linking order (item 3 above).

What are your thoughts @ariovistus ? Also from the wiki:

If building a shared library and not a D command-line executable, you must also initialize and exit the D runtime by calling rt_init() and rt_term() before and after all D code is run, (...). Running multiple D shared libraries is currently unsupported on Android, only a single D shared library that statically links against the D runtime will work.

How does this fall in place with Python importing and running pyd objects? Is this what python_so_linux_boilerplate.d already enforces?

@ariovistus
Copy link
Owner

been a while since I've messed with d disassembly, but isn't _Dmain the D main function they're referencing? well, maybe not, maybe the compiler injects some extra smarts in when it sees "void main()" or its ilk. it looks like if d_lump=False you will need to ensure the linking order is satisfied in dcompiler.py, otherwise there's only one object file.

python_so_linux_boilerplate.d does deal with calling rt_init and rt_term. looks like when gcc is available it uses some gcc attributes in so_ctor.c, when LDC is available it uses some LDC specific pragmas. don't think you need to do anything here.

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

No branches or pull requests

2 participants