renpy / renpy-build

Build system for the Ren'Py visual novel engine. (The engine itself, not games.)
76 stars 51 forks source link

Fix search path for pkgconf and cmake in cross build #83

Closed brainos233 closed 1 year ago

brainos233 commented 1 year ago

For pkgconf/pkg-config:

https://gitlab.freedesktop.org/pkg-config/pkg-config/-/issues/6 says

Details

> PKG_CONFIG_PATH > > A colon-separated (on Windows, semicolon-separated) list of directories to be searched for .pc files ***before the default locations***. > > PKG_CONFIG_LIBDIR > > A colon-separated (on Windows, semicolon-separated) list of directories to ***replace the default pkg-config search path***, usually defined at build time.

So PKG_CONFIG_PATH should be defined when kind="host", PKG_CONFIG_LIBDIR should be defined when cross building.

But when debootstrap is used to create sysroot for linux, *.pc files in sysroot will use /usr as prefix, so even PKG_CONFIG_LIBDIR is set, compiler still uses libraries and headers provided by build system, not sysroot. One possible solution is set PKG_CONFIG_SYSROOT_DIR, but it will prepend prefix to libraries outside of SYSROOT, see https://github.com/pkgconf/pkgconf/issues/213 and https://github.com/pkgconf/pkgconf/pull/280.

My solution is replacing the original prefix /usr to {{sysroot}}/usr manually, so PKG_CONFIG can correct cflags and don't broke any path given by {{install}}/lib/pkgconfig/*.pc.

For cmake:

By passing variables CMAKE_FIND_ROOT_PATH and CMAKE_SYSROOT to set the paths used by find_package(), find_library().

Ndk uses its own method provided by CMAKE_TOOLCHAIN_FILE={{cross}}/{{ndk_version}}/build/cmake/android.toolchain.cmake, so it only needs CMAKE_FIND_ROOT_PATH, but must define ANDROID_ABI and ANDROID_PLATFORM manually. Here, I try to use the ndk_version defined in #82 to consistently define the version that uses the Ndk throughout the build system.

brainos233 commented 1 year ago

Already successfully tested building for platforms linux, windows, mac, web in python 3.

renpytom commented 1 year ago

Something about this broke libaom.

brainos233 commented 1 year ago

Something about this broke libaom.

What is it and in what platform and arch? I try to re-build the whole project in a new Ubuntu 22.04 VM, there is a problem when building sdl, fixed by #87, I tried to build for linux_x86 windows_x86 and android_arm64 and didn't find any issues about libaom.

brainos233 commented 1 year ago

Something about this broke libaom.

I think I found it

CMake Error at /usr/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/usr/bin/ccache"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/brainos/renpy-build-test/tmp/build/aom.linux-armv7l/CMakeFiles/CMakeTmp

    Run Build Command(s):/home/brainos/renpy-build-test/tmp/sysroot.linux-armv7l/usr/bin/gmake -f Makefile cmTC_0385c/fast && arm-binfmt-P: Could not open '/lib/ld-linux-armhf.so.3': No such file or directory

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:28 (project)

I think it is because CMAKE_FIND_ROOT_PATH_MODE_PROGRAM should be set to NEVER, I will do more test.