Skip to content

Commit 52a28b8

Browse files
authored
Update libabseil to 20260107.1 (#4897)
Co-authored-by: Alexis Placet <2400067+Alex-PLACET@users.noreply.github.com>
1 parent 94ef3b5 commit 52a28b8

File tree

4 files changed

+238
-12
lines changed

4 files changed

+238
-12
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "=========================================="
5+
echo "Building libabseil tests..."
6+
echo "=========================================="
7+
8+
mkdir -p build_tests
9+
cd build_tests
10+
11+
emcmake cmake ../tests \
12+
-GNinja \
13+
-DCMAKE_BUILD_TYPE=Release \
14+
-DCMAKE_FIND_ROOT_PATH=$PREFIX \
15+
-DCMAKE_PREFIX_PATH=$PREFIX
16+
17+
emmake ninja
18+
19+
echo "Running libabseil tests..."
20+
node test_abseil.js
21+
22+
echo "=========================================="
23+
echo "All libabseil tests passed!"
24+
echo "=========================================="
Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
context:
2-
version: '20240116.3'
2+
version: '20260107.1'
33
name: libabseil
44

55
package:
@@ -8,10 +8,10 @@ package:
88

99
source:
1010
url: https://github.com/abseil/abseil-cpp/archive/refs/tags/${{ version }}.tar.gz
11-
sha256: e887b423da5a1ba66e71610094fd7147ff2febfedccdfbf00f2c644ac21adf83
11+
sha256: 4314e2a7cbac89cac25a2f2322870f343d81579756ceff7f431803c2c9090195
1212

1313
build:
14-
number: 1
14+
number: 0
1515

1616
requirements:
1717
build:
@@ -21,13 +21,29 @@ requirements:
2121
- ninja
2222

2323
tests:
24+
- package_contents:
25+
lib:
26+
- libabsl_base.a
27+
- libabsl_civil_time.a
28+
- libabsl_cord.a
29+
- libabsl_strings.a
30+
- libabsl_status.a
31+
include:
32+
- absl/base/config.h
33+
- absl/strings/string_view.h
34+
- absl/status/status.h
35+
- absl/synchronization/mutex.h
2436
- script:
25-
- test -f $PREFIX/lib/libabsl_base.a
26-
- test -f $PREFIX/lib/libabsl_civil_time.a
27-
- test -f $PREFIX/lib/libabsl_cord.a
28-
- test -f $PREFIX/lib/libabsl_cordz_functions.a
29-
- test -f $PREFIX/include/absl/synchronization/mutex.h
30-
- test -f $PREFIX/include/absl/base/thread_annotations.h
37+
- bash build_tests.sh
38+
requirements:
39+
build:
40+
- ${{ compiler('cxx') }}
41+
- cmake
42+
- ninja
43+
files:
44+
recipe:
45+
- build_tests.sh
46+
- tests/
3147

3248
about:
3349
homepage: https://github.com/abseil/abseil-cpp
@@ -36,11 +52,13 @@ about:
3652
license_file: LICENSE
3753
summary: Abseil Common Libraries (C++)
3854
description: |
39-
Abseil is an open-source collection of C++ code (compliant to C++11)
40-
designed to augment the C++ standard library.
41-
documentation: https://github.com/abseil/abseil-cpp
55+
Abseil is an open-source collection of C++ library code designed to augment
56+
the C++ standard library. The Abseil library code is collected from Google's
57+
own C++ code base and has been extensively tested and used in production.
58+
documentation: https://abseil.io
4259
repository: https://github.com/abseil/abseil-cpp
4360

4461
extra:
4562
recipe-maintainers:
4663
- KGB99
64+
- Alex-PLACET
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
project(abseil_test CXX)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
find_package(absl REQUIRED)
8+
9+
add_executable(test_abseil test_abseil.cpp)
10+
target_link_libraries(test_abseil PRIVATE
11+
absl::strings
12+
absl::str_format
13+
absl::status
14+
absl::statusor
15+
absl::flat_hash_map
16+
absl::flat_hash_set
17+
absl::base
18+
absl::log
19+
absl::time
20+
)
21+
22+
if(EMSCRIPTEN)
23+
target_link_options(test_abseil PRIVATE
24+
-sALLOW_MEMORY_GROWTH=1
25+
-sINITIAL_MEMORY=64MB
26+
)
27+
endif()
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <vector>
4+
5+
#include "absl/strings/str_cat.h"
6+
#include "absl/strings/str_split.h"
7+
#include "absl/strings/string_view.h"
8+
#include "absl/strings/str_format.h"
9+
#include "absl/container/flat_hash_map.h"
10+
#include "absl/container/flat_hash_set.h"
11+
#include "absl/status/status.h"
12+
#include "absl/status/statusor.h"
13+
#include "absl/time/time.h"
14+
#include "absl/time/clock.h"
15+
16+
// Report helper
17+
static int failures = 0;
18+
#define CHECK(cond) \
19+
do { \
20+
if (!(cond)) { \
21+
std::cerr << "FAIL: " #cond " (line " << __LINE__ << ")" << std::endl; \
22+
++failures; \
23+
} \
24+
} while (false)
25+
26+
// ---------------------------------------------------------------------------
27+
// Test absl::strings
28+
// ---------------------------------------------------------------------------
29+
void test_strings() {
30+
std::cout << "Testing absl::strings..." << std::endl;
31+
32+
// StrCat
33+
std::string s = absl::StrCat("Hello", ", ", "World", "!");
34+
CHECK(s == "Hello, World!");
35+
36+
// StrFormat
37+
std::string formatted = absl::StrFormat("value=%d pi=%.2f", 42, 3.14159);
38+
CHECK(formatted == "value=42 pi=3.14");
39+
40+
// StrSplit
41+
std::vector<std::string> parts = absl::StrSplit("a,b,c,d", ',');
42+
CHECK(parts.size() == 4);
43+
CHECK(parts[0] == "a");
44+
CHECK(parts[3] == "d");
45+
46+
// string_view
47+
absl::string_view sv = "abcdef";
48+
CHECK(sv.size() == 6);
49+
CHECK(sv.substr(1, 3) == "bcd");
50+
51+
std::cout << " absl::strings OK" << std::endl;
52+
}
53+
54+
// ---------------------------------------------------------------------------
55+
// Test absl::flat_hash_map / flat_hash_set
56+
// ---------------------------------------------------------------------------
57+
void test_containers() {
58+
std::cout << "Testing absl::containers..." << std::endl;
59+
60+
// flat_hash_map
61+
absl::flat_hash_map<std::string, int> map;
62+
map["one"] = 1;
63+
map["two"] = 2;
64+
map["three"] = 3;
65+
CHECK(map.size() == 3);
66+
CHECK(map["one"] == 1);
67+
CHECK(map.contains("two"));
68+
CHECK(!map.contains("four"));
69+
70+
// flat_hash_set
71+
absl::flat_hash_set<int> set = {1, 2, 3, 4, 5};
72+
CHECK(set.size() == 5);
73+
CHECK(set.contains(3));
74+
CHECK(!set.contains(6));
75+
set.insert(6);
76+
CHECK(set.contains(6));
77+
78+
std::cout << " absl::containers OK" << std::endl;
79+
}
80+
81+
// ---------------------------------------------------------------------------
82+
// Test absl::Status / absl::StatusOr
83+
// ---------------------------------------------------------------------------
84+
absl::StatusOr<int> safe_divide(int a, int b) {
85+
if (b == 0) {
86+
return absl::InvalidArgumentError("division by zero");
87+
}
88+
return a / b;
89+
}
90+
91+
void test_status() {
92+
std::cout << "Testing absl::Status / absl::StatusOr..." << std::endl;
93+
94+
// OK status
95+
absl::Status ok = absl::OkStatus();
96+
CHECK(ok.ok());
97+
98+
// Error status
99+
absl::Status err = absl::NotFoundError("item not found");
100+
CHECK(!err.ok());
101+
CHECK(err.code() == absl::StatusCode::kNotFound);
102+
103+
// StatusOr success
104+
auto result = safe_divide(10, 2);
105+
CHECK(result.ok());
106+
CHECK(*result == 5);
107+
108+
// StatusOr failure
109+
auto bad = safe_divide(10, 0);
110+
CHECK(!bad.ok());
111+
CHECK(bad.status().code() == absl::StatusCode::kInvalidArgument);
112+
113+
std::cout << " absl::Status OK" << std::endl;
114+
}
115+
116+
// ---------------------------------------------------------------------------
117+
// Test absl::Time
118+
// ---------------------------------------------------------------------------
119+
void test_time() {
120+
std::cout << "Testing absl::Time..." << std::endl;
121+
122+
absl::Time epoch = absl::UnixEpoch();
123+
absl::Time now = absl::Now();
124+
125+
// now should be strictly after epoch
126+
CHECK(now > epoch);
127+
128+
// Duration arithmetic
129+
absl::Duration one_hour = absl::Hours(1);
130+
absl::Duration one_min = absl::Minutes(1);
131+
CHECK(one_hour == 60 * one_min);
132+
133+
absl::Time future = epoch + absl::Seconds(3600);
134+
CHECK(future - epoch == one_hour);
135+
136+
std::cout << " absl::Time OK" << std::endl;
137+
}
138+
139+
// ---------------------------------------------------------------------------
140+
// Main
141+
// ---------------------------------------------------------------------------
142+
int main() {
143+
std::cout << "=== Testing Abseil C++ library ===" << std::endl;
144+
145+
test_strings();
146+
test_containers();
147+
test_status();
148+
test_time();
149+
150+
if (failures > 0) {
151+
std::cerr << failures << " test(s) FAILED." << std::endl;
152+
return 1;
153+
}
154+
155+
std::cout << "=== All Abseil tests passed! ===" << std::endl;
156+
return 0;
157+
}

0 commit comments

Comments
 (0)