Skip to content

Commit

Permalink
Add C++ build flags (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
externl authored Feb 19, 2025
1 parent f0ebbe8 commit f3aa6d9
Show file tree
Hide file tree
Showing 28 changed files with 178 additions and 154 deletions.
29 changes: 21 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,33 @@ jobs:
find . -name CMakeLists.txt -type f | while IFS= read -r file; do
dir=$(dirname "$file");
cmake -B "$dir/build" -S "$dir" -DIce_DEBUG=ON -DCMAKE_BUILD_TYPE=Release
cmake --build "$dir/build"
cmake -B "$dir/build" -S "$dir" -DIce_DEBUG=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_COMPILE_WARNING_AS_ERROR=ON
cmake --build "$dir/build" --verbose
done
if: runner.os != 'Windows'

- name: Build C++ Demos
timeout-minutes: 20
working-directory: ice-demos/cpp
run: |
# No IceBT on Windows
Remove-Item -Recurse -Force "IceBT"
# No IceBT on Windows
Remove-Item -Recurse -Force "IceBT"
Get-ChildItem -Recurse -Filter CMakeLists.txt | ForEach-Object {
$ErrorActionPreference = "Stop"
Get-ChildItem -Recurse -Filter CMakeLists.txt | ForEach-Object {
Write-Output "Processing: $_"
$dir = $_.DirectoryName
cmake -B "$dir/build" -S "$dir" -DIce_DEBUG=ON
cmake --build "$dir/build" --config Release
}
# Run cmake configure step
cmake -B "$dir/build" -S "$dir" -DIce_DEBUG=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=ON
if ($LASTEXITCODE -ne 0) { throw "CMake configuration failed" }
# Run cmake build step
cmake --build "$dir/build" --config Release --verbose
if ($LASTEXITCODE -ne 0) { throw "CMake build failed" }
}
if: runner.os == 'Windows'

- name: Build C# Demos
Expand All @@ -113,9 +123,12 @@ jobs:
timeout-minutes: 20
working-directory: ice-demos/csharp
run: |
$ErrorActionPreference = "Stop"
Get-ChildItem -Recurse -Filter *.sln | ForEach-Object {
dotnet build $_.FullName
if ($LASTEXITCODE -ne 0) { throw "dotnet build failed" }
}
if: runner.os == 'Windows'

- name: Run .NET format
Expand Down
9 changes: 3 additions & 6 deletions cpp/DataStorm/clock/Reader.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) ZeroC, Inc.

#include "../../common/Time.h"

#include <DataStorm/DataStorm.h>
#include <Ice/Ice.h>

Expand Down Expand Up @@ -63,12 +65,7 @@ main(int argc, char* argv[])
nullptr,
[](const DataStorm::Sample<string, chrono::system_clock::time_point>& sample)
{
auto time = chrono::system_clock::to_time_t(sample.getValue());
char timeString[100];
if (strftime(timeString, sizeof(timeString), "%x %X", localtime(&time)) == 0)
{
timeString[0] = '\0';
}
auto timeString = Time::formatTime(sample.getValue());
cout << "received time for `" << sample.getKey() << "': " << timeString << endl;
});

Expand Down
9 changes: 2 additions & 7 deletions cpp/DataStorm/node/Writer.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) ZeroC, Inc.

#include "../../common/Time.h"
#include <DataStorm/DataStorm.h>
#include <Ice/Ice.h>

#include <iostream>
#include <random>
#include <string>
Expand Down Expand Up @@ -38,12 +38,7 @@ main(int argc, char* argv[])

while (!node.isShutdown())
{
auto now = chrono::system_clock::to_time_t(chrono::system_clock::now());
char timeString[100];
if (strftime(timeString, sizeof(timeString), "%x %X", localtime(&now)) == 0)
{
timeString[0] = '\0';
}
auto timeString = Time::formatTime(chrono::system_clock::now());
writer.update(timeString);
this_thread::sleep_for(chrono::seconds(1));
}
Expand Down
4 changes: 4 additions & 0 deletions cpp/DataStorm/stock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ project(datastorm_stock CXX)

include(../../cmake/common.cmake)

# This demo requires C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(reader Reader.cpp Stock.ice)
slice2cpp_generate(reader)
target_link_libraries(reader Ice::Ice Ice::DataStorm)
Expand Down
2 changes: 1 addition & 1 deletion cpp/DataStorm/stock/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ main(int argc, char* argv[])
else
{
auto tickers = stocks.getConnectedKeys();
if (find(tickers.begin(), tickers.end(), stock) == tickers.end())
if (ranges::find(tickers, stock) == tickers.end())
{
cout << "unknown stock `" << stock << "'" << endl;
return 1;
Expand Down
16 changes: 3 additions & 13 deletions cpp/Ice/cancellation/Client.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) ZeroC, Inc.

#include "../../common/Env.h"
#include "Greeter.h"

#include <chrono>
Expand All @@ -11,17 +12,6 @@ using namespace std;
int
main(int argc, char* argv[])
{
// Figure out my name.
const char* name = getenv("USER");
if (name == nullptr)
{
name = getenv("USERNAME");
}
if (name == nullptr)
{
name = "masked user";
}

// Create an Ice communicator to initialize the Ice runtime. The CommunicatorHolder is a RAII helper that creates
// the communicator in its constructor and destroys it when it goes out of scope.
const Ice::CommunicatorHolder communicatorHolder{argc, argv};
Expand All @@ -37,7 +27,7 @@ main(int argc, char* argv[])
VisitorCenter::GreeterPrx slowGreeter{communicator, "slowGreeter:tcp -h localhost -p 4061"};

// Send a request to the regular greeter and get the response.
string greeting = greeter->greet(name);
string greeting = greeter->greet(Env::getUsername());
cout << greeting << endl;

// Create another slow greeter proxy with an invocation timeout of 4 seconds (the default invocation timeout is
Expand All @@ -57,7 +47,7 @@ main(int argc, char* argv[])

// Send a request to the slow greeter, and cancel this request after 4 seconds.
function<void()> cancel = slowGreeter->greetAsync(
name,
Env::getUsername(),
[](const string& greeting) { cout << "Received unexpected greeting: " << greeting << endl; },
[](exception_ptr exceptionPtr)
{
Expand Down
3 changes: 2 additions & 1 deletion cpp/Ice/cancellation/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ main(int argc, char* argv[])
Ice::CtrlCHandler ctrlCHandler;

// Set the maximum number of threads in the server thread pool to 10, since Chatbot::greet waits synchronously.
Ice::InitializationData initData{.properties = Ice::createProperties(argc, argv)};
Ice::InitializationData initData;
initData.properties = Ice::createProperties(argc, argv);
initData.properties->setProperty("Ice.ThreadPool.Server.SizeMax", "10");

// Create an Ice communicator to initialize the Ice runtime. The CommunicatorHolder is a RAII helper that creates
Expand Down
14 changes: 2 additions & 12 deletions cpp/Ice/config/Client.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) ZeroC, Inc.

#include "../../common/Env.h"
#include "Greeter.h"

#include <Ice/Ice.h>
Expand All @@ -11,17 +12,6 @@ using namespace std;
int
main(int argc, char* argv[])
{
// Figure out my name.
const char* name = getenv("USER");
if (name == nullptr)
{
name = getenv("USERNAME");
}
if (name == nullptr)
{
name = "masked user";
}

// Create an Ice communicator to initialize the Ice runtime. The communicator gets its configuration properties from
// file config.client in the client's current working directory. The communicator initialization also parses the
// command-line options to find and set additional properties.
Expand All @@ -34,7 +24,7 @@ main(int argc, char* argv[])
communicator->propertyToProxy<VisitorCenter::GreeterPrx>("Greeter.Proxy");

// Send a request to the remote object and get the response.
string greeting = greeter->greet(name);
string greeting = greeter->greet(Env::getUsername());

cout << greeting << endl;
return 0;
Expand Down
17 changes: 4 additions & 13 deletions cpp/Ice/context/Client.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) ZeroC, Inc.

#include "../../common/Env.h"
#include "Greeter.h"

#include <cstdlib>
Expand All @@ -10,20 +11,10 @@ using namespace std;
int
main(int argc, char* argv[])
{
// Figure out my name.
const char* name = getenv("USER");
if (name == nullptr)
{
name = getenv("USERNAME");
}
if (name == nullptr)
{
name = "masked user";
}

// Set the Ice.ImplicitContext property to "Shared" before creating the communicator.
// This is only necessary for the implicit context API (see below).
Ice::InitializationData initData{.properties = Ice::createProperties(argc, argv)};
Ice::InitializationData initData;
initData.properties = Ice::createProperties(argc, argv);
initData.properties->setProperty("Ice.ImplicitContext", "Shared");

// Create an Ice communicator to initialize the Ice runtime. The CommunicatorHolder is a RAII helper that creates
Expand All @@ -39,7 +30,7 @@ main(int argc, char* argv[])

// Send a request to the remote object and get the response. We request a French greeting by setting the context
// parameter.
string greeting = greeter->greet(name, {{"language", "fr"}});
string greeting = greeter->greet(Env::getUsername(), {{"language", "fr"}});
cout << greeting << endl;

// Do it again, this time by setting the context on the proxy.
Expand Down
5 changes: 5 additions & 0 deletions cpp/Ice/filesystem/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

#include "Filesystem.h"

#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable : 4250) // ... : inherits ... via dominance
#endif

// Provides an in-memory implementation of the Filesystem objects.
namespace Server
{
Expand Down
14 changes: 2 additions & 12 deletions cpp/Ice/forwarder/Client.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) ZeroC, Inc.

#include "../../common/Env.h"
#include "Greeter.h"

#include <cstdlib>
Expand All @@ -10,17 +11,6 @@ using namespace std;
int
main(int argc, char* argv[])
{
// Figure out my name.
const char* name = getenv("USER");
if (name == nullptr)
{
name = getenv("USERNAME");
}
if (name == nullptr)
{
name = "masked user";
}

// Create an Ice communicator to initialize the Ice runtime.
const Ice::CommunicatorHolder communicatorHolder{argc, argv};
const Ice::CommunicatorPtr& communicator = communicatorHolder.communicator();
Expand All @@ -29,7 +19,7 @@ main(int argc, char* argv[])
VisitorCenter::GreeterPrx greeter{communicator, "greeter:tcp -h localhost -p 10000"};

// Send a request to the remote object and wait for the response.
string greeting = greeter->greet(name);
string greeting = greeter->greet(Env::getUsername());
cout << greeting << endl;

return 0;
Expand Down
14 changes: 2 additions & 12 deletions cpp/Ice/greeter/Client.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) ZeroC, Inc.

#include "../../common/Env.h"
#include "Greeter.h"

#include <cstdlib>
Expand All @@ -11,17 +12,6 @@ using namespace std;
int
main(int argc, char* argv[])
{
// Figure out my name.
const char* name = getenv("USER");
if (name == nullptr)
{
name = getenv("USERNAME");
}
if (name == nullptr)
{
name = "masked user";
}

// Create an Ice communicator to initialize the Ice runtime. The CommunicatorHolder is a RAII helper that creates
// the communicator in its constructor and destroys it when it goes out of scope.
const Ice::CommunicatorHolder communicatorHolder{argc, argv};
Expand All @@ -35,7 +25,7 @@ main(int argc, char* argv[])

// Send a request to the remote object and wait synchronously for the response.
// Both the -> and . syntax can be used to make invocations with the proxy.
string greeting = greeter->greet(name);
string greeting = greeter->greet(Env::getUsername());
cout << greeting << endl;

// Send another request to the remote object, this time with greetAsync. greetAsync returns a future immediately.
Expand Down
16 changes: 3 additions & 13 deletions cpp/Ice/middleware/Client.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) ZeroC, Inc.

#include "../../common/Env.h"
#include "Greeter.h"

#include <cstdlib>
Expand All @@ -10,17 +11,6 @@ using namespace std;
int
main(int argc, char* argv[])
{
// Figure out my name.
const char* name = getenv("USER");
if (name == nullptr)
{
name = getenv("USERNAME");
}
if (name == nullptr)
{
name = "masked user";
}

// Create an Ice communicator to initialize the Ice runtime. The CommunicatorHolder is a RAII helper that creates
// the communicator in its constructor and destroys it when it goes out of scope.
const Ice::CommunicatorHolder communicatorHolder{argc, argv};
Expand All @@ -37,7 +27,7 @@ main(int argc, char* argv[])
// Send a request to the remote object with an invalid token in the request context.
try
{
string unexpected = greeter.greet(name, {{"token", "pineapple"}});
string unexpected = greeter.greet(Env::getUsername(), {{"token", "pineapple"}});
cout << "Received unexpected greeting: " << unexpected << endl;
}
catch (const Ice::ObjectNotExistException&)
Expand All @@ -46,7 +36,7 @@ main(int argc, char* argv[])
}

// Send a request with the correct token in the request context.
string greeting = greeter.greet(name, {{"token", validToken}});
string greeting = greeter.greet(Env::getUsername(), {{"token", validToken}});
cout << greeting << endl;

return 0;
Expand Down
Loading

0 comments on commit f3aa6d9

Please sign in to comment.