Skip to content

Commit

Permalink
强制静态库
Browse files Browse the repository at this point in the history
  • Loading branch information
sjhgithub committed Jun 13, 2024
1 parent 67c7bf8 commit 75efbd6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ build --experimental_cc_shared_library
# cc_shared_library ensures no library is linked statically more than once.
build --experimental_link_static_libraries_once=false

build --copt=-DTF_STATIC_LIBRARY_BUILD
build --copt=-DTFL_STATIC_LIBRARY_BUILD

# Prevent regressions on those two incompatible changes
# TODO: remove those flags when they are flipped in the default Bazel version TF uses.
build --incompatible_enforce_config_setting_visibility
Expand Down
2 changes: 1 addition & 1 deletion bazel_build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SET CC1=win_clang
SET CC2=win_mingw
SET CC3=win_msys
SET ROT=E:/bazel_root
SET ROT=E:/bazel_root_static
SET TGT=//tensorflow:tensorflow.dll //tensorflow:tensorflow.lib //tensorflow:install_headers //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tf_nightly_cpu //tensorflow/lite:tensorflowlite //tensorflow/lite/delegates/flex:tensorflowlite_flex
SET CMD=bazel --output_user_root="%ROT%" build --noincompatible_do_not_split_linking_cmdline --config=windows --config=%CC1% --verbose_failures --config=opt --local_ram_resources=2048

Expand Down
33 changes: 18 additions & 15 deletions tensorflow/c/c_api_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@ limitations under the License.
#ifndef TENSORFLOW_C_C_API_MACROS_H_
#define TENSORFLOW_C_C_API_MACROS_H_

#define TF_STATIC_LIBRARY_BUILD
#ifdef SWIG
#define TF_CAPI_EXPORT
#define TF_CAPI_EXPORT
#elif defined(TF_STATIC_LIBRARY_BUILD)
#define TF_CAPI_EXPORT
#else
#if defined(_WIN32)
#ifdef TF_COMPILE_LIBRARY
#define TF_CAPI_EXPORT __declspec(dllexport)
#else
#define TF_CAPI_EXPORT __declspec(dllimport)
#endif // TF_COMPILE_LIBRARY
#else
#ifdef TF_CAPI_WEAK
#define TF_CAPI_EXPORT \
__attribute__((visibility("default"))) __attribute((weak))
#else
#define TF_CAPI_EXPORT __attribute__((visibility("default")))
#endif // TF_CAPI_WEAK
#endif // _WIN32
#if defined(_WIN32)
#ifdef TF_COMPILE_LIBRARY
#define TF_CAPI_EXPORT __declspec(dllexport)
#else
#define TF_CAPI_EXPORT __declspec(dllimport)
#endif // TF_COMPILE_LIBRARY
#else
#ifdef TF_CAPI_WEAK
#define TF_CAPI_EXPORT \
__attribute__((visibility("default"))) __attribute((weak))
#else
#define TF_CAPI_EXPORT __attribute__((visibility("default")))
#endif // TF_CAPI_WEAK
#endif // _WIN32
#endif // SWIG

// TF_Bool is the C API typedef for unsigned char, while TF_BOOL is
Expand Down
23 changes: 12 additions & 11 deletions tensorflow/lite/core/c/c_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,21 @@ extern "C" {

// Define TFL_CAPI_EXPORT macro to export a function properly with a shared
// library.
#define TFL_STATIC_LIBRARY_BUILD
#ifdef SWIG
#define TFL_CAPI_EXPORT
#define TFL_CAPI_EXPORT
#elif defined(TFL_STATIC_LIBRARY_BUILD)
#define TFL_CAPI_EXPORT
#define TFL_CAPI_EXPORT
#else // not definded TFL_STATIC_LIBRARY_BUILD
#if defined(_WIN32)
#ifdef TFL_COMPILE_LIBRARY
#define TFL_CAPI_EXPORT __declspec(dllexport)
#else
#define TFL_CAPI_EXPORT __declspec(dllimport)
#endif // TFL_COMPILE_LIBRARY
#else
#define TFL_CAPI_EXPORT __attribute__((visibility("default")))
#endif // _WIN32
#if defined(_WIN32)
#ifdef TFL_COMPILE_LIBRARY
#define TFL_CAPI_EXPORT __declspec(dllexport)
#else
#define TFL_CAPI_EXPORT __declspec(dllimport)
#endif // TFL_COMPILE_LIBRARY
#else
#define TFL_CAPI_EXPORT __attribute__((visibility("default")))
#endif // _WIN32
#endif // SWIG

/// Note that new error status values may be added in future in order to
Expand Down

0 comments on commit 75efbd6

Please sign in to comment.