Skip to content

Commit 191ae30

Browse files
authored
adapt macos platform (#3)
* adapt macos platform mcpp-community/OpenOrg#1 Signed-off-by: SPeak Shen <speakshen@163.com> * chagne module-partition to json-module, but add `mcpplibs.llmapi`prefix to avoid module conflict issue --------- Signed-off-by: SPeak Shen <speakshen@163.com>
1 parent 72cdf18 commit 191ae30

File tree

6 files changed

+33
-25
lines changed

6 files changed

+33
-25
lines changed

examples/xmake.lua

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
target("hello_mcpp")
2-
set_kind("binary")
3-
add_files("hello_mcpp.cpp")
4-
add_deps("llmapi")
1+
-- TODO: fix build on macOS (12.3) libc++/println issue
2+
if not is_host("macosx") then
3+
-- xmake f --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20
4+
--add_ldflags("-L/opt/homebrew/opt/llvm@20/lib/c++ -L/opt/homebrew/opt/llvm@20/lib/unwind -lunwind")
55

6-
target("basic")
7-
set_kind("binary")
8-
add_files("basic.cpp")
9-
add_deps("llmapi")
6+
target("hello_mcpp")
7+
set_kind("binary")
8+
add_files("hello_mcpp.cpp")
9+
add_deps("llmapi")
10+
11+
target("basic")
12+
set_kind("binary")
13+
add_files("basic.cpp")
14+
add_deps("llmapi")
15+
16+
target("chat")
17+
set_kind("binary")
18+
add_files("chat.cpp")
19+
add_deps("llmapi")
20+
end
1021

11-
target("chat")
12-
set_kind("binary")
13-
add_files("chat.cpp")
14-
add_deps("llmapi")
1522

1623
includes("c")

src/json/json.cppm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module;
22

33
#include <json.hpp>
44

5-
export module nlohmann.json;
5+
//export module nlohmann.json; // workaround for module name conflict in some build systems
6+
export module mcpplibs.llmapi.nlohmann.json;
67

78
export namespace nlohmann {
89
using ::nlohmann::adl_serializer;

src/llmapi.cppm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export module mcpplibs.llmapi;
22

3-
import std;
3+
export import :url;
4+
export import :openai;
45

5-
import nlohmann.json;
6+
import std;
67

7-
import mcpplibs.llmapi.url;
8-
import mcpplibs.llmapi.openai;
8+
import mcpplibs.llmapi.nlohmann.json;
99

1010
namespace mcpplibs::llmapi {
1111
export using OpenAI = openai::OpenAI;

src/openai.cppm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ module;
22

33
#include <curl/curl.h>
44

5-
export module mcpplibs.llmapi.openai;
5+
export module mcpplibs.llmapi:openai;
6+
7+
export import :url;
68

79
import std;
8-
import nlohmann.json;
910

10-
import mcpplibs.llmapi.url;
11+
import mcpplibs.llmapi.nlohmann.json;
1112

1213
export namespace mcpplibs::llmapi::openai {
1314

src/url.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export module mcpplibs.llmapi.url;
1+
export module mcpplibs.llmapi:url;
22

33
import std;
44

xmake.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,23 @@ add_requires("libcurl 8.11.0")
77
set_languages("c++23")
88

99
target("llmapi")
10-
set_kind("static")
10+
set_kind("moduleonly")
1111
add_files("src/*.cppm", { public = true, install = true })
12-
add_packages("libcurl")
12+
add_packages("libcurl", { public = true })
1313
--add_deps("__nlohmann_json")
1414
add_includedirs("src/json")
1515
add_headerfiles("src/json/json.hpp")
1616
add_files("src/json/json.cppm", { public = true })
1717
-- relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
1818
-- ld: failed to set dynamic section sizes: bad value
1919
-- collect2: error: ld returned 1 exit status
20-
add_cxxflags("-fPIC")
20+
--add_cxxflags("-fPIC")
2121

2222
target("llmapi_c")
2323
--set_kind("shared")
2424
set_kind("static")
2525
add_files("src/c/llmapi.cpp")
2626
add_deps("llmapi")
27-
add_packages("libcurl")
2827
add_includedirs("include", { public = true })
2928
add_headerfiles("include/llmapi.h")
3029

0 commit comments

Comments
 (0)