Skip to content

Commit

Permalink
Build micromamba with /MD (#2862)
Browse files Browse the repository at this point in the history
* Build micromamba with /MD

* Factor same dependencies

* Factor header only libraries
  • Loading branch information
AntoinePrv authored Sep 22, 2023
1 parent 3c200f9 commit 60962b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/static_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ concurrency:
cancel-in-progress: true

jobs:
conda-build:
micromamba-static-unix:
name: "micromamba - ${{ matrix.platform }}-${{ matrix.arch }}"
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
shell: cmd
# remove libsolv overlay-ports once https://github.com/microsoft/vcpkg/pull/31275 is released
run: |
vcpkg install --overlay-ports=.\ports\libsolv --triplet x64-windows-static
vcpkg install --overlay-ports=.\ports\libsolv --triplet x64-windows-static-md
- uses: hendrikmuhs/ccache-action@main
with:
variant: sccache
Expand All @@ -129,12 +129,12 @@ jobs:
- name: build micromamba
shell: cmd
run: |
set CMAKE_PREFIX_PATH=.\vcpkg_installed\x64-windows-static
set CMAKE_PREFIX_PATH=.\vcpkg_installed\x64-windows-static-md
cmake -S . ^
-B build ^
-D CMAKE_CXX_COMPILER_LAUNCHER=sccache ^
-D CMAKE_C_COMPILER_LAUNCHER=sccache ^
-D CMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" ^
-D CMAKE_MSVC_RUNTIME_LIBRARY="MultiThreadedDLL" ^
-D CMAKE_BUILD_TYPE="Release" ^
-D BUILD_LIBMAMBA=ON ^
-D BUILD_STATIC=ON ^
Expand Down
37 changes: 17 additions & 20 deletions libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ set(LIBMAMBA_PRIVATE_HEADERS
# Targets and link
# ================

find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(tl-expected REQUIRED)
find_package(nlohmann_json REQUIRED)

macro(libmamba_create_target target_name linkage output_name)
string(TOUPPER "${linkage}" linkage_upper)
if (NOT ${linkage_upper} MATCHES "^(SHARED|STATIC)$")
Expand All @@ -330,6 +335,14 @@ macro(libmamba_create_target target_name linkage output_name)
${LIBMAMBA_SOURCES}
)

# Header only libraries are always linked the same way
target_link_libraries(
${target_name}
PUBLIC
tl::expected
nlohmann_json::nlohmann_json
)

mamba_target_add_compile_warnings(
${target_name}
WARNING_AS_ERROR ${MAMBA_WARNING_AS_ERROR}
Expand Down Expand Up @@ -414,31 +427,25 @@ macro(libmamba_create_target target_name linkage output_name)
target_link_options(${target_name} PUBLIC -static-libstdc++ -static-libgcc)
endif()

find_package(fmt REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(tl-expected REQUIRED)

add_compile_definitions(SPDLOG_FMT_EXTERNAL)
target_link_libraries(
${target_name}
PUBLIC
${STATIC_DEPS}
${MAMBA_FORCE_DYNAMIC_LIBS}
spdlog::spdlog_header_only
fmt::fmt-header-only
spdlog::spdlog_header_only
)

elseif (WIN32)

set(CMAKE_PREFIX_PATH "$ENV{VCPKG_ROOT}/installed/x64-windows-static/")
set(CMAKE_PREFIX_PATH "$ENV{VCPKG_ROOT}/installed/x64-windows-static-md/")

# For Windows we have a vcpkg based build system right now.
find_package(LibArchive REQUIRED)
find_package(CURL CONFIG REQUIRED)
find_package(yaml-cpp CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(fmt REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_library(LIBLZMA_LIBRARIES lzma REQUIRED)
find_library(LZ4_LIBRARY NAMES lz4)
find_library(LZO2_LIBRARY NAMES lzo2)
Expand All @@ -449,7 +456,6 @@ macro(libmamba_create_target target_name linkage output_name)
find_library(LIBSOLV_BUILD_STATICRARIES NAMES solv)
find_library(LIBSOLVEXT_BUILD_STATICRARIES NAMES solvext)
find_package(reproc++ CONFIG REQUIRED)
find_package(tl-expected REQUIRED)

find_library(LIBXML2_LIBRARY NAMES libxml2)
find_library(ICONV_LIBRARY NAMES libiconv iconv)
Expand All @@ -468,7 +474,6 @@ macro(libmamba_create_target target_name linkage output_name)
${BZIP2_LIBRARIES}
${LIBLZMA_LIBRARIES}
CURL::libcurl
nlohmann_json::nlohmann_json
fmt::fmt-header-only
# Since conda-forge spdlog is built with a bundled version of fmt we use the
# header only version to avoid chasing after the correct fmt version mathching
Expand All @@ -480,7 +485,6 @@ macro(libmamba_create_target target_name linkage output_name)
${sodium_LIBRARY_RELEASE}
reproc++
reproc
tl::expected
)

add_compile_definitions(
Expand All @@ -490,7 +494,7 @@ macro(libmamba_create_target target_name linkage output_name)
SOLV_BUILD_STATIC
)
include_directories($ENV{CONDA_PREFIX}/Library/include/)
include_directories($ENV{VCPKG_ROOT}/installed/x64-windows-static/include/)
include_directories($ENV{VCPKG_ROOT}/installed/x64-windows-static-md/include/)
endif()
else ()
message(" -> Dynamically linking against libmamba (shared) dependencies")
Expand All @@ -504,9 +508,6 @@ macro(libmamba_create_target target_name linkage output_name)
find_package(OpenSSL REQUIRED)
find_package(yaml-cpp CONFIG REQUIRED)
find_package(reproc++ CONFIG REQUIRED)
find_package(tl-expected REQUIRED)
find_package(fmt REQUIRED)
find_package(spdlog CONFIG REQUIRED)

set(LIBMAMBA_LIBRARIES_DEPS
${LIBSOLV_LIBRARIES}
Expand All @@ -520,7 +521,6 @@ macro(libmamba_create_target target_name linkage output_name)
yaml-cpp
reproc++
reproc
tl::expected
fmt::fmt
# Since conda-forge spdlog is built with a bundled version of fmt we use the
# header only version to avoid chasing after the correct fmt version mathching
Expand Down Expand Up @@ -585,12 +585,9 @@ macro(libmamba_create_target target_name linkage output_name)
endif()

if (${linkage_upper} STREQUAL "STATIC")
find_package(nlohmann_json CONFIG REQUIRED)
find_package(Threads REQUIRED)

target_link_libraries(${target_name} PUBLIC
nlohmann_json::nlohmann_json
Threads::Threads)
target_link_libraries(${target_name} PUBLIC Threads::Threads)
endif ()

list(APPEND libmamba_targets ${target_name})
Expand Down

0 comments on commit 60962b9

Please sign in to comment.