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

First try to test with modules under OSX with clang v16.0.1 #1

Closed

Conversation

ClausKlein
Copy link

I run into problems while linking the module-test:

clang++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk \
  -Wl,-search_paths_first -Wl,-headerpad_max_install_names  test/CMakeFiles/test-module.dir/__/src/fmt.cc.o \
  test/CMakeFiles/module-test.dir/module-test.cc.o test/CMakeFiles/module-test.dir/test-main.cc.o -o bin/module-test \
  test/libtest-main.a  fmt.cc.pcm  test/gtest/libgtest.a

Undefined symbols for architecture x86_64:
  "fmt::v9::vsystem_error(int, fmt::v9::basic_string_view<char>, fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender, char>>)", referenced from:
      std::__1::system_error fmt::v9::system_error<>(int, fmt::v9::basic_format_string<char>) in libtest-main.a(gtest-extra.cc.o)
  "fmt::v9::file::dup(int)", referenced from:
      output_redirect::output_redirect(__sFILE*) in libtest-main.a(gtest-extra.cc.o)
  "fmt::v9::file::dup2(int)", referenced from:
      output_redirect::output_redirect(__sFILE*) in libtest-main.a(gtest-extra.cc.o)
      output_redirect::restore() in libtest-main.a(gtest-extra.cc.o)
  "fmt::v9::file::pipe(fmt::v9::file&, fmt::v9::file&)", referenced from:
      output_redirect::output_redirect(__sFILE*) in libtest-main.a(gtest-extra.cc.o)
  "fmt::v9::file::read(void*, unsigned long)", referenced from:
      output_redirect::restore_and_read() in libtest-main.a(gtest-extra.cc.o)
      read(fmt::v9::file&, unsigned long) in libtest-main.a(gtest-extra.cc.o)
  "fmt::v9::file::close()", referenced from:
      fmt::v9::file::operator=(fmt::v9::file&&) in libtest-main.a(gtest-extra.cc.o)
      output_redirect::restore() in libtest-main.a(gtest-extra.cc.o)
      output_redirect::restore_and_read() in libtest-main.a(gtest-extra.cc.o)
  "fmt::v9::file::~file()", referenced from:
      output_redirect::output_redirect(__sFILE*) in libtest-main.a(gtest-extra.cc.o)
      output_redirect::~output_redirect() in libtest-main.a(gtest-extra.cc.o)
ld: symbol(s) not found for architecture x86_64
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
bash-3.2$ 

 * use the standard `test-main.cc` component instead of injected test infrastructure sources
 * undo now obsolete commit `00235d8a` from July 2021
Clang cannot import user-defined literals as it seems.
@ClausKlein ClausKlein marked this pull request as draft April 24, 2023 11:53
Comment on lines -58 to -60
if (FMT_MODULE)
return ()
endif ()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This disables all tests?

Comment on lines +108 to 113
set(FMT_CAN_MODULE ${FMT_MODULE})
if (CMAKE_CXX_STANDARD GREATER 17)
if (MSVC_VERSION GREATER 1933 OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(FMT_CAN_MODULE ON)
endif ()
endif ()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems more clear to me

CMakeLists.txt Outdated Show resolved Hide resolved
@ClausKlein
Copy link
Author

With this example CMakeLists.txt, CMake v3.26 works with clang++ v16.0.1 and c++20 modules
But how may this used for the fmt library as module?

cmake_minimum_required(VERSION 3.26)

set(CMAKE_EXPORT_COMPILE_COMMANDS YES)

project(clang-tidy-issue LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS NO)
set(CMAKE_CXX_STANDARD_REQUIRED YES)

set(CMAKE_CXX_SCAN_FOR_MODULES YES)

# First find clang-tidy, this also allows users to provide hints
find_program(CLANG_TIDY NAMES clang-tidy REQUIRED)

# https://clang.llvm.org/docs/StandardCPlusPlusModules.html#how-to-build-projects-using-modules
# clang++ -std=c++20 -x c++-module foo.cxx --precompile -o build/foo.pcm
# clang++ -std=c++20 main.cxx -fprebuilt-module-path=build build/foo.pcm -o build/Hello
#
# see https://gitlab.kitware.com/cmake/cmake/-/blob/v3.26.3/Help/dev/experimental.rst?ref_type=tags#c-20-module-apis
# and https://gitlab.kitware.com/cmake/cmake/-/blob/v3.26.3/.gitlab/ci/cxx_modules_rules_gcc.cmake?ref_type=tags
#     https://gitlab.kitware.com/cmake/cmake/-/blob/v3.26.3/.gitlab/ci/cxx_modules_rules_clang.cmake?ref_type=tags

set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API 2182bf5c-ef0d-489a-91da-49dbc3090d2a)
set(CMake_TEST_CXXModules_UUID "a246741c-d067-4019-a8fb-3d16b0c9d1d3")
# Workaround for C++Modules: Missing module map flags in exported compile commands
# see https://gitlab.kitware.com/cmake/cmake/-/issues/24618
set(CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT} @<OBJECT>.modmap")

