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

Fix pkgconfig metadata on windows #51

Merged
merged 6 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions recipe/cmake_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
project(cf_dummy LANGUAGES CXX)
cmake_minimum_required(VERSION 3.12)
find_package(absl REQUIRED CONFIG)

add_executable(flags_example flags_example.cpp)
target_link_libraries(flags_example absl::flags absl::strings)
51 changes: 51 additions & 0 deletions recipe/cmake_test/flags_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// taken from https://abseil.io/docs/cpp/guides/flags
// exercises both flags and non-flags (for abseil_dll) import

#include <iostream>
#include <string>

#include "absl/flags/flag.h"
#include "absl/flags/marshalling.h"
#include "absl/strings/string_view.h"

struct PortNumber {
explicit PortNumber(int p = 0) : port(p) {}

int port; // Valid range is [0..32767]
};

// Returns a textual flag value corresponding to the PortNumber `p`.
std::string AbslUnparseFlag(PortNumber p) {
// Delegate to the usual unparsing for int.
return absl::UnparseFlag(p.port);
}

// Parses a PortNumber from the command line flag value `text`.
// Returns true and sets `*p` on success; returns false and sets `*error`
// on failure.
bool AbslParseFlag(absl::string_view text, PortNumber* p, std::string* error) {
// Convert from text to int using the int-flag parser.
if (!absl::ParseFlag(text, &p->port, error)) {
return false;
}
if (p->port < 0 || p->port > 32767) {
*error = "not in range [0,32767]";
return false;
}
return true;
}

ABSL_FLAG(PortNumber, port, PortNumber(0), "What port to listen on");

// exercise above code

int main() {
PortNumber p = absl::GetFlag(FLAGS_port);
std::cout << "default: " << p.port << std::endl;

absl::SetFlag(&FLAGS_port, 10101);
p = absl::GetFlag(FLAGS_port);
std::cout << "modified: " << p.port << std::endl;

return 0;
}
54 changes: 49 additions & 5 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% set version = "20220623.0" %}
{% set v_major = version.split(".")[0] %}

# shared builds for flags_* libraries are not supported on windows, see
# https://github.com/abseil/abseil-cpp/pull/1115
Expand Down Expand Up @@ -33,14 +34,14 @@ source:
- patches/0006-avoid-building-static-libs-on-windows-when-BUILD_SHA.patch
# backport https://github.com/abseil/abseil-cpp/pull/1269
- patches/0007-Compile-all-dependencies-of-the-DLL-with-ABSL_CONSUM.patch
{% if shared_libs == "ON" %}
# Helps downstream packages import the dll without an extra defin
# Helps downstream packages import the dll without an extra define
# https://github.com/conda-forge/abseil-cpp-feedstock/issues/43#issuecomment-1242969515
- patches/0008-default_dll_import_for_windows.patch
{% endif %}
- patches/0008-default-dll-import-for-windows.patch # [win and shared_libs == "ON"]
# add pkgconfig metadata for shared builds on windows
- patches/0009-add-pkgconfig-metadata-for-shared-windows-builds.patch

build:
number: 4
number: 5

outputs:
{% if shared_libs == "ON" %}
Expand All @@ -66,6 +67,13 @@ outputs:
- abseil-cpp ={{ version }}

test:
requires:
- {{ compiler('cxx') }}
- cmake
- ninja
- pkg-config
files:
- cmake_test/
commands:
# windows-only (almost-)all-in-one DLL + import library
- if not exist %LIBRARY_BIN%\\abseil_dll.dll exit 1 # [win]
Expand All @@ -84,8 +92,24 @@ outputs:
{% else %}
- if exist %LIBRARY_LIB%\\absl_{{ each_lib }}.lib exit 1 # [win]
{% endif %}

# pkg-config (should point to abseil_dll on shared windows builds)
- pkg-config --print-errors --exact-version "{{ v_major }}" absl_{{ each_lib }}
{% endfor %}

# pkg-config (abseil_dll)
- pkg-config --print-errors --exact-version "{{ v_major }}" abseil_dll # [win]

