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

[APR] Support for cross-building using cache file #17609

Closed
wants to merge 6 commits into from

Conversation

swebb2066
Copy link
Contributor

@swebb2066 swebb2066 commented May 18, 2023

The APR configure.in script makes extensive (30 instances) use of AC_TRY_RUN (to determine system capabilities) and checks for /dev/zero. These runtime checks only work when run on the host so the configure script will fail when cross compiling unless the relevant configuration variables are provided in a cache file or on the command line or in an environment variable.

The configuration variable values are most easily determined by running the configure script on a host system using:
./configure --cache-file={gnu_host_triplet}.cache
and then removing the 'precious' autoconf variables:
ac_cv_env_*

The generated cache file can be repeatedly used to cross-compile to the targeted host system by including it with the recipe data.
The default targeted host system name can be overriden in the profile using (for example).

[conf]
tools.gnu:host_triplet=arm-linux-gnueabihf

This PR assumes the generated cache file is stored in the 'cross_build' directory.

Using the command:
conan create . apr/1.7.4@ -pr:h arm-linux-gnueabihf -pr:b default
on the master branch conanfile.py with the validate() removed results in:

Exporting package recipe
apr/1.7.4 exports: File 'conandata.yml' found. Exporting it...
apr/1.7.4 exports: Copied 1 '.yml' file: conandata.yml
apr/1.7.4: Calling export_sources()
apr/1.7.4: A new conanfile.py version was exported
apr/1.7.4: Folder: /home/stephen/.conan/data/apr/1.7.4/_/_/export
apr/1.7.4: Source folder is corrupted, forcing removal
apr/1.7.4: Exported revision: 8068d417833d1980a50813734ce2fac8
Configuration (profile_host):
[settings]
arch=armv7
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=8
os=Linux
os_build=Linux
[options]
boost:bzip2=False
boost:shared=False
boost:zlib=False
log4cxx:shared=True
yaml-cpp:shared=False
[build_requires]
[env]
AR=arm-linux-gnueabihf-ar
AS=arm-linux-gnueabihf-as
CC=arm-linux-gnueabihf-gcc
CFLAGS=-I/opt/xtools/arm-linux-gnueabihf/usr/include
CONAN_CFLAGS=-I/opt/xtools/arm-linux-gnueabihf/usr/include -DLINUX -D_GNU_SOURCE
CONAN_CMAKE_TOOLCHAIN_FILE=/opt/xtools/cmake/Toolchain-arm-linux-gnueabihf.cmake
CXX=arm-linux-gnueabihf-g++
CXXCC=arm-linux-gnueabihf-cpp
CXXFLAGS=-I/opt/xtools/arm-linux-gnueabihf/usr/include
LD=arm-linux-gnueabihf-ld
LIBRARY_PATH=/opt/xtools/arm-linux-gnueabihf/usr/lib
PATH=[/opt/xtools/chain-armv7/bin]
RANLIB=arm-linux-gnueabihf-ranlib
STRIP=arm-linux-gnueabihf-strip
[conf]
tools.gnu:host_triplet=arm-linux-gnueabihf

Configuration (profile_build):
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=9
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

apr/1.7.4: Forced build from source
apr/1.7.4 (test package): Installing package
Requirements
    apr/1.7.4 from local cache - Cache
Packages
    apr/1.7.4:0a55575c31cb553c11a11103974cbcf4338da16c - Invalid

Cross-build from 'Linux:x86_64' to 'Linux:armv7'
Installing (downloading, building) binaries...
apr/1.7.4: WARN: Build folder is dirty, removing it: /home/stephen/.conan/data/apr/1.7.4/_/_/build/0a55575c31cb553c11a11103974cbcf4338da16c
apr/1.7.4: Configuring sources in /home/stephen/.conan/data/apr/1.7.4/_/_/source/src
Downloading apr-1.7.4.tar.bz2 completed [873.56k]                                        apr/1.7.4: :
apr/1.7.4:
apr/1.7.4: Copying sources to build folder
apr/1.7.4: Building your package in /home/stephen/.conan/data/apr/1.7.4/_/_/build/0a55575c31cb553c11a11103974cbcf4338da16c
apr/1.7.4: Generator txt created conanbuildinfo.txt
apr/1.7.4: Calling generate()
apr/1.7.4: Aggregating env generators
apr/1.7.4: Calling build()
apr/1.7.4: Apply patch (conan): Use BUILD_SHARED_LIBS to conditionally build static/dynamic libs
apr/1.7.4: Apply patch (bugfix): Replace deprecated sys_siglist[] with strsignal()
apr/1.7.4: Calling:
 > "/home/stephen/.conan/data/apr/1.7.4/_/_/build/0a55575c31cb553c11a11103974cbcf4338da16c/src/configure" '--disable-shared' '--enable-static' '--prefix=/' '--bindir=${prefix}/bin' '--sbindir=${prefix}/bin' '--libdir=${prefix}/lib' '--includedir=${prefix}/include' '--oldincludedir=${prefix}/include' '--host=arm-linux-gnueabihf' '--build=x86_64-linux-gnu' '--with-installbuilddir=${prefix}/res/build-1' 'apr_cv_mutex_robust_shared=yes'