set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
  string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE
                "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E -x c++ <SOURCE>"
                " -MT <DYNDEP_FILE> -MD -MF <DEP_FILE>"
                " -fmodules-ts -fdep-file=<DYNDEP_FILE> -fdep-output=<OBJECT> -fdep-format=trtbd"
                " -o <PREPROCESSED_SOURCE>"
  )
  set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "gcc")
  set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG "-fmodules-ts -fmodule-mapper=<MODULE_MAP_FILE> -fdep-format=trtbd -x c++")

  set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY};-checks=*,-llvmlibc-*,-fuchsia-*,-cppcoreguidelines-init-variables")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "clang")

  # FIXME: how to control the output path of the pcm file with cmake, so that clang-tidy find them too?
  set(CMAKE_CXX_CLANG_TIDY
    "${CLANG_TIDY};-extra-arg=-fprebuilt-module-path=${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/foo.dir"
  )
endif()

file(WRITE foo.cppm
     [=[
// Global module fragment where #includes can happen
module;
#include <iostream>

// first thing after the Global module fragment must be a module command
// XXX import std.core;

export module foo;

export class foo {
public:
  foo() = default;
  ~foo() = default;
  void helloworld();
};

void foo::helloworld() { std::cout << "hello world\n"; }
]=]
)

file(WRITE main.cxx
     [=[
import foo;

auto main() -> int
{
  foo myFoo;
  myFoo.helloworld();
  return 0;
}
]=]
)

add_library(foo)
target_sources(
  foo
  PUBLIC FILE_SET
         cxx_modules
         TYPE
         CXX_MODULES
         FILES
         foo.cppm
)
add_executable(hello main.cxx)
target_link_libraries(hello foo)

enable_testing()
add_test(NAME hello COMMAND hello)

install(TARGETS foo ARCHIVE PUBLIC_HEADER
  FILE_SET cxx_modules DESTINATION include
  CXX_MODULES_BMI DESTINATION share/cxx-modules
)
include(cpack)

@ClausKlein ClausKlein marked this pull request as ready for review April 24, 2023 15:05
@ClausKlein
Copy link
Author

@DanielaE
Copy link
Owner

Cool! 😎
I will look into this after I have clang on MSYS2 running in CI. Until then I will push as many forced updates as needed. As soon as this is working, please rebase on top of that.
Whatever you change, it must not kill CI! And please make your changes as few and as small as possible. The smallest viable changeset is the best one. Improvements can come later.
Even better: try to get it on CI, too - if at all possible.

@DanielaE
Copy link
Owner

With this example CMakeLists.txt, CMake v3.26 works with clang++ v16.0.1 and c++20 modules But how may this used for the fmt library as module?

This example is from Victor, right?

@ClausKlein
Copy link
Author

With this example CMakeLists.txt, CMake v3.26 works with clang++ v16.0.1 and c++20 modules But how may this used for the fmt library as module?

This example is from Victor, right?

It is based on this https://discourse.cmake.org/t/c-20-modules-api-example/7303

@ClausKlein ClausKlein marked this pull request as draft April 24, 2023 18:56
@DanielaE DanielaE force-pushed the test-with-modules branch 4 times, most recently from 4b58317 to 8f1a722 Compare April 25, 2023 14:52
@ClausKlein ClausKlein deleted the branch DanielaE:test-with-modules April 26, 2023 07:48
@ClausKlein ClausKlein closed this Apr 26, 2023
@ClausKlein ClausKlein deleted the test-with-modules branch April 26, 2023 07:48
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 this pull request may close these issues.

2 participants