Skip to content

Commit e95d590

Browse files
committed
Add Windows stub in seperate file.
1 parent c76744e commit e95d590

3 files changed

Lines changed: 47 additions & 18 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* Copyright 2025 The TensorFlow Authors. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
16+
#ifdef _WIN32
17+
18+
#include "tensorflow/c/c_api.h"
19+
#include "tensorflow/c/c_api_experimental.h"
20+
21+
// On Windows, the TensorFlow C library currently does not export TFE_GetServerDef.
22+
// Provide a local stub so that the JNI native library can link successfully.
23+
// The stub simply sets the status to TF_UNIMPLEMENTED and returns an empty
24+
// TF_Buffer.
25+
extern "C" TF_Buffer* TFE_GetServerDef(const char* text_proto, TF_Status* status) {
26+
if (status != nullptr) {
27+
TF_SetStatus(status, TF_UNIMPLEMENTED,
28+
"TFE_GetServerDef is not available in the Windows build of libtensorflow.");
29+
}
30+
// Allocate an empty TF_Buffer on the heap so that callers can still call
31+
// TF_DeleteBuffer() on the returned pointer safely.
32+
TF_Buffer* buf = static_cast<TF_Buffer*>(malloc(sizeof(TF_Buffer)));
33+
if (buf != nullptr) {
34+
buf->data = nullptr;
35+
buf->length = 0;
36+
buf->data_deallocator = nullptr;
37+
}
38+
return buf;
39+
}
40+
41+
#endif // _WIN32

tensorflow-core/tensorflow-core-native/src/main/native/org/tensorflow/internal/c_api/tfj_graph.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2024 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2025 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -30,4 +30,9 @@ TF_CAPI_EXPORT extern void TFJ_UnmapOperationName(TF_Graph* g, TF_Operation* ope
3030

3131
#include "tfj_graph_impl.cc" // include CC file in its header to compile it with JavaCPP
3232

33+
#ifdef _WIN32
34+
// Ensure the Windows-specific stub for TFE_GetServerDef is linked.
35+
#include "tfe_serverdef_stub.cc"
36+
#endif
37+
3338
#endif // TENSORFLOW_JAVA_GRAPH_H_

tensorflow-core/tensorflow-core-native/src/main/native/org/tensorflow/internal/c_api/tfj_graph_impl.cc

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,4 @@ void TFJ_UnmapOperationName(TF_Graph* g, TF_Operation* operation) {
3434
TFJ_GraphId TFJ_GetGraphId(const TF_Graph* g) { return NULL; }
3535
void TFJ_UnmapOperationName(TF_Graph* g, TF_Operation* operation) {}
3636

37-
// Provide stub for missing TFE_GetServerDef symbol on Windows.
38-
#include "tensorflow/c/c_api.h"
39-
#include "tensorflow/c/c_api_experimental.h"
40-
extern "C" TF_Buffer* TFE_GetServerDef(const char* text_proto, TF_Status* status) {
41-
if (status != nullptr) {
42-
TF_SetStatus(status, TF_UNIMPLEMENTED,
43-
"TFE_GetServerDef is not supported on Windows build of libtensorflow.");
44-
}
45-
TF_Buffer* buf = static_cast<TF_Buffer*>(malloc(sizeof(TF_Buffer)));
46-
if (buf != nullptr) {
47-
buf->data = nullptr;
48-
buf->length = 0;
49-
buf->data_deallocator = nullptr;
50-
}
51-
return buf;
52-
}
53-
5437
#endif // #indef _WIN32

0 commit comments

Comments
 (0)