# CMake integration
- cd cmake_test
- export CMAKE_ARGS="$CMAKE_ARGS -GNinja -DCMAKE_BUILD_TYPE=Release" # [unix]
- set "CMAKE_ARGS=%CMAKE_ARGS% -GNinja -DCMAKE_BUILD_TYPE=Release" # [win]
- cmake $CMAKE_ARGS -DCMAKE_CXX_STANDARD={{ cxx_standard }} . # [unix]
- cmake %CMAKE_ARGS% -DCMAKE_CXX_STANDARD={{ cxx_standard }} . # [win]
- cmake --build .
- ./flags_example # [unix]
- flags_example.exe # [win]

{% else %} # shared_libs == "OFF"

- name: libabseil-static
Expand All @@ -106,6 +130,13 @@ outputs:
# make sure we don't co-install with old version of old package name
- abseil-cpp ={{ version }}
test:
requires:
- {{ compiler('cxx') }}
- cmake
- ninja
- pkg-config
files:
- cmake_test/
commands:
# absence of DLL on windows
- if exist %LIBRARY_BIN%\\abseil_dll.dll exit 1 # [win]
Expand All @@ -117,8 +148,21 @@ outputs:
- if not exist %LIBRARY_LIB%\\absl_{{ each_lib }}.lib exit 1 # [win]
# absence of shared libs
- test ! -f $PREFIX/lib/libabsl_{{ each_lib }}${SHLIB_EXT} # [unix]

# pkg-config
- pkg-config --print-errors --exact-version "{{ v_major }}" absl_{{ each_lib }}
{% endfor %}

# CMake integration
- cd cmake_test
- export CMAKE_ARGS="$CMAKE_ARGS -GNinja -DCMAKE_BUILD_TYPE=Release" # [unix]
- set "CMAKE_ARGS=%CMAKE_ARGS% -GNinja -DCMAKE_BUILD_TYPE=Release" # [win]
- cmake $CMAKE_ARGS -DCMAKE_CXX_STANDARD={{ cxx_standard }} . # [unix]
- cmake %CMAKE_ARGS% -DCMAKE_CXX_STANDARD={{ cxx_standard }} . # [win]
- cmake --build .
- ./flags_example # [unix]
- flags_example.exe # [win]

{% endif %} # shared_libs == "ON" / "OFF"

# for compatibility with previous behavior of "abseil-cpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 336f3e70a058f6b07aa25725ea2a23a739f190ef Mon Sep 17 00:00:00 2001
From: Francesco Biscani <[email protected]>
Date: Sat, 21 Sep 2019 15:05:46 +0200
Subject: [PATCH 1/7] patch out the build issue on clang4 osx
Subject: [PATCH 1/9] patch out the build issue on clang4 osx

---
absl/time/internal/cctz/include/cctz/civil_time_detail.h | 4 ++++
Expand All @@ -23,5 +23,5 @@ index a5b084e6..0a9a4389 100644
#include <limits>
#include <ostream>
--
2.37.3.windows.1
2.38.1.windows.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From a99ff2d64fb489dfc207572edb2d8a151d3c92f9 Mon Sep 17 00:00:00 2001
From: Francesco Biscani <[email protected]>
Date: Sat, 21 Sep 2019 21:39:26 +0200
Subject: [PATCH 2/7] fix for linking to the CoreFoundation framework on OSX
Subject: [PATCH 2/9] fix for linking to the CoreFoundation framework on OSX

