Skip to content

Commit

Permalink
Add MS Windows support (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
astrocox authored Feb 25, 2024
1 parent 21957d4 commit 0c9f75d
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 19 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ jobs:
cc: "clang",
cxx: "clang++"
}
- {
name: "Windows Latest MSVC",
os: windows-latest,
build_type: "Release",
cc: "cl",
cxx: "cl"
}

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -67,6 +74,15 @@ jobs:
minio --version
clang-format --version
- name: Install dependencies if Windows
shell: bash
if: startsWith(matrix.config.os, 'windows')
run: |
choco install -y --no-progress cmake wget
wget --quiet https://dl.min.io/server/minio/release/windows-amd64/minio.exe
chmod +x minio.exe
cmake --version
- name: Install vcpkg
shell: bash
run: |
Expand All @@ -78,7 +94,8 @@ jobs:
./vcpkg-master/vcpkg integrate install
./vcpkg-master/vcpkg install
- name: C++ Style check
- name: C++ Style check if not Windows
if: ${{ !startsWith(matrix.config.os, 'windows') }}
shell: bash
run: |
./check-style.sh
Expand All @@ -105,6 +122,16 @@ jobs:
MINIO_CI_CD=true minio server test-xl/{1...4}/ &
sleep 10
- name: Start MinIO server if Windows
if: startsWith(matrix.config.os, 'windows')
shell: bash
run: |
mkdir -p ~/.minio/certs
cp ./tests/public.crt ./tests/private.key ~/.minio/certs/
certutil -addstore -f "ROOT" ./tests/public.crt
MINIO_CI_CD=true ./minio.exe server test-xl/{1...4}/ &
sleep 10
- name: Run tests if Ubuntu
if: startsWith(matrix.config.name, 'Ubuntu_Latest_GCC')
run: |
Expand All @@ -115,6 +142,12 @@ jobs:
run: |
SERVER_ENDPOINT=localhost:9000 ACCESS_KEY=minioadmin SECRET_KEY=minioadmin ./build/tests/tests
- name: Run tests if Windows
shell: bash
if: startsWith(matrix.config.os, 'windows')
run: |
SERVER_ENDPOINT=localhost:9000 ACCESS_KEY=minioadmin SECRET_KEY=minioadmin ENABLE_HTTPS=1 ./build/tests/Release/tests.exe
- name: Run CMake test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ docs/*svg
docs/*map
docs/*md5
include/config.h
.idea/
cmake-build*
vcpkg-master.zip
vcpkg-master/

10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0091 NEW)

project(miniocpp)

cmake_minimum_required(VERSION 3.10)

include(GNUInstallDirs)

macro(set_globals)
Expand Down Expand Up @@ -80,6 +80,12 @@ ELSE(OPENSSL_FOUND)
MESSAGE(FATAL_ERROR "Could not find the OpenSSL library and development files.")
ENDIF(OPENSSL_FOUND)

if(WIN32)
list(APPEND requiredlibs wsock32)
list(APPEND requiredlibs ws2_32)
list(APPEND requiredlibs ZLIB::ZLIB)
endif()

message(STATUS "Found required libs: ${requiredlibs}")

INCLUDE (CheckIncludeFiles)
Expand Down
4 changes: 4 additions & 0 deletions include/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
#ifndef _MINIO_HTTP_H
#define _MINIO_HTTP_H

#ifdef _WIN32
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#endif

#include <curlpp/Easy.hpp>
#include <curlpp/Multi.hpp>
Expand Down
5 changes: 5 additions & 0 deletions include/providers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
#define _MINIO_CREDS_PROVIDERS_H

#include <INIReader.h>
#ifdef _WIN32
#include <ws2def.h>
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#endif
#include <sys/types.h>

#include <fstream>
Expand Down
21 changes: 13 additions & 8 deletions include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
#ifndef _MINIO_UTILS_H
#define _MINIO_UTILS_H

#include <arpa/inet.h>
#ifndef _WIN32
#include <pwd.h>
#endif

#include <openssl/buffer.h>
#include <openssl/evp.h>
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
#include <zlib.h>

#include <array>
#include <chrono>
#include <cmath>
#include <cstring>
#include <ctime>
#include <curlpp/cURLpp.hpp>
#include <iomanip>
#include <iostream>
Expand All @@ -41,9 +44,8 @@
namespace minio {
namespace utils {
inline constexpr unsigned int kMaxMultipartCount = 10000; // 10000 parts
inline constexpr unsigned long kMaxObjectSize =
5L * 1024 * 1024 * 1024 * 1024; // 5TiB
inline constexpr unsigned long kMaxPartSize = 5L * 1024 * 1024 * 1024; // 5GiB
inline constexpr unsigned long long kMaxObjectSize = 5497558138880ULL; // 5TiB
inline constexpr unsigned long long kMaxPartSize = 5368709120UL; // 5GiB
inline constexpr unsigned int kMinPartSize = 5 * 1024 * 1024; // 5MiB

bool GetEnv(std::string& var, const char* name);
Expand Down Expand Up @@ -122,7 +124,7 @@ class Time {
public:
Time() {}

Time(std::time_t tv_sec, suseconds_t tv_usec, bool utc) {
Time(std::time_t tv_sec, long tv_usec, bool utc) {
this->tv_.tv_sec = tv_sec;
this->tv_.tv_usec = tv_usec;
this->utc_ = utc;
Expand All @@ -146,7 +148,10 @@ class Time {

static Time Now() {
Time t;
gettimeofday(&t.tv_, NULL);
auto usec = std::chrono::system_clock::now().time_since_epoch() /
std::chrono::microseconds(1);
t.tv_.tv_sec = static_cast<long>(usec / 1000000);
t.tv_.tv_usec = static_cast<long>(usec % 1000000);
return t;
}

Expand Down
2 changes: 1 addition & 1 deletion src/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ minio::s3::DownloadObjectResponse minio::s3::Client::DownloadObject(

std::string temp_filename =
args.filename + "." + curlpp::escape(etag) + ".part.minio";
std::ofstream fout(temp_filename, fout.trunc | fout.out);
std::ofstream fout(temp_filename, std::ios::trunc | std::ios::out);
if (!fout.is_open()) {
return error::Error("unable to open file " + temp_filename);
}
Expand Down
23 changes: 21 additions & 2 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ const std::regex IPV4_REGEX(
"^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
"(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$");

#ifdef _WIN32
// strptime is defined here because it's not available on Windows.
static char* strptime(const char* s, const char* f, struct tm* tm) {
std::istringstream input(s);
input.imbue(std::locale(setlocale(LC_ALL, nullptr)));
input >> std::get_time(tm, f);
if (input.fail()) {
return nullptr;
}
return (char*)(s + input.tellg());
}
#endif

bool minio::utils::GetEnv(std::string& var, const char* name) {
if (const char* value = std::getenv(name)) {
var = value;
Expand All @@ -38,8 +51,13 @@ bool minio::utils::GetEnv(std::string& var, const char* name) {

std::string minio::utils::GetHomeDir() {
std::string home;
#ifdef _WIN32
GetEnv(home, "USERPROFILE");
return home;
#else
if (GetEnv(home, "HOME")) return home;
return getpwuid(getuid())->pw_dir;
#endif
}

std::string minio::utils::Printable(std::string s) {
Expand Down Expand Up @@ -258,7 +276,8 @@ std::string minio::utils::FormatTime(const std::tm* time, const char* format) {

std::tm* minio::utils::Time::ToUTC() {
std::tm* t = new std::tm;
*t = utc_ ? *std::localtime(&tv_.tv_sec) : *std::gmtime(&tv_.tv_sec);
const time_t secs = tv_.tv_sec;
*t = utc_ ? *std::localtime(&secs) : *std::gmtime(&secs);
return t;
}

Expand Down Expand Up @@ -336,7 +355,7 @@ minio::utils::Time minio::utils::Time::FromISO8601UTC(const char* value) {
char* rv = strptime(value, "%Y-%m-%dT%H:%M:%S", &t);
unsigned long ul = 0;
sscanf(rv, ".%lu", &ul);
suseconds_t tv_usec = (suseconds_t)ul;
long tv_usec = (long)ul;
std::time_t time = std::mktime(&t);
return Time(time, tv_usec, true);
}
Expand Down
8 changes: 3 additions & 5 deletions tests/tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <unistd.h>

#include <chrono>
#include <random>
#include <thread>

Expand All @@ -39,7 +37,7 @@ class RandomBuf : public std::streambuf {
int_type underflow() override {
if (size_ == 0) return EOF;

size_t size = std::min(size_, buf_.size());
size_t size = std::min<size_t>(size_, buf_.size());
setg(&buf_[0], &buf_[0], &buf_[size]);
for (size_t i = 0; i < size; ++i) buf_[i] = charset[pick(rg)];
size_ -= size;
Expand Down Expand Up @@ -623,7 +621,7 @@ class Tests {
}
}};

usleep(10 * 1000); // sleep for 10ms.
std::this_thread::sleep_for(std::chrono::milliseconds(10));

std::string object_name = RandObjectName();
try {
Expand Down

0 comments on commit 0c9f75d

Please sign in to comment.