Skip to content

Commit b5b785d

Browse files
committed
Improved DLL tests.
1 parent b507e2a commit b5b785d

File tree

11 files changed

+105
-21
lines changed

11 files changed

+105
-21
lines changed

build_rules/Xt_Build_Instances.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ List<string> FindInstFiles() {
158158
// by construction guid_to_node should only contain projects that
159159
// the root project references or depends on transitively
160160
foreach(Node node in guid_to_node.Values) {
161+
//TODO: each project should just write the list of .xti files to a cache file
162+
//so we don't have to reconstruct it from the header cache file here
161163
string[] props = {"Xt_InstFilePath_FromHeader", "Xt_InstFilePath", "Xt_HeaderCachePath", "Xt_InstSuffix"};
162164
string[] values = props.Select(prop => node.project.GetPropertyValue(prop)).ToArray();
163165
if(values.Any(value => value == "")) continue;

src/xt_inst_gen/xt_comp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ int find_exported_templates(
175175
return true;
176176
});
177177

178-
fmt::print("finished parsing\n");
178+
//fmt::print("finished parsing\n");
179179
return 0;
180180
}
181181

src/xt_inst_gen/xt_inst_file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ struct xt_inst_file_reader_writer
251251
it = it_end + 1;
252252
}
253253

254-
if (version != xt_inst_file::current_version) {
254+
if (!ret.contents.empty() && version != xt_inst_file::current_version) {
255255
fmt::print("note: version mismatch, ignoring file contents\n");
256256
ret = {};
257257
}

src/xt_inst_gen/xt_link.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ int do_link(int argc, const char *argv[]) {
416416

417417
for (auto exported_symbol : inst_file.get_exported_symbols()) {
418418
bool got_one = false;
419+
// todo: use a trie or binary search or something to speed up the prefix search
419420
remove_if_and_erase(remaining_unresolved_names, [&](auto & p) {
420421
if (string_starts_with(p.to_match, exported_symbol.get_name())) {
421422
std::string_view to_inst = p.to_inst;

test/dll/CMakeLists.txt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,55 @@ project(test_dll LANGUAGES CXX)
33

44
find_package(export_template REQUIRED)
55

6+
# == A ==
67
add_executable(A
78
A_main.cpp
89
B_loader.cpp
910
)
11+
add_dependencies(A B) # don't link with B
12+
target_link_libraries(A C D)
1013

11-
# TODO:
12-
# B is meant to be loaded at runtime by A so
13-
# A should not link with B but B should build before A
14-
# so in VS, B should be a dependency of A but should not be referenced by it
15-
target_link_libraries(A B C D)
16-
14+
# == B ==
1715
add_library(B SHARED
1816
B.cpp
1917
B.h
2018
)
21-
2219
target_compile_definitions(B
2320
PRIVATE B_DLL_EXPORT
2421
)
22+
target_link_libraries(B C)
23+
24+
# == C ==
25+
add_library(C STATIC
26+
C.cpp
27+
C.h
28+
)
2529

30+
# == D ==
2631
add_library(D SHARED
2732
D.cpp
2833
D.h
2934
)
30-
3135
target_compile_definitions(D
3236
PRIVATE D_DLL_EXPORT
3337
INTERFACE D_DLL_IMPORT
3438
)
35-
36-
target_link_libraries(B C)
37-
38-
add_library(C STATIC
39-
C.cpp
40-
C.h
39+
target_link_libraries(D E)
40+
41+
# == E ==
42+
add_library(E SHARED
43+
E.cpp
44+
E.h
45+
E1.cpp
46+
E1.h
47+
)
48+
target_compile_definitions(E
49+
PRIVATE E_DLL_EXPORT
50+
INTERFACE E_DLL_IMPORT
4151
)
4252

43-
set_property(TARGET A B C PROPERTY CXX_STANDARD 17)
53+
set_property(TARGET A B C D E PROPERTY CXX_STANDARD 17)
4454

45-
target_export_template(A B C D)
55+
target_export_template(A B C D E)
4656

4757
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT A)

test/dll/D.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "D.h"
22
#include <D.xti>
33

4+
#include "E.h"
5+
46
#include <stdio.h>
57

68
namespace D {
@@ -32,12 +34,15 @@ namespace D {
3234
void D1<T>::D4<U>::foo() {
3335
printf("%s\n", __FUNCSIG__);
3436
}
37+
38+
__declspec(dllexport) void exported_function() {
39+
E::foo<int>();
40+
}
3541

3642
template<typename T>
3743
void D2::foo() {
3844
printf("%s\n", __FUNCSIG__);
45+
exported_function();
3946
}
40-
41-
__declspec(dllexport) void dummy_func() {}
4247

4348
} // namespace D

test/dll/E.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "E.h"
2+
#include <E.xti>
3+
4+
#include "E1.h"
5+
6+
#include <stdio.h>
7+
8+
namespace E {
9+
10+
__declspec(dllexport) void exported_function() {
11+
E1::foo<bool>();
12+
}
13+
14+
template <typename T>
15+
void foo() {
16+
printf("%s\n", __FUNCSIG__);
17+
exported_function();
18+
}
19+
20+
} // namespace E

test/dll/E.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#if defined(E_DLL_EXPORT)
4+
#define E_DLL_SPEC __declspec(dllexport)
5+
#elif defined(E_DLL_IMPORT)
6+
#define E_DLL_SPEC __declspec(dllimport)
7+
#else
8+
#define E_DLL_SPEC
9+
#endif
10+
11+
#pragma warning (push)
12+
#pragma warning (disable:5030)
13+
namespace E
14+
{
15+
template <typename T>
16+
[[export_template]] E_DLL_SPEC void foo();
17+
} // namespace E
18+
#pragma warning (pop)
19+
20+
#undef E_DLL_SPEC

test/dll/E1.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "E1.h"
2+
#include <E1.xti>
3+
4+
#include <stdio.h>
5+
6+
namespace E1
7+
{
8+
9+
template <typename T>
10+
void foo() {
11+
printf("%s\n", __FUNCSIG__);
12+
}
13+
14+
} // namespace E1

test/dll/E1.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#pragma warning (push)
4+
#pragma warning (disable:5030)
5+
namespace E1
6+
{
7+
8+
template<typename T>
9+
[[export_template]] void foo();
10+
11+
} // namespace E1
12+
#pragma warning (pop)

0 commit comments

Comments
 (0)