checking build system type... x86_64-pc-linux-gnu
checking host system type... arm-unknown-linux-gnueabihf
checking target system type... arm-unknown-linux-gnueabihf
Configuring APR library
Platform: arm-unknown-linux-gnueabihf
checking for working mkdir -p... yes
APR Version: 1.7.4
checking for chosen layout... apr
checking for arm-linux-gnueabihf-gcc... arm-linux-gnueabihf-gcc
checking whether the C compiler works... yes

omitting a long list of checks ....

checking for shmctl... yes
checking for create_area... no
checking for mprotect... yes
checking for MAP_ANON in sys/mman.h... yes
checking for /dev/zero... configure: error: cannot check for file existence when cross compiling
apr/1.7.4:
apr/1.7.4: ERROR: Package '0a55575c31cb553c11a11103974cbcf4338da16c' build failed
apr/1.7.4: WARN: Build folder /home/stephen/.conan/data/apr/1.7.4/_/_/build/0a55575c31cb553c11a11103974cbcf4338da16c/build-release
ERROR: apr/1.7.4: Error in build() method, line 113
        autotools.configure()
        ConanException: Error 1 while executing "/home/stephen/.conan/data/apr/1.7.4/_/_/build/0a55575c31cb553c11a11103974cbcf4338da16c/src/configure" '--disable-shared' '--enable-static' '--prefix=/' '--bindir=${prefix}/bin' '--sbindir=${prefix}/bin' '--libdir=${prefix}/lib' '--includedir=${prefix}/include' '--oldincludedir=${prefix}/include' '--host=arm-linux-gnueabihf' '--build=x86_64-linux-gnu' '--with-installbuilddir=${prefix}/res/build-1' 'apr_cv_mutex_robust_shared=yes'

@CLAassistant
Copy link

CLAassistant commented May 18, 2023

CLA assistant check
All committers have signed the CLA.

@jcar87
Copy link
Contributor

jcar87 commented May 18, 2023

Hi @swebb2066, thank you for your contribution.

For completion, could you attach a log to the PR description that shows the error that you get when trying to cross-build this recipe (without these changes)?

My understanding is that when --target and --host are passed to the ./configure script (with the relevant triples when cross-building), the checks are not performed, as Autotools knows that it is crossbuilding and does not attempt to run the compiled test executables. Whether or not it can proceed with the build without additional input, that's a different story, but would love to see a log.

Thanks!

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@swebb2066 swebb2066 marked this pull request as ready for review May 19, 2023 05:40
@conan-center-bot

This comment has been minimized.

@stale
Copy link

stale bot commented Jun 18, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 18, 2023
@stale stale bot removed the stale label Jun 18, 2023
@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

@conan-center-bot

This comment has been minimized.

Copy link
Contributor

@valgur valgur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very nice solution to a tricky problem. Thank you!

Copy link
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Apr 24, 2024
Copy link
Contributor

This pull request has been automatically closed because it has not had recent activity. Thank you for your contributions.

@github-actions github-actions bot closed this May 25, 2024
@swebb2066
Copy link
Contributor Author

@prince-chrismc Could you please reopen this - it just needs a second reviewer.

@prince-chrismc
Copy link
Contributor

prince-chrismc commented May 25, 2024

I am no longer involved in the Conan project So i unfortunately can't help. However I do see questions from the team #17609 (comment) that have not been answered so you might what to explain these changes in more detail if you'd like to get this moving

@conan-center-bot

This comment has been minimized.

@swebb2066
Copy link
Contributor Author

However I do see questions from the team #17609 (comment) that have not been answered

I answered this by adding the log in an edit to the PR. In summary, using the command:
conan create . apr/1.7.4@ -pr:h arm-linux-gnueabihf -pr:b default
results in
checking for /dev/zero... configure: error: cannot check for file existence when cross compiling

My understanding is that when --target and --host are passed to the ./configure script (with the relevant triples when cross-building), the checks are not performed

So this understanding is not correct,

@conan-center-bot
Copy link
Collaborator

Conan v1 pipeline ✔️

All green in build 2 (5d74097ac8d5f6c747959011018839af8123a973):

  • apr/1.7.4:
    All packages built successfully! (All logs)

  • apr/1.7.0:
    All packages built successfully! (All logs)


Conan v2 pipeline ✔️

Note: Conan v2 builds are now mandatory. Please read our discussion about it.

All green in build 2 (5d74097ac8d5f6c747959011018839af8123a973):

  • apr/1.7.4:
    All packages built successfully! (All logs)

  • apr/1.7.0:
    All packages built successfully! (All logs)

Copy link
Contributor

@franramirez688 franramirez688 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked it for Conan 2 and it's working too:

$ conan create . --version 1.7.4 -pr:h cross
...
======== Input profiles ========
Profile host:
[settings]
arch=armv7
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=8
os=Linux
[options]
boost/*:bzip2=False
boost/*:shared=False
boost/*:zlib=False
log4cxx/*:shared=True
yaml-cpp/*:shared=False
[conf]
tools.gnu:host_triplet=arm-linux-gnueabihf
[buildenv]
AR=arm-linux-gnueabihf-ar
AS=arm-linux-gnueabihf-as
CC=arm-linux-gnueabihf-gcc
CXX=arm-linux-gnueabihf-g++
CXXCC=arm-linux-gnueabihf-cpp
LD=arm-linux-gnueabihf-ld
RANLIB=arm-linux-gnueabihf-ranlib
STRIP=arm-linux-gnueabihf-strip

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux
....
apr/1.7.4: package(): Packaged 41 '.h' files
apr/1.7.4: package(): Packaged 3 files: LICENSE, apr-1-config, libtool
apr/1.7.4: package(): Packaged 1 '.a' file: libapr-1.a
apr/1.7.4: package(): Packaged 1 '.exp' file: apr.exp
apr/1.7.4: package(): Packaged 1 '.mk' file: apr_rules.mk
apr/1.7.4: package(): Packaged 1 '.sh' file: mkdir.sh
apr/1.7.4: package(): Packaged 2 '.awk' files: make_var_export.awk, make_exports.awk
apr/1.7.4: Created package revision 2fa96a8ace312b66d276862dbb33e02f
apr/1.7.4: Package 'a9facdc916a89b51805165331047fa4dca273ad3' created
apr/1.7.4: Full package reference: apr/1.7.4#d1ced664417e992ee2cfe16d40e9d195:a9facdc916a89b51805165331047fa4dca273ad3#2fa96a8ace312b66d276862dbb33e02f
apr/1.7.4: Package folder /root/.conan2/p/b/apr8171acf48b1ae/p
WARN: deprecated: Usage of deprecated Conan 1.X features that will be removed in Conan 2.X:
WARN: deprecated:     'env_info' used in: apr/1.7.4

I'm getting an error running the test_package but I'm sure I'm missing some CFLAGS injected via profile:

gmake[2]: Warning: File 'CMakeFiles/test_package.dir/flags.make' has modification time 1.2 s in the future
[ 50%] Building C object CMakeFiles/test_package.dir/test_package.c.o
In file included from /root/.conan2/p/b/apr8171acf48b1ae/p/include/apr_version.h:130,
                 from /home/develop/conan-center-index/recipes/apr/all/test_package/test_package.c:1:
/root/.conan2/p/b/apr8171acf48b1ae/p/include/apr.h:381:10: error: unknown type name ‘off64_t’
  381 | typedef  off64_t           apr_off_t;
      |          ^~~~~~~
gmake[2]: *** [CMakeFiles/test_package.dir/build.make:76: CMakeFiles/test_package.dir/test_package.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test_package.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2

ERROR: apr/1.7.4 (test package): Error in build() method, line 21
	cmake.build()
	ConanException: Error 2 while executing

Without this fix, we got a fast error:

checking for mprotect... yes
checking for MAP_ANON in sys/mman.h... yes
checking for /dev/zero... configure: error: cannot check for file existence when cross compiling

apr/1.7.4: ERROR:
Package 'a9facdc916a89b51805165331047fa4dca273ad3' build failed
apr/1.7.4: WARN: Build folder /root/.conan2/p/b/apr939632588d82c/b/build-release
ERROR: apr/1.7.4: Error in build() method, line 114
	autotools.configure()
	ConanException: Error 1 while executing

cc @jcar87

@jcar87
Copy link
Contributor

jcar87 commented Jun 24, 2024

My understanding is that when --target and --host are passed to the ./configure script (with the relevant triples when cross-building), the checks are not performed

So this understanding is not correct,

The vast majority of projects that use autotools and make use of the AC_TRY_RUN macro, do provide a default fallback when cross-compiling, as per the documentation here: https://ftp.gnu.org/old-gnu/Manuals/autoconf-2.53/html_node/Test-Programs.html

In that regard, apr cannot be cross-compiled by traditional means, and the only fallback is to use a cache file - so this makes apr a bit unique in this sense (have not encountered a case similar to this in conan center so far for a library that is built with autotools). Indeed the only way to cross-compile that is documented by upstream is by pre-empting the configuration checks with a cache file that needs to be generated on the target system.

I can see there are some commits/issues upstream dealing with some of the quirks:

The problem with conan center bundling pre-generated cache files, is that they are too "wide" a net to cast - some things are very specific to the build environment (I can see some absolute paths on the machine they were generated on) - and some things may not necessarily be "universally" true - for example, some are checks on headers that may or may not be available.

With @franramirez688 we have identified about 5 variables coming from checks for a cross-build - I think that narrows it down quite a lot, and if we can assume they are true in the general case, we can happily pass those to configure, rather than an entire pre-generated cache file. On the other hand, preserving the ability to do is useful, but it would be up to the user to generate them and provide one that suits their needs.

#24329

@jcar87
Copy link
Contributor

jcar87 commented Jun 24, 2024

closed in favour of #24329 but please comment if there are any further issues

@jcar87 jcar87 closed this Jun 24, 2024
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.

8 participants