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

[bug] Premake generator is broken #17345

Open
Enhex opened this issue Nov 19, 2024 · 5 comments · May be fixed by #17350
Open

[bug] Premake generator is broken #17345

Enhex opened this issue Nov 19, 2024 · 5 comments · May be fixed by #17350
Assignees

Comments

@Enhex
Copy link
Contributor

Enhex commented Nov 19, 2024

Describe the bug

Conan version 2.9.2

How to reproduce it

when calling the generated conan_setup() in conandeps.premake5.lua without arguments,
it only works with x86 release build because in conan_setup_build() it calls
filter { "configurations:release", "architecture:x86_64" }
which filters away all the setup calls for any other configuration.

when i call conan create . on my recipe it seems to default to debug build,
because it fails to add dependencies' include dirs.

it's possible to work around the wrong config detection by manually specifying
the configuration string (example: conan_setup("release_x86_64"),
for every configuration combination...

bug_premake.zip

Conan 1's Premake generator worked fine, if it ain't broke why break it?

@memsharded memsharded self-assigned this Nov 19, 2024
@memsharded memsharded linked a pull request Nov 20, 2024 that will close this issue
@memsharded
Copy link
Member

Hi @Enhex

Thanks for your feedback.

I am doing #17350, including a test and some pending fixes to Premake, because this generator seems to have quite low usage, so there was a mismatch with the compiler.version that was not working and it was undertested.

It seems to be working fine for x86_64, not sure what could be failing.

@Enhex
Copy link
Contributor Author

Enhex commented Nov 20, 2024

when I run conan create . the package build silently(?) fails.
take note of the Building nanovg (debug), which mismatches the Conan generator's release (the generated Premake Lua scripts only contain release config)?

nanovg/master: Calling build()
nanovg/master: RUN: premake5 gmake2
Building configurations...
Running action 'gmake2'...
Generated Makefile...
Generated nanovg.make...
Done (18ms).

nanovg/master: RUN: build
==== Building nanovg (debug) ====
Creating obj/Debug
Creating bin/Debug
nanovg.c
In file included from nanovg/src/nanovg.c:26:
nanovg/src/fontstash.h:150:10: fatal error: ft2build.h: No such file or directory
  150 | #include <ft2build.h>
      |          ^~~~~~~~~~~~
compilation terminated.
make[1]: *** [nanovg.make:142: obj/Debug/nanovg.o] Error 1
make: *** [Makefile:30: nanovg] Error 2

it seems to be silent because it carries on to run the test_package which also fails because there's no compiled library:

======== Testing the package: Building ========
nanovg/master (test package): Calling build()
nanovg/master (test package): Running CMake.configure()
nanovg/master (test package): RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/mnt/hdd/dev_hdd/nanovg/conan-nanovg/test_package" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/mnt/hdd/dev_hdd/nanovg/conan-nanovg/test_package"
-- Using Conan toolchain: /mnt/hdd/dev_hdd/nanovg/conan-nanovg/test_package/build/gcc-14-x86_64-17-release/generators/conan_toolchain.cmake
-- Conan toolchain: Defining architecture flag: -m64
-- Conan toolchain: C++ Standard 17 with extensions OFF
-- The CXX compiler identification is GNU 14.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Target declared 'nanovg::nanovg'
CMake Error at build/gcc-14-x86_64-17-release/generators/cmakedeps_macros.cmake:67 (message):
  Library 'nanovg' not found in package.  If 'nanovg' is a system library,
  declare it with 'cpp_info.system_libs' property
Call Stack (most recent call first):
  build/gcc-14-x86_64-17-release/generators/nanovg-Target-release.cmake:23 (conan_package_library_targets)
  build/gcc-14-x86_64-17-release/generators/nanovgTargets.cmake:24 (include)
  build/gcc-14-x86_64-17-release/generators/nanovg-config.cmake:16 (include)
  CMakeLists.txt:5 (find_package)


-- Configuring incomplete, errors occurred!

this happens because in the generated premake file there's only support for 1 configuration which mismatches what's actually being used.
for example in conan_freetype_vars_release_x86_64.premake5.lua:

-- ...
t_conandeps["release_x86_64"]["freetype"] = {}
t_conandeps["release_x86_64"]["freetype"]["includedirs"] = {"/home/desktop/.conan2/p/b/freete219fd5cdef6f/p/include",
"/home/desktop/.conan2/p/b/freete219fd5cdef6f/p/include/freetype2"}
t_conandeps["release_x86_64"]["freetype"]["libdirs"] = {"/home/desktop/.conan2/p/b/freete219fd5cdef6f/p/lib"}
-- ...

and in conandeps.premake5.lua:

function conan_setup_build(conf, pkg)
    if conf == nil then
        filter { "configurations:release", "architecture:x86_64" } -- defaults to only working with this configuration
            conan_setup_build("release_x86_64")
        filter {}
    elseif pkg == nil then
        for k,v in pairs(conandeps[conf]) do
            conan_setup_build(conf, k)
        end
    else

        includedirs(conandeps[conf][pkg]["includedirs"])
        bindirs(conandeps[conf][pkg]["bindirs"])
        defines(conandeps[conf][pkg]["defines"])

    end
end

Why the generated Premake scripts are release/debug and architecture specific?
with the Conan 1 generator they weren't and you'd use separate build directory for each configuration,
which avoids the need to manually select the 1 generated config in the premake5.lua file.

i don't understand what this new generator tries to solves, it only seems to over-complicate things with all these nested dictionaries, merging and recursion.
the old generator just generate a list of includedirs/defines/etc and a function that adds them to Premake.

@memsharded
Copy link
Member

I don't know, I have very little idea about Premake of how the PremakeDeps works.
It was contributed in #13390 by @Ohjurot, maybe they can give a bit more of insights.

conan create .

It would be great to have the conanfile and necessary files to reproduce that.

@Enhex
Copy link
Contributor Author

Enhex commented Nov 20, 2024

my first post got a .zip download with a reproducible example.
here's the link again: https://github.com/user-attachments/files/17819834/bug_premake.zip

for more context it's my initial attempt to upgrade the following script from Conan 1 to Conan 2,
and I ended up committing the conan_setup("release_x86_64") work around.
https://github.com/Enhex/conan-nanovg

regarding #13390 as i suspected it's a multi build attempt.
perhaps like Conan 1 had separate generators for multi build and single build Premake can do that too,
to keep things simple.

@Ohjurot
Copy link
Contributor

Ohjurot commented Nov 21, 2024

Hello again,

thank you for the heads up!

As already written in full detail in my comment to your PR @Enhex (#17355 (comment)) this is from my POV expected behavior and not a bug. Yes it is a bit unlucky that it does not work with the out of the box "first" premake script.

One very important info is that all configurations supported by your premake script needs to be covered by conan. So if you use the starter example from premake you already need at least two builds (Debug and Release). For me it is not clear how premake decided which architecture to use. However you need to make sure that you retrieve your conan dependencies 2 time one time for Debug and one time for Release (architecture needs to match whatever premake decides to use). Any configuration not covered by conan will not have the right includes and links setup.

Taking your premake5.lua file it is quit easy to fix by hard coding the architecture to 64-Bit (32-Bit is also possible but then make sure to also fetch 32-Bit conan libs):

location_dir = "./"

include(location_dir .. "conandeps.premake5.lua")

workspace("nanovg")
    location(location_dir)
    architecture "x86_64"
    configurations { "Debug", "Release" }

    project("nanovg")
        kind "StaticLib"
        language "C++"
        cppdialect "C++17"
        targetdir = location_dir .. "bin/%{cfg.buildcfg}"

        conan_setup()

        files{
            "nanovg/src/**",
        }

        links{"OpenGL32.lib"}
        defines{"FONS_USE_FREETYPE"}

        filter "configurations:Debug"
            defines { "DEBUG" }
            symbols "On"

        filter "configurations:Release"
            defines { "NDEBUG" }
            optimize "On"

In case you also want to support 32-Bit I would recommend taking a look at premake5's platforms:
https://premake.github.io/docs/platforms/

You could configure the platforms as follows:

platforms { "x32", "x64" }
filter { "platforms:x32" }
    architecture "x86"
filter {}
filter { "platforms:x64" }
    architecture "x86_64"
filter {}

When doing like that you need to make sure to fetch the following 4 conan dependencies:

  • Debug x86
  • Release x86
  • Debug x86_64
  • Release x86_64

You can see a full working example (template repo) here: https://github.com/Moxibyte/MoxPP (However without 32-Bit support)

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

Successfully merging a pull request may close this issue.

3 participants