Skip to content

Commit

Permalink
Fixed Windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Sep 29, 2024
1 parent 8b791ca commit 5be6a0f
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 06
CACHE_VER: 09
TZ: "Etc/UTC"
VERBOSE: no

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gem-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 08
CACHE_VER: 09
DEBIAN_FRONTEND: "noninteractive"
TZ: "Etc/UTC"
# show cmake output
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 08
CACHE_VER: 09
VERBOSE: no

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 06
CACHE_VER: 09
DEBIAN_FRONTEND: "noninteractive"
TZ: "Etc/UTC"
# show cmake output (yes/no)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-msys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ concurrency:
cancel-in-progress: true

env:
CACHE_VER: 04
CACHE_VER: 09
VERBOSE: no

jobs:
Expand Down
4 changes: 3 additions & 1 deletion lib/tebako/packager/patch_libraries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ class << self
DARWIN_DEP_LIBS_2 = ["glog", "gflags", "brotlienc", "brotlidec", "brotlicommon", "fmt"].freeze
# rubocop:enable Style/WordArray

LIBTEBAKOFS = "-Wl,--push-state,--whole-archive -l:libtebako-fs.a -Wl,--pop-state"

COMMON_LINUX_LIBRARIES = [
"-l:libtebako-fs.a", "-l:libdwarfs-wr.a", "-l:libdwarfs.a", "LIBCOMPRESSION",
LIBTEBAKOFS, "-l:libdwarfs-wr.a", "-l:libdwarfs.a", "LIBCOMPRESSION",
"-l:libfolly.a", "-l:libfsst.a", "-l:libmetadata_thrift.a", "-l:libthrift_light.a",
"-l:libxxhash.a", "-l:libfmt.a", "-l:libdouble-conversion.a", "-l:libglog.a",
"-l:libgflags.a", "-l:libevent.a"
Expand Down
158 changes: 79 additions & 79 deletions src/tebako-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@
#include <sys/stat.h>
#include <fcntl.h>


#include <string>
#include <cstdint>
#include <vector>
#include <stdexcept>
#include <tuple>

#ifdef _WIN32
#include <winsock2.h>
#include <windows.h>
#include <winsock2.h>
#include <windows.h>
#endif


#include <tebako/tebako-config.h>
#include <tebako/tebako-io.h>

Expand All @@ -58,87 +56,89 @@

static int running_miniruby = 0;

extern "C" int tebako_main(int* argc, char*** argv) {
int ret = -1, fsret = -1;
char** new_argv = NULL;
char* argv_memory = NULL;

if (strstr((*argv)[0], "miniruby") != NULL) {
// Ruby build script is designed in such a way that this patch is also applied towards miniruby
// Just pass through in such case
ret = 0;
running_miniruby = -1;
}
else {
try {
fsret = load_fs(&gfsData[0],
gfsSize,
tebako::fs_log_level,
NULL /* cachesize*/,
NULL /* workers */,
NULL /* mlock */,
NULL /* decompress_ratio*/,
NULL /* image_offset */
);

if (fsret == 0) {
if ((*argc > 1) && strcmp((*argv)[1], "--tebako-extract")==0) {
ret = tebako::build_arguments_for_extract(argc, argv, tebako::fs_mount_point);
}
else {
auto [mount_args, parsed_argv] = tebako::parse_arguments(*argc, *argv);
std::tie(*argc, *argv) = tebako::build_arguments(parsed_argv, tebako::fs_mount_point, tebako::fs_entry_point);
ret = 0;
}
}
atexit(drop_fs);
}

catch (std::exception e) {
printf("Failed to process command line: %s\n", e.what());
}

if (!tebako_is_running_miniruby()) {
if (getcwd(tebako::original_cwd, sizeof(tebako::original_cwd)) == NULL) {
printf("Failed to get current directory: %s\n", strerror(errno));
return -1;
}

if (tebako::needs_cwd) {
if (tebako_chdir(tebako::package_cwd) != 0) {
printf("Failed to chdir to '%s' : %s\n", tebako::package_cwd, strerror(errno));
ret = -1;
}
}
}

if (ret != 0) {
try {
printf("Tebako initialization failed\n");
if (new_argv) delete new_argv;
if (argv_memory) delete argv_memory;
if (fsret == 0) {
drop_fs();
}
}
catch (...) {
// Nested error, no recovery :(
}
}
}
return ret;
extern "C" int tebako_main(int* argc, char*** argv)
{
int ret = -1, fsret = -1;
char** new_argv = nullptr;
char* argv_memory = nullptr;

if (strstr((*argv)[0], "miniruby") != nullptr) {
// Ruby build script is designed in such a way that this patch is also applied towards miniruby
// Just pass through in such case
ret = 0;
running_miniruby = -1;
}
else {
try {
fsret = load_fs(&gfsData[0], gfsSize, tebako::fs_log_level, nullptr /* cachesize*/, nullptr /* workers */,
nullptr /* mlock */, nullptr /* decompress_ratio*/, nullptr /* image_offset */
);

if (fsret == 0) {
if ((*argc > 1) && strcmp((*argv)[1], "--tebako-extract") == 0) {
ret = tebako::build_arguments_for_extract(argc, argv, tebako::fs_mount_point);
}
else {
auto [mount_args, parsed_argv] = tebako::parse_arguments(*argc, *argv);
std::tie(*argc, *argv) = tebako::build_arguments(parsed_argv, tebako::fs_mount_point, tebako::fs_entry_point);
ret = 0;
}
}
atexit(drop_fs);
}

catch (std::exception e) {
printf("Failed to process command line: %s\n", e.what());
}

if (getcwd(tebako::original_cwd, sizeof(tebako::original_cwd)) == nullptr) {
printf("Failed to get current directory: %s\n", strerror(errno));
ret = -1;
}

if (tebako::needs_cwd) {
if (tebako_chdir(tebako::package_cwd) != 0) {
printf("Failed to chdir to '%s' : %s\n", tebako::package_cwd, strerror(errno));
ret = -1;
}
}
}

if (ret != 0) {
try {
printf("Tebako initialization failed\n");
if (new_argv) {
delete new_argv;
new_argv = nullptr;
}
if (argv_memory) {
delete argv_memory;
argv_memory = nullptr;
}
if (fsret == 0) {
drop_fs();
}
}
catch (...) {
// Nested error, no recovery :(
}
}
return ret;
}

extern "C" const char* tebako_mount_point(void) {
return tebako::fs_mount_point;
extern "C" const char* tebako_mount_point(void)
{
return tebako::fs_mount_point;
}

extern "C" const char* tebako_original_pwd(void) {
return tebako::original_cwd;
extern "C" const char* tebako_original_pwd(void)
{
return tebako::original_cwd;
}

extern "C" int tebako_is_running_miniruby(void) {
return running_miniruby;
extern "C" int tebako_is_running_miniruby(void)
{
return running_miniruby;
}

#ifdef RB_W32_PRE_33
Expand Down

0 comments on commit 5be6a0f

Please sign in to comment.