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

[android] vcpkg_configure_make correct set flags for android build #15605

Conversation

xandox
Copy link
Contributor

@xandox xandox commented Jan 12, 2021

vcpkg_configure_make properly set CFLAGS, CXXFLAGS, LDFLAG, CC and CXX env variables now for android cross compilation.

  • Which triplets are supported/not supported? Mostly android triplets,

  • Have you updated the CI baseline? - no

  • Does your PR follow the maintainer guide?
    yes

@JackBoosY JackBoosY self-assigned this Jan 13, 2021
@JackBoosY JackBoosY added the category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly label Jan 13, 2021
@JackBoosY
Copy link
Contributor

Regression when building mlpack:x86-windows:

armadillo.lib(wrapper2.cpp.obj) : error LNK2019: unresolved external symbol _sgetrf_ referenced in function _wrapper2_sgetrf_
armadillo.lib(wrapper2.cpp.obj) : error LNK2019: unresolved external symbol _dgetrf_ referenced in function _wrapper2_dgetrf_
armadillo.lib(wrapper2.cpp.obj) : error LNK2019: unresolved external symbol _cgetrf_ referenced in function _wrapper2_cgetrf_
armadillo.lib(wrapper2.cpp.obj) : error LNK2019: unresolved external symbol _zgetrf_ referenced in function _wrapper2_zgetrf_

@JackBoosY
Copy link
Contributor

Regression is gone.

@JackBoosY
Copy link
Contributor

@Neumann-A Can you please review again?

Thanks.

@JackBoosY
Copy link
Contributor

Fixes #15255.

scripts/cmake/vcpkg_configure_make.cmake Outdated Show resolved Hide resolved
scripts/cmake/vcpkg_configure_make.cmake Show resolved Hide resolved
scripts/get_cmake_vars/CMakeLists.txt Outdated Show resolved Hide resolved
scripts/get_cmake_vars/CMakeLists.txt Outdated Show resolved Hide resolved
scripts/get_cmake_vars/CMakeLists.txt Outdated Show resolved Hide resolved
scripts/get_cmake_vars/CMakeLists.txt Show resolved Hide resolved
@JackBoosY
Copy link
Contributor

Seems have many regressions when building x64-osx, please get failure logs here.

@xandox xandox requested a review from JackBoosY January 25, 2021 13:58
@venabled
Copy link
Contributor

@xandox Thanks for the contribution. I've been playing around with this PR to try and build 'libiconv' the past two days, and I've found a few things that have prevented that port from building.

I think most of it was that --gcc-toolchain' and '--sysroot' are getting pulled into the VCPKG_DETECTED_CMAKE_C*FLAGS*` variables.

And according to @DanAlbert post in the NDK repo and the NDK integration with other build systems documentation those really shouldn't be in there.

I guess this isn't really a problem with vcpkg_configure_make as it's an issue in Meson ports too. These aren't set as C/CPP flags in the Android toolchain CMake file, so Ill have to keep digging.

@xandox
Copy link
Contributor Author

xandox commented Jan 25, 2021

@venabled hi. I am not sure what you mean. I am able to build libiconv with 21d and 22 ndk. What is you problem?

According to the article you provided - yes, looks like --sysroot and --gcc-toolchain not necessary here, but they are not a problem. They came from android.toolchain.cmake and have correct paths.

@venabled
Copy link
Contributor

I guess I should have been more specific, I had to modify 'libiconv' port as the current port only builds from source if you're on Windows.

@xandox
Copy link
Contributor Author

xandox commented Jan 25, 2021

Yes, sure. See #15606.

@DanAlbert
Copy link

@venabled hi. I am not sure what you mean. I am able to build libiconv with 21d and 22 ndk. What is you problem?

According to the article you provided - yes, looks like --sysroot and --gcc-toolchain not necessary here, but they are not a problem. They came from android.toolchain.cmake and have correct paths.

Possibly superfluous context here, but in case it's helpful:

