Skip to content

[question] Please document settings_target and its difference from settings #3208

@DoDoENT

Description

@DoDoENT

What is your question?

I'm curious about the difference between self.settings and self.settings_target. I understand that self.settings_build refer to settings on the build machine, and that self.settings refer to host (target) for which package is built. However, why is then self.settings_target needed?

I've search the documentation for settings_target keyword, and found almost nothing. There is only a obscure mention in "Adding information" part of the package_id method documentation , a brief mention in XCRun documentation, without any explanation, and a broken link in "Read more" section of "Tool requires packages".

I've basically discovered the settings_target by reading these weird comments in the official Android NDK conan package.

While creating my own NDK conan package, I wanted to make a similar validation, so I initially wrote the validate method in my recipe like this:

def validate(self):
    if self.settings.os != "Android":
        raise ConanInvalidConfiguration(
            f"You've added {self.ref} as a build requirement, while os={self.settings.os} != Android"
        )
    if self.settings.compiler != 'clang':
        raise ConanInvalidConfiguration(
            f"Android NDK only supports clang compiler, while compiler={self.settings.compiler} != 'clang'"
        )
    if self.settings.compiler.libcxx not in ['c++_static', 'c++_shared', 'libc++v2']:
        raise ConanInvalidConfiguration(f'Unsupported libcxx library:{self.settings.compiler.libcxx}')

However, this validation always failed, both when creating the package (which is kind of expected, since I was creating the package using profile for my mac), and while using the package (which I didn't expect, since host system was now Android, and build system was mac, so WTF?!?).

Then, I rewrote my validate like this:

def validate(self):
    if self.settings_target.os != "Android":
        raise ConanInvalidConfiguration(
            f"You've added {self.ref} as a build requirement, while os={self.settings_target.os} != Android"
        )
    if self.settings_target.compiler != 'clang':
        raise ConanInvalidConfiguration(
            f"Android NDK only supports clang compiler, while compiler={self.settings_target.compiler} != 'clang'"
        )
    if self.settings_target.compiler.libcxx not in ['c++_static', 'c++_shared', 'libc++v2']:
        raise ConanInvalidConfiguration(f'Unsupported libcxx library:{self.settings_target.compiler.libcxx}')

... and this failed with accessing None object, because apparently sometimes self.settings_target is None. Why? I've seen this being raised as an issue where another toolchain is being packaged into conan.

My final version of validate is this:

def validate(self):
    if self.settings_target is not None:
        if self.settings_target.os != "Android":
            raise ConanInvalidConfiguration(
                f"You've added {self.ref} as a build requirement, while os={self.settings_target.os} != Android"
            )
        if self.settings_target.compiler != 'clang':
            raise ConanInvalidConfiguration(
                f"Android NDK only supports clang compiler, while compiler={self.settings_target.compiler} != 'clang'"
            )
        if self.settings_target.compiler.libcxx not in ['c++_static', 'c++_shared', 'libc++v2']:
            raise ConanInvalidConfiguration(f'Unsupported libcxx library:{self.settings_target.compiler.libcxx}')

... which works correctly, but I don't understand why.

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions