conan icon indicating copy to clipboard operation
conan copied to clipboard

Can the generated props file to point to the same package for both debug and release configs?

Open sandybhat16 opened this issue 1 year ago • 8 comments

What is your question?

I have a requirement where I wanted to create only release package for both x86 and x64. But while installing the package, as there is no Debug package created, the generator does not create an entry in the props file for Debug config. It creates only for Release config. But is there a way where I can include Debug configs also in the props file to point to the same release package?

Below is the props generated.

<?xml version="1.0" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<ImportGroup Label="PropertySheets">
		<Import Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'Win32'" Project="conan_mypackage_release_win32.props"/>
		<Import Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'x64'" Project="conan_mypackage_release_x64.props"/>
	</ImportGroup>
	<PropertyGroup>
		<conan_mypackage_props_imported>True</conan_mypackage_props_imported>
	</PropertyGroup>
</Project>

I would like something like below:

<?xml version="1.0" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<ImportGroup Label="PropertySheets">
		<Import Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'Win32'" Project="conan_mypackage_release_win32.props"/>
		<Import Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'x64'" Project="conan_mypackage_release_x64.props"/>
		<Import Condition="'$(Configuration)' == 'Debug' And '$(Platform)' == 'Win32'" Project="conan_mypackage_release_win32.props"/>
		<Import Condition="'$(Configuration)' == 'Debug' And '$(Platform)' == 'x64'" Project="conan_mypackage_release_x64.props"/>
	</ImportGroup>
	<PropertyGroup>
		<conan_mypackage_props_imported>True</conan_mypackage_props_imported>
	</PropertyGroup>
</Project>

Have you read the CONTRIBUTING guide?

  • [X] I've read the CONTRIBUTING guide

sandybhat16 avatar Jul 31 '24 07:07 sandybhat16

Hi @sandybhat16

If you want to install "Release" dependencies for both Debug and Release project configurations this is done with:

conan install . -s &:build_type=Release -s build_type=Release 
conan install . -s &:build_type=Debug -s build_type=Release 

As the default build_type is Release, this is the same as:

conan install .
conan install . -s &:build_type=Debug

A different story is that in Windows it is generally not possible to link different build types together and it often will raise linking errors.

memsharded avatar Jul 31 '24 07:07 memsharded

Thank you for your response. Can this be also achieved through conan recipe when I create the package? Because I do not want to alter my conan install call, which is generic to all the packages(Other packages need separate debug and release for x86 & x64). If this can be achieved through the recipe then my conan install . for build_type=Debug or build_type=Release should install the same package.

sandybhat16 avatar Jul 31 '24 09:07 sandybhat16

No, this is not possible in conanfile, conanfiles cannot define settings, only profile/command line arguments can define settings.

s(Other packages need separate debug and release for x86 & x64).

yes, this is the expected in Windows/msvc. What is that special package that is valid both for Debug and Release? Why don't you just remove the build_type in that specific recipe, like in package_id()?

memsharded avatar Jul 31 '24 09:07 memsharded

I have already omitted build_type. This is just a requirement that we deploy only release binaries that has to be consumed by any package. We deploy release binaries as no debugging is required by the consumer. To give you more context, I provide you with the details:

My Recipe:

from conan import ConanFile
from conan.tools.files import copy
import os
import shutil

class MyPackageRecipe(ConanFile):
    name = "mypackage"
    version = "10.0.0"

    # Optional metadata
    license = "xxx"
    author = "xxx"
    #url = "xxx"
    description = "xxx"
    
    settings = "os", "compiler", "build_type", "arch"
    build_policy = "never"
    
    def layout(self):
        _os = str(self.settings.os).lower()
        _arch = str(self.settings.arch).lower()
        root_folder = os.path.join(self.settings.arch)       
        self.folders.build = root_folder
        self.folders.source = self.folders.build
        self.cpp.source.includedirs = ["include"]
        self.cpp.source.libdirs = ["lib"]

        
    def package(self):
        local_lib_folder = os.path.join(self.source_folder, self.cpp.source.libdirs[0], str(self.settings.build_type))
        
        copy(self, "*.*", local_lib_folder, os.path.join(self.package_folder, "lib"), keep_path=True, excludes="*.exp")

CLI to create other packages:

conan export-pkg CustomBoostRecipe.py -s arch=x86 -s build_type=Debug
conan export-pkg CustomBoostRecipe.py -s arch=x86 -s build_type=Release

CLI to create Special package with only Release binaries: conan export-pkg MyPackageRecipe.py -s arch=x86

CLI to upload package: conan upload mypackage/10.0.0:* -r myRemote -c

Common CLI to install package:

$PackageList = boost/1.71.0 gtest/1.81.0 mypackage/10.0.0
conan install $PackageList -s arch=$Platform -s build_type=$Configuration -r $RemoteServer -g MSBuildDeps -of $ConanGeneratedPropsFilesFolder -b missing

Props file generated for other packages:

<?xml version="1.0" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<ImportGroup Label="PropertySheets">
		<Import Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'Win32'" Project="conan_customboostpackage_release_win32.props"/>
		<Import Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'x64'" Project="conan_customboostpackage_release_x64.props"/>
		<Import Condition="'$(Configuration)' == 'Debug' And '$(Platform)' == 'Win32'" Project="conan_customboostpackage_debug_win32.props"/>
		<Import Condition="'$(Configuration)' == 'Debug' And '$(Platform)' == 'x64'" Project="conan_customboostpackage_debug_x64.props"/>
	</ImportGroup>
	<PropertyGroup>
		<conan_customboostpackage_props_imported>True</conan_customboostpackage_props_imported>
	</PropertyGroup>
</Project>

Props file generated for special package:

<?xml version="1.0" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<ImportGroup Label="PropertySheets">
		<Import Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'Win32'" Project="conan_mypackage_release_win32.props"/>
		<Import Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'x64'" Project="conan_mypackage_release_x64.props"/>
	</ImportGroup>
	<PropertyGroup>
		<conan_mypackage_props_imported>True</conan_mypackage_props_imported>
	</PropertyGroup>
</Project>

In the above, the props entry for debug is missing, hence I am trying to find a way using the general conan install command to install both debug and release but the artifact repository contains only release package and both the debug or release config should always install the release package and update the props file accordingly.

Hope I was able to convey the whole scenario :)

sandybhat16 avatar Jul 31 '24 10:07 sandybhat16

But you recipe didn't remove the build_type:

  • I can see that it contains settings = "os", "compiler", "build_type", "arch" so, the binary depends on build_type
  • I can see that it doesn't have a package_id() method removing the build_type either.

memsharded avatar Jul 31 '24 14:07 memsharded

I dropped the build_type from the settings and now it always creates release packages, but still the conan generators still generate the props for only release. This is understood as that is the default and unless not specified what type of build, it cannot generate respective props right? I don't think so there is a way where I can generate this unless I have separate packages for debug and release right?

Update recipe:

from conan import ConanFile
from conan.tools.files import copy
import os
import shutil

class MyPackageRecipe(ConanFile):
    name = "mypackage"
    version = "10.0.0"

    # Optional metadata
    license = "xxx"
    author = "xxx"
    #url = "xxx"
    description = "xxx"
    
    settings = "os", "compiler",  "arch"
    build_policy = "never"
    
    def layout(self):
        _os = str(self.settings.os).lower()
        _arch = str(self.settings.arch).lower()
        root_folder = os.path.join(self.settings.arch)       
        self.folders.build = root_folder
        self.folders.source = self.folders.build
        self.cpp.source.includedirs = ["include"]
        self.cpp.source.libdirs = ["lib"]

        
    def package(self):
        local_lib_folder = os.path.join(self.source_folder, self.cpp.source.libdirs[0], str(self.settings.build_type))
        
        copy(self, "*.*", local_lib_folder, os.path.join(self.package_folder, "lib"), keep_path=True, excludes="*.exp")

sandybhat16 avatar Aug 01 '24 11:08 sandybhat16

Sorry, I am afraid I still don't fully understand the issue.

If I do:

conan install --requires=zlib/1.3.1 -g MSBuildDeps

Then the generated zlib.props file contains only the Release configuration:

<ImportGroup Label="PropertySheets">
	<Import Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'x64'" Project="conan_zlib_release_x64.props"/>
</ImportGroup>

Then, only if I do an install for Debug:

conan install --requires=zlib/1.3.1 -g MSBuildDeps -s build_type=Debug --build=missing

Then I get the 2 configurations in zlib.props:

<ImportGroup Label="PropertySheets">
	<Import Condition="'$(Configuration)' == 'Release' And '$(Platform)' == 'x64'" Project="conan_zlib_release_x64.props"/>
	<Import Condition="'$(Configuration)' == 'Debug' And '$(Platform)' == 'x64'" Project="conan_zlib_debug_x64.props"/>
</ImportGroup>

This is irrespective of the dependency build-type, even if it is a header-only package with only 1 single config, it is still needed to do 2 conan install commands, one for Release and the other for Debug.

Your command above conan install $PackageList doesn't work, it needs the --requires=xxxx syntax. And even if it worked, it doesn't create the .props file with the 2 configurations. We would need complete and exact reproducible instructions to be able to understand this issue, can you please try to provide them?

memsharded avatar Aug 02 '24 10:08 memsharded

Hi @sandybhat16

Any further feedback from my last comment above? Thanks for your feedback.

memsharded avatar Oct 17 '24 12:10 memsharded

Closing as staled, please re-open or create a new ticket if you have any further feedback.

memsharded avatar Nov 25 '24 10:11 memsharded