Skip to content

Commit 9da165f

Browse files
authored
Merge pull request #6559 from xmake-io/conan
Improve conan to support for wasm
2 parents bcc6904 + f550650 commit 9da165f

File tree

3 files changed

+69
-77
lines changed

3 files changed

+69
-77
lines changed

xmake/modules/package/manager/conan/configurations.lua

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,47 @@
1818
-- @file configurations.lua
1919
--
2020

21+
-- get arch for conan
22+
function arch(arch)
23+
local map = {x86_64 = "x86_64",
24+
x64 = "x86_64",
25+
i386 = "x86",
26+
x86 = "x86",
27+
armv7 = "armv7",
28+
["armv7-a"] = "armv7", -- for android, deprecated
29+
["armeabi"] = "armv7", -- for android, removed in ndk r17
30+
["armeabi-v7a"] = "armv7", -- for android
31+
armv7s = "armv7s", -- for iphoneos
32+
arm64 = "armv8", -- for iphoneos
33+
["arm64-v8a"] = "armv8", -- for android
34+
mips = "mips",
35+
mips64 = "mips64",
36+
wasm32 = "wasm"}
37+
return assert(map[arch], "unknown arch(%s)!", arch)
38+
end
39+
40+
-- get os platform for conan
41+
function plat(plat)
42+
local map = {macosx = "Macos",
43+
windows = "Windows",
44+
mingw = "Windows",
45+
linux = "Linux",
46+
cross = "Linux",
47+
iphoneos = "iOS",
48+
android = "Android",
49+
wasm = "Emscripten"}
50+
return assert(map[plat], "unknown plat(%s)!", plat)
51+
end
52+
53+
-- get build type
54+
function build_type(mode)
55+
if mode == "debug" then
56+
return "Debug"
57+
else
58+
return "Release"
59+
end
60+
end
61+
2162
-- get configurations
2263
function main()
2364
return

xmake/modules/package/manager/conan/find_package.lua

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
-- imports
2222
import("core.base.option")
2323
import("core.project.config")
24+
import("package.manager.conan.configurations")
2425

2526
-- get build info file
2627
function _conan_get_buildinfo_file(name, dep_name)
@@ -31,40 +32,12 @@ function _conan_get_buildinfo_file(name, dep_name)
3132
return path.absolute(path.join(config.builddir() or os.tmpdir(), ".conan", name, filename))
3233
end
3334

34-
-- get conan platform
35-
function _conan_get_plat(opt)
36-
local plats = {macosx = "Macos", windows = "Windows", mingw = "Windows", linux = "Linux", cross = "Linux", iphoneos = "iOS", android = "Android"}
37-
return plats[opt.plat]
38-
end
39-
40-
-- get conan architecture
41-
function _conan_get_arch(opt)
42-
local archs = {x86_64 = "x86_64",
43-
x64 = "x86_64",
44-
i386 = "x86",
45-
x86 = "x86",
46-
armv7 = "armv7",
47-
["armv7-a"] = "armv7", -- for android, deprecated
48-
["armeabi"] = "armv7", -- for android, removed in ndk r17
49-
["armeabi-v7a"] = "armv7", -- for android
50-
armv7s = "armv7s", -- for iphoneos
51-
arm64 = "armv8", -- for iphoneos
52-
["arm64-v8a"] = "armv8", -- for android
53-
mips = "mips",
54-
mips64 = "mips64"}
55-
return archs[opt.arch]
56-
end
57-
58-
-- get conan mode
59-
function _conan_get_mode(opt)
60-
return opt.mode == "debug" and "Debug" or "Release"
61-
end
62-
6335
-- get info key
6436
function _conan_get_infokey(opt)
65-
local plat = _conan_get_plat(opt)
66-
local arch = _conan_get_arch(opt)
67-
local mode = _conan_get_mode(opt)
37+
opt = opt or {}
38+
local plat = configurations.plat(opt.plat)
39+
local arch = configurations.arch(opt.arch)
40+
local mode = configurations.build_type(opt.mode)
6841
if plat and arch and mode then
6942
return plat .. "_" .. arch .. "_" .. mode
7043
end

xmake/modules/package/manager/conan/v2/install_package.lua

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ import("core.project.config")
2525
import("core.tool.toolchain")
2626
import("core.platform.platform")
2727
import("lib.detect.find_tool")
28+
import("lib.detect.find_file")
29+
import("detect.sdks.find_emsdk")
2830
import("devel.git")
2931
import("net.fasturl")
32+
import("package.manager.conan.configurations")
3033

3134
-- get build env
3235
function _conan_get_build_env(name, plat)
@@ -110,45 +113,6 @@ function _conan_install_xmake_generator(conan)
110113
end
111114
end
112115

113-
-- get arch
114-
function _conan_get_arch(arch)
115-
local map = {x86_64 = "x86_64",
116-
x64 = "x86_64",
117-
i386 = "x86",
118-
x86 = "x86",
119-
armv7 = "armv7",
120-
["armv7-a"] = "armv7", -- for android, deprecated
121-
["armeabi"] = "armv7", -- for android, removed in ndk r17
122-
["armeabi-v7a"] = "armv7", -- for android
123-
armv7s = "armv7s", -- for iphoneos
124-
arm64 = "armv8", -- for iphoneos
125-
["arm64-v8a"] = "armv8", -- for android
126-
mips = "mips",
127-
mips64 = "mips64"}
128-
return assert(map[arch], "unknown arch(%s)!", arch)
129-
end
130-
131-
-- get os
132-
function _conan_get_os(plat)
133-
local map = {macosx = "Macos",
134-
windows = "Windows",
135-
mingw = "Windows",
136-
linux = "Linux",
137-
cross = "Linux",
138-
iphoneos = "iOS",
139-
android = "Android"}
140-
return assert(map[plat], "unknown os(%s)!", plat)
141-
end
142-
143-
-- get build type
144-
function _conan_get_build_type(mode)
145-
if mode == "debug" then
146-
return "Debug"
147-
else
148-
return "Release"
149-
end
150-
end
151-
152116
-- get compiler version
153117
--
154118
-- https://github.com/conan-io/conan/blob/353c63b16c31c90d370305b5cbb5dc175cf8a443/conan/tools/microsoft/visual.py#L13
@@ -229,6 +193,20 @@ function _conan_generate_compiler_profile(profile, configs, opt)
229193
end
230194
conf = {}
231195
conf["tools.android:ndk_path"] = ndk:config("ndk")
196+
elseif plat == "wasm" then
197+
local emsdk = find_emsdk()
198+
assert(emsdk and emsdk.emscripten, "emscripten not found!")
199+
local emscripten_cmakefile = find_file("Emscripten.cmake", path.join(emsdk.emscripten, "cmake/Modules/Platform"))
200+
assert(emscripten_cmakefile, "Emscripten.cmake not found!")
201+
202+
profile:print("compiler=gcc")
203+
profile:print("compiler.cppstd=gnu17")
204+
profile:print("compiler.libcxx=libstdc++11")
205+
profile:print("compiler.version=12")
206+
207+
conf = {}
208+
conf["tools.build:compiler_executables"] = "{'c':'emcc', 'cpp':'em++', 'ar':'emar', 'ranlib':'emranlib'}"
209+
conf["tools.cmake.cmaketoolchain:user_toolchain"] = "['" ..emscripten_cmakefile .. "']"
232210
else
233211
local program, toolname = platform.tool("cc", plat, arch)
234212
if toolname == "gcc" or toolname == "clang" then
@@ -261,9 +239,9 @@ end
261239
function _conan_generate_build_profile(configs, opt)
262240
local profile = io.open("profile_build.txt", "w")
263241
profile:print("[settings]")
264-
profile:print("arch=%s", _conan_get_arch(os.arch()))
265-
profile:print("build_type=%s", _conan_get_build_type(opt.mode))
266-
profile:print("os=%s", _conan_get_os(os.host()))
242+
profile:print("arch=%s", configurations.arch(os.arch()))
243+
profile:print("build_type=%s", configurations.build_type(opt.mode))
244+
profile:print("os=%s", configurations.plat(os.host()))
267245
_conan_generate_compiler_profile(profile, configs, {plat = os.host(), arch = os.arch()})
268246
profile:close()
269247
end
@@ -272,9 +250,9 @@ end
272250
function _conan_generate_host_profile(configs, opt)
273251
local profile = io.open("profile_host.txt", "w")
274252
profile:print("[settings]")
275-
profile:print("arch=%s", _conan_get_arch(opt.arch))
276-
profile:print("build_type=%s", _conan_get_build_type(opt.mode))
277-
profile:print("os=%s", _conan_get_os(opt.plat))
253+
profile:print("arch=%s", configurations.arch(opt.arch))
254+
profile:print("build_type=%s", configurations.build_type(opt.mode))
255+
profile:print("os=%s", configurations.plat(opt.plat))
278256
_conan_generate_compiler_profile(profile, configs, opt)
279257
profile:close()
280258
end

0 commit comments

Comments
 (0)