---
absl/time/CMakeLists.txt | 6 ++++--
Expand All @@ -27,5 +27,5 @@ index debab3ba..4eb9ebf8 100644
absl_cc_library(
NAME
--
2.37.3.windows.1
2.38.1.windows.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 1a77917fe7c5c3feece1a608d5537f848f4e930f Mon Sep 17 00:00:00 2001
From: "Uwe L. Korn" <[email protected]>
Date: Thu, 30 Jul 2020 13:01:32 +0200
Subject: [PATCH 3/7] remove "-ignore:4221" from ABSL_MSVC_LINKOPTS
Subject: [PATCH 3/9] remove "-ignore:4221" from ABSL_MSVC_LINKOPTS

see also https://github.com/microsoft/vcpkg/issues/13945
---
Expand Down Expand Up @@ -41,5 +41,5 @@ index 0d6c1ec3..8df92751 100644
# Standard). These flags are used for detecting whether or not the target
# architecture has hardware support for AES instructions which can be used
--
2.37.3.windows.1
2.38.1.windows.1

4 changes: 2 additions & 2 deletions recipe/patches/0004-add-missing-osx-workaround.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 3b5f3943a593d5c7544b594d0bd6eec569d26067 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <[email protected]>
Date: Fri, 1 Jul 2022 13:37:17 +0200
Subject: [PATCH 4/7] add missing osx workaround
Subject: [PATCH 4/9] add missing osx workaround

---
absl/debugging/internal/examine_stack.cc | 4 ++++
Expand All @@ -23,5 +23,5 @@ index 5bdd341e..e86f384f 100644
#include <sys/ucontext.h>
#endif
--
2.37.3.windows.1
2.38.1.windows.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From fa9d0f4abb4c4a3112e2c1faa3138206354bd6c4 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <[email protected]>
Date: Wed, 2 Mar 2022 08:07:20 +1100
Subject: [PATCH 5/7] alphabetize ABSL_INTERNAL_DLL_TARGETS
Subject: [PATCH 5/9] alphabetize ABSL_INTERNAL_DLL_TARGETS

this is a pure reshuffle; no additions/deletions
---
Expand Down Expand Up @@ -220,5 +220,5 @@ index 00cddb84..5638ed66 100644

function(absl_internal_dll_contains)
--
2.37.3.windows.1
2.38.1.windows.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 5b0225562085b17749a04a57cd6e89e8926c7053 Mon Sep 17 00:00:00 2001
From: "H. Vetinari" <[email protected]>
Date: Wed, 2 Mar 2022 13:43:37 +1100
Subject: [PATCH 6/7] avoid building static libs on windows when
Subject: [PATCH 6/9] avoid building static libs on windows when
BUILD_SHARED_LIBS=ON

except all flags_* libraries, for which DLL builds on windows
Expand Down Expand Up @@ -57,5 +57,5 @@ index 5638ed66..b9a3664b 100644
"str_format_internal"
"strings"
--
2.37.3.windows.1
2.38.1.windows.1

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From d4b55614c1f10515c7a8a98ec24fe5a1df5750d2 Mon Sep 17 00:00:00 2001
From: Isuru Fernando <[email protected]>
Date: Fri, 2 Sep 2022 04:04:37 -0500
Subject: [PATCH 7/7] Compile all dependencies of the DLL with ABSL_CONSUME_DLL
Subject: [PATCH 7/9] Compile all dependencies of the DLL with ABSL_CONSUME_DLL

---
CMake/AbseilDll.cmake | 1 +
Expand All @@ -20,5 +20,5 @@ index b9a3664b..5e1316f0 100644
install(TARGETS abseil_dll EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
--
2.37.3.windows.1
2.38.1.windows.1

29 changes: 29 additions & 0 deletions recipe/patches/0008-default-dll-import-for-windows.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 82228c69ff641a83838ba5f0d12dc3f6f4d60f28 Mon Sep 17 00:00:00 2001
From: Mark Harfouche <[email protected]>
Date: Sun, 11 Sep 2022 10:32:19 -0400
Subject: [PATCH 8/9] default dll import for windows

---
absl/base/config.h | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/absl/base/config.h b/absl/base/config.h
index 8533aead..cc92658c 100644
--- a/absl/base/config.h
+++ b/absl/base/config.h
@@ -737,10 +737,9 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#if defined(_MSC_VER)
#if defined(ABSL_BUILD_DLL)
#define ABSL_DLL __declspec(dllexport)
-#elif defined(ABSL_CONSUME_DLL)
-#define ABSL_DLL __declspec(dllimport)
#else
-#define ABSL_DLL
+// conda-forge addition: by default, users import the definitions defined here
+#define ABSL_DLL __declspec(dllimport)
#endif
#else
#define ABSL_DLL
--
2.38.1.windows.1

15 changes: 0 additions & 15 deletions recipe/patches/0008-default_dll_import_for_windows.patch

This file was deleted.

Loading