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

[question] Correct way to use XCrun in Conan v2 #12071

Closed
1 task done
paulocoutinhox opened this issue Sep 9, 2022 · 9 comments · Fixed by #12172
Closed
1 task done

[question] Correct way to use XCrun in Conan v2 #12071

paulocoutinhox opened this issue Sep 9, 2022 · 9 comments · Fixed by #12172
Assignees
Milestone

Comments

@paulocoutinhox
Copy link
Contributor

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 paulocoutinhox changed the title [question] Correct way to use XCrun [question] Correct way to use XCrun in Conan v2 Sep 9, 2022
@czoido czoido self-assigned this Sep 12, 2022
@czoido
Copy link
Contributor

czoido commented Sep 12, 2022

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.

@paulocoutinhox
Copy link
Contributor Author

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.

@czoido
Copy link
Contributor

czoido commented Sep 14, 2022

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.

@paulocoutinhox
Copy link
Contributor Author

paulocoutinhox commented Sep 16, 2022

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:

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

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.

@czoido
Copy link
Contributor

czoido commented Sep 16, 2022

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 czoido added this to the 1.53 milestone Sep 16, 2022
@czoido
Copy link
Contributor

czoido commented Sep 16, 2022

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.

@memsharded
Copy link
Member

Closed by #12172, will be in 1.53

@paulocoutinhox
Copy link
Contributor Author

Nice and thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants