conan icon indicating copy to clipboard operation
conan copied to clipboard

[question] Correct way to use XCrun in Conan v2

Open paulocoutinhox opened this issue 3 years ago • 7 comments
trafficstars

Hi,

What is the correct way to use XCRun in conan v1/v2 compatible?

I made this: https://github.com/nativium/nativium/pull/21/files#diff-46d8e7b650df6bb59541dab2a0fc2c56436aeb97a5c4079e18a6831515164bddR3-R7

But it is ugly: from conan.tools.apple.apple import XCRun

Thanks.

paulocoutinhox avatar Sep 09 '22 14:09 paulocoutinhox

Hi @paulocoutinhox,

We did not make the XCRun tool public yet on purpouse. You can check the comments in the sources. In conan2 we tried to make everything more explicit, so the idea is that instead of using XCRun, you use the configuration tools.apple:sdk_path. This value is used inside the generators to set the path for the sdk location and will be passed as SDKROOT or -isysroot depending on the generator used. Hope this helps, please tell me if this would fit your needs. Thanks for the question.

czoido avatar Sep 12 '22 10:09 czoido

Hi,

Ok, i see that you have a method that return it:

def apple_sdk_path(conanfile):
    sdk_path = conanfile.conf.get("tools.apple:sdk_path")
    if not sdk_path:
        sdk_path = XCRun(conanfile.settings).sdk_path
    return sdk_path

But how i can use it in practice?

Or i need use XcodeBuild, like this:

x = XcodeBuild(self)
sysroot = x.sdkroot

?

Thanks.

paulocoutinhox avatar Sep 14 '22 06:09 paulocoutinhox

Hi @paulocoutinhox,

The apple_sdk_path tool is not meant to be used in recipes, only documented tools should be used. For the moment, the valid apple tools are fix_apple_shared_install_name, is_apple_os, to_apple_arch, XcodeDeps, XcodeDeps and XcodeToolchain.

The recommended use is that instead of doing something like:

path = apple_sdk_path(self)

or

xb = XcodeBuild(self)
path = xb.sdkroot

you do:

path = self.conf.get("tools.apple:sdk_path")

To set that configuration you can do it in your profiles in the [conf] section:

[settings]
arch=x86_64
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=13
os=Macos
....

[conf]
tools.apple:sdk_path=path/to/sdk

or directly in the command line:

conan create . -c tools.apple:sdk_path=path/to/sdk

Hope this helps.

czoido avatar Sep 14 '22 07:09 czoido

Hi @czoido

The only necessary code is this?

path = self.conf.get("tools.apple:sdk_path")

Because inside conan it has a fallback:

def apple_sdk_path(conanfile):
    sdk_path = conanfile.conf.get("tools.apple:sdk_path")
    if not sdk_path:
        sdk_path = XCRun(conanfile.settings).sdk_path
    return sdk_path

It is here: https://github.com/conan-io/conan/blob/9c4487efc26118dc5953720bddd3eb265c2f485e/conan/tools/apple/apple.py#L73-L77

I cant set on conf, i need set on my toolchain to make it work automatically.

I can't keep making my process worse because of Conan version 2. I need to keep getting the SDK path correct as it was before.

I need only replace it here: https://github.com/nativium/nativium/blob/main/conan/darwin-toolchain/conanfile.py#L102

I need a way that don't will change in v2.

paulocoutinhox avatar Sep 16 '22 05:09 paulocoutinhox

Hi @paulocoutinhox,

Let me mark this issue as look-into and check with the team so we can discuss what how we should approach these cases. Thanks a lot for the feedback.

czoido avatar Sep 16 '22 06:09 czoido

Hi @paulocoutinhox,

After having a look at this with the team and checking that some Conan Center recipes also use XCRun we will make it public, so I'm marking this issue with the label feature for the next release. We also talked about adding some internal code or arguments to address this.

I would like to comment as well that in Conan 1.48 we added support for the CMakeToolchain for several of the flags and CMake variables that you are using in the toolchain with the intention of replace those toolchains and have built-in support for that. You can check the support in CMakeToolchain in the docs. It has not support for AutotoolsToolchain yet but we will add it soon.

czoido avatar Sep 16 '22 13:09 czoido

Thanks @czoido

Autotools use this part? https://github.com/nativium/nativium/blob/main/conan/darwin-toolchain/conanfile.py#L105-L106

And CMake use this part? https://github.com/nativium/nativium/blob/main/conan/darwin-toolchain/conanfile.py#L108-L115

paulocoutinhox avatar Sep 16 '22 16:09 paulocoutinhox

Closed by https://github.com/conan-io/conan/pull/12172, will be in 1.53

memsharded avatar Sep 22 '22 23:09 memsharded

Nice and thanks!

paulocoutinhox avatar Sep 22 '22 23:09 paulocoutinhox