Skip to content

Commit a68eff4

Browse files
authored
Merge pull request #6435 from Arthapz/fix-namespaced-module-dep
(C++ modules support) fix _patch_sourcebatch when target and deps is in the same namespace
2 parents 29ee4b4 + bb8609c commit a68eff4

File tree

15 files changed

+158
-1
lines changed

15 files changed

+158
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export module hello;
2+
3+
export namespace hello {
4+
extern int data__;
5+
void say_hello();
6+
7+
class say {
8+
public:
9+
say(int data);
10+
void hello();
11+
private:
12+
int data_;
13+
};
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module;
2+
#include <iostream>
3+
4+
module hello;
5+
import mod;
6+
7+
void inner() {
8+
std::cout << "hello world! data: "
9+
<< mod::foo() << std::endl;
10+
}
11+
12+
namespace hello {
13+
int data__;
14+
void say_hello() { ::inner(); }
15+
16+
say::say(int data) : data_{data} {
17+
}
18+
19+
void say::hello() {
20+
hello::data__ = data_;
21+
::inner();
22+
}
23+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import hello;
2+
3+
int main() {
4+
hello::data__ = 123;
5+
hello::say_hello();
6+
hello::say(sizeof(hello::say)).hello();
7+
return 0;
8+
}
9+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export module mod;
2+
3+
export namespace mod {
4+
int foo();
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module mod;
2+
import hello;
3+
4+
namespace mod {
5+
int foo() {
6+
return hello::data__;
7+
}
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
inherit(".test_base")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
add_rules("mode.release", "mode.debug")
2+
set_languages("c++20")
3+
4+
namespace("foo", function()
5+
target("dep")
6+
set_kind("static")
7+
add_files("src/hello.mpp", "src/mod.mpp", {public = true})
8+
add_files("src/hello_impl.cpp", "src/mod_impl.cpp")
9+
10+
target("binary")
11+
set_kind("binary")
12+
add_files("src/main.cpp")
13+
add_deps("dep")
14+
end)
15+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export module hello;
2+
3+
export namespace hello {
4+
extern int data__;
5+
void say_hello();
6+
7+
class say {
8+
public:
9+
say(int data);
10+
void hello();
11+
private:
12+
int data_;
13+
};
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module;
2+
#include <iostream>
3+
4+
module hello;
5+
import mod;
6+
7+
void inner() {
8+
std::cout << "hello world! data: "
9+
<< mod::foo() << std::endl;
10+
}
11+
12+
namespace hello {
13+
int data__;
14+
void say_hello() { ::inner(); }
15+
16+
say::say(int data) : data_{data} {
17+
}
18+
19+
void say::hello() {
20+
hello::data__ = data_;
21+
::inner();
22+
}
23+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import hello;
2+
3+
int main() {
4+
hello::data__ = 123;
5+
hello::say_hello();
6+
hello::say(sizeof(hello::say)).hello();
7+
return 0;
8+
}
9+

0 commit comments

Comments
 (0)