From e2efb5d41c91d0d1818f8f85a40726fa80537f23 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Mon, 14 Jun 2021 15:31:44 -0700 Subject: [PATCH] Fix Windows shared_library builds To make shared_library builds work on Windows with MSVS 2019, this commit: - Silences a useless warning about a private member in dll-exported Status class. - Exports the File class used by packager.exe - Removes the explicit File dependency in packager.exe in favor of libpackager, now that File is exported - Add missing defines in packager.exe and packager_test.exe that instruct the linker to import Status and File from the library Closes #318 (shared_library builds on Windows) Issue #336 (progress toward GitHub Actions workflow to replace Travis and Appveyor, where we need to build and test shared_library on all platforms) b/190743862 (internal; tracking replacement of Travis) Change-Id: I091f1655d88d36f353f7df497101eef17729eefe --- packager/common.gypi | 2 ++ packager/file/file.gyp | 8 ++++++++ packager/file/file.h | 3 ++- packager/packager.gyp | 13 ++++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/packager/common.gypi b/packager/common.gypi index 07181e51ea..04824c2781 100644 --- a/packager/common.gypi +++ b/packager/common.gypi @@ -52,6 +52,8 @@ # the current code page. It typically happens when compiling # the code in CJK environment if there is non-ASCII characters # in the file. + 4251, # Warnings about private std::string in Status in a shared + # library config on Windows. ], }, { # We do not have control over non-shaka code. Disable some warnings to diff --git a/packager/file/file.gyp b/packager/file/file.gyp index 2c280a66a7..9a842ee707 100644 --- a/packager/file/file.gyp +++ b/packager/file/file.gyp @@ -43,6 +43,14 @@ '../third_party/curl/curl.gyp:libcurl', '../version/version.gyp:version', ], + 'conditions': [ + ['libpackager_type == "shared_library"', { + 'defines': [ + 'SHARED_LIBRARY_BUILD', + 'SHAKA_IMPLEMENTATION', + ], + }], + ], }, { 'target_name': 'file_unittest', diff --git a/packager/file/file.h b/packager/file/file.h index 7854cb768c..5c2f42b57e 100644 --- a/packager/file/file.h +++ b/packager/file/file.h @@ -13,6 +13,7 @@ #include "packager/base/macros.h" #include "packager/file/public/buffer_callback_params.h" +#include "packager/status.h" namespace shaka { @@ -24,7 +25,7 @@ extern const char* kHttpFilePrefix; const int64_t kWholeFile = -1; /// Define an abstract file interface. -class File { +class SHAKA_EXPORT File { public: /// Open the specified file. /// This is a file factory method, it opens a proper file automatically diff --git a/packager/packager.gyp b/packager/packager.gyp index 8b11f0bf2c..c82f38aef4 100644 --- a/packager/packager.gyp +++ b/packager/packager.gyp @@ -100,12 +100,16 @@ ], 'dependencies': [ 'base/base.gyp:base', - 'file/file.gyp:file', 'libpackager', 'third_party/gflags/gflags.gyp:gflags', 'tools/license_notice.gyp:license_notice', ], 'conditions': [ + ['libpackager_type == "shared_library"', { + 'defines': [ + 'SHARED_LIBRARY_BUILD', + ], + }], ['profiling==1', { 'dependencies': [ 'base/allocator/allocator.gyp:allocator', @@ -135,6 +139,13 @@ 'sources': [ 'packager_test.cc', ], + 'conditions': [ + ['libpackager_type == "shared_library"', { + 'defines': [ + 'SHARED_LIBRARY_BUILD', + ], + }], + ], 'dependencies': [ 'libpackager', 'testing/gmock.gyp:gmock',