While they're not necessary to build correctly, as long as they are set to the appropriate values they shouldn't harm anything. The toolchain file still configures them because (iirc), CMake's find_* behaviors depend on CMAKE_SYSROOT. There were also old versions of our gradle plugin that depended on that value being present.

-gcc-toolchain I think has done nothing useful since r19 :)

The problem in the NDK bug linked was that folks had set --sysroot's value to the wrong path, and that can definitely break things.

@strega-nil-ms
Copy link
Contributor

Cool, @JackBoosY could you review today?

@@ -1,4 +1,4 @@
if(NOT VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_ANDROID)
if(NOT VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_CROSSCOMPILING)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the point of this change? Port libiconv could be empty when the target has iconv, but it must be built

  • when the target is Windows.
  • when the target is ...

But it doesn't matter if we are cross compiling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I am building libiconv on linux-x64 for linux-arm64 without VCPKG_CROSSCOMPILING it will let empty, for example.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I am building libiconv on linux-x64 for linux-arm64 without VCPKG_CROSSCOMPILING it will let empty, for example.

IIUC that's just the intention of that code block: "iconv is empty unless built for Windows or Android." Probably this assumes iconv system libraries on linux, osx or bsd, and maybe this is not 100% right. But it doesn't matter if you compile from a different platform or natively.

Can you just remove the iconv changes from this PR? IMO they seem to be unrelated to "vcpkg_configure_make flags for android".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, done

@JackBoosY
Copy link
Contributor

Can you please resolve the file conflicts?

@xandox
Copy link
Contributor Author

xandox commented Jul 21, 2021

Can you please resolve the file conflicts?

done

Copy link
Contributor

@dg0yt dg0yt left a comment

Choose a reason for hiding this comment

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

I would like to note that the get_cmake_vars project is transforming into a unit which no longer reports the actual cmake variables. This is probably beneficial for some use cases, but it can fail miserably for other uses.
My preference would be a clearer separation of concerns, e.g. by using different variables for computed effective properties, and/or by offering a separate entry point for getting these properties.

Comment on lines +147 to +150
foreach(_lang IN ITEMS C CXX)
foreach(INCDIR ${CMAKE_${_lang}_IMPLICIT_INCLUDE_DIRECTORIES})
string(APPEND CMAKE_${_lang}_FLAGS " ${CMAKE_INCLUDE_SYSTEM_FLAG_${_lang}}${INCDIR}")
endforeach()
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see the benefit here. Implicit directories are needed to be known in order to find a file in build system configuration steps, but they do not need to be given explicitly to the compiler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately for some cases it needed to be explicitly provided. Especially for macos native compiler.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately for some cases it needed to be explicitly provided. Especially for macos native compiler.

Now I wonder how I can build autotools projects without vcpkg/cmake.

(All really meant constructive. I just want to avoid pitfalls from my personal cross-platform cmake experience.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. good catch.
I am not good in autotools or macos, so some explanation could be not accurate. But what I saw is. There are two different compile system in macos (how I understand this). First one which cmake uses usually placed in /Library/..... The compiler in this system unusable without all this flags and include directories. And cmake provide them to it. The second one placed in /usr/bin and if you just run configure.sh for some autotools package very probably that it will select second one system. And it is what happen right now in master when you install some autotools package by vcpkg. So there is some inconsistent.

When I just start this PR I tried to leave this behaviour unchanged. But guys decided it's not good idea. And now I force autotools use the same compiler as cmake

Copy link
Contributor

Choose a reason for hiding this comment

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

When I just start this PR I tried to leave this behaviour unchanged. But guys decided it's not good idea. And now I force autotools use the same compiler as cmake

Yes, this is a good thing.

I am not good in autotools or macos

I wouldn't claim to be an expert. This discussion is also an invitation for others to help with feedback.

@xandox
Copy link
Contributor Author

xandox commented Jul 21, 2021

I would like to note that the get_cmake_vars project is transforming into a unit which no longer reports the actual cmake variables.

Not sure what you mean. Which variable it reports now?

My preference would be a clearer separation of concerns, e.g. by using different variables for computed effective properties, and/or by offering a separate entry point for getting these properties.

It reports all properties, consumer could use only what they need.

@Neumann-A
Copy link
Contributor

Why do we need host cmake vars? VCPKG should not build for the host but only the target! host binaries are provided by host dependencies! Otherwise patch the buildsystem

@xandox
Copy link
Contributor Author

xandox commented Jul 21, 2021

Why do we need host cmake vars? VCPKG should not build for the host but only the target!

Host cmake vars needed for host tools used during compilation (file generators and so on).

host binaries are provided by host dependencies! Otherwise patch the buildsystem

It's good idea but not for all ports in single pull request. Let's merge this one which works, and then everyone who would like to patch every single autotools port to separate host-build-tools from main package could do it in their own rithm.

@dg0yt
Copy link
Contributor

dg0yt commented Jul 21, 2021

I would like to note that the get_cmake_vars project is transforming into a unit which no longer reports the actual cmake variables.

Not sure what you mean. Which variable it reports now?

All the added lines which look like string(APPEND CMAKE_...) transform the original value of CMAKE_....

@xandox
Copy link
Contributor Author

xandox commented Jul 21, 2021

I would like to note that the get_cmake_vars project is transforming into a unit which no longer reports the actual cmake variables.

Not sure what you mean. Which variable it reports now?

All the added lines which look like string(APPEND CMAKE_...) transform the original value of CMAKE_....

So, you suggest to make another one project like get_cmake_vars_ex? Is get_cmake_vars project needed only for other buildsystems to provide correct options?

@dg0yt
Copy link
Contributor

dg0yt commented Jul 21, 2021

I would like to note that the get_cmake_vars project is transforming into a unit which no longer reports the actual cmake variables.

Not sure what you mean. Which variable it reports now?

All the added lines which look like string(APPEND CMAKE_...) transform the original value of CMAKE_....

So, you suggest to make another one project like get_cmake_vars_ex? Is get_cmake_vars project needed only for other buildsystems to provide correct options?

I didn't want to jump into proposing a particular implementation.

Following the single responsibility principle and the principle of least surprise, get_cmake_vars should do just that: report cmake variables. Still, output may vary by platform, to cover special properties.
And then another script/function can compose the variables to form new variables. It doesn't even need another CMake project, it will simply use the output of get_cmake_vars. If the purpose is providing configuration information for build system, I would probably choose a name like get_build_configuration.

Disclaimer: This is just personal opinion of an external contributor.

@m-kuhn
Copy link
Contributor

m-kuhn commented Aug 27, 2021

Gentle ping, an integration of this would be much appreciated (it's really nice work)

@strega-nil-ms
Copy link
Contributor

This does look good, but it needs to be updated for the new style of z_vcpkg_get_cmake_vars; @xandox are you interested in updating the PR for the new world order; otherwise, @m-kuhn do you want to take over this PR?

@xandox
Copy link
Contributor Author

xandox commented Sep 8, 2021

@strega-nil-ms @m-kuhn Sorry, but right now I have no time to work on this PR. If someone would take over this I will be appreciated.

@JackBoosY JackBoosY marked this pull request as draft September 9, 2021 02:32
@m-kuhn
Copy link
Contributor

m-kuhn commented Sep 10, 2021

I am afraid this pull request is outside my comfort zone and I don't have the time available to expand this zone at the moment.

Even if it was within the zone, what I think this needs currently is:

  1. a core maintainer to comment on [android] vcpkg_configure_make correct set flags for android build #15605 (comment) - which as far as I can see is the only open question at the moment
  2. a rebase / merge of master

and since number 2 depends on number 1 it will be hard to take over for anyone at the moment

@JackBoosY
Copy link
Contributor

If you want to continue this PR, please reopen it.

@JackBoosY JackBoosY closed this Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly
Projects
None yet
10 participants