Skip to content

Commit

Permalink
dispenso: add package (#2996)
Browse files Browse the repository at this point in the history
* dispenso: add package

* fix test

* fix syslinks

* patch syslinks
  • Loading branch information
star-hengxing authored Dec 27, 2023
1 parent 32abec1 commit 095e769
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 12 deletions.
59 changes: 47 additions & 12 deletions packages/c/concurrentqueue/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,59 @@
package("concurrentqueue")

set_homepage("https://github.com/cameron314/concurrentqueue")
set_description("An industrial-strength lock-free queue for C++.")
set_description("A fast multi-producer, multi-consumer lock-free concurrent queue for C++11")
set_license("BSD")

add_urls("https://github.com/cameron314/concurrentqueue/archive/refs/tags/$(version).tar.gz",
"https://github.com/cameron314/concurrentqueue.git")

add_versions("v1.0.4", "87fbc9884d60d0d4bf3462c18f4c0ee0a9311d0519341cac7cbd361c885e5281")

add_configs("c_api", {description = "Build C API", default = false, type = "boolean"})

add_deps("cmake")

add_urls("https://github.com/cameron314/concurrentqueue.git")
add_includedirs("include", "include/concurrentqueue/moodycamel")

on_load(function (package)
if not package:config("c_api") then
package:set("kind", "library", {headeronly = true})
end
end)

on_install(function (package)
os.cp("*.h", package:installdir("include/concurrentqueue"))
local configs = {}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
import("package.tools.cmake").install(package, configs)

if package:config("c_api") then
io.writefile("xmake.lua", [[
add_rules("mode.debug", "mode.release")
target("concurrentqueue-c")
set_kind("$(kind)")
add_files("c_api/*.cpp")
add_headerfiles("(c_api/concurrentqueue.h)")
if is_plat("windows") and is_kind("shared") then
add_defines("DLL_EXPORT")
end
]])
import("package.tools.xmake").install(package)

if package:is_plat("windows") and (not package:config("shared")) then
package:add("defines", "MOODYCAMEL_STATIC")
end
end
end)

on_test(function (package)
assert(package:check_cxxsnippets({test = [[
#include <assert.h>
static void test() {
#include <concurrentqueue.h>
void test() {
moodycamel::ConcurrentQueue<int> q;
bool success = q.enqueue(25);
int item;
bool found = q.try_dequeue(item);
assert(found && item == 25);
q.enqueue(25);
}
]]}, {configs = {languages = "c++11"}, includes = "concurrentqueue/concurrentqueue.h"}))
]]}, {configs = {languages = "c++11"}}))
if package:config("c_api") then
assert(package:has_cfuncs("moodycamel_cq_create", {includes = "c_api/concurrentqueue.h"}))
end
end)

40 changes: 40 additions & 0 deletions packages/d/dispenso/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package("dispenso")
set_homepage("https://github.com/facebookincubator/dispenso")
set_description("The project provides high-performance concurrency, enabling highly parallel computation.")
set_license("MIT")

add_urls("https://github.com/facebookincubator/dispenso/archive/refs/tags/$(version).tar.gz",
"https://github.com/facebookincubator/dispenso.git")

add_versions("v1.1.0", "581f95c16cd479692bc89448d0648f6ce24162454308c544c4d35bf5e9efe5c8")

if is_plat("linux", "bsd") then
add_syslinks("pthread")
elseif is_plat("windows", "mingw") then
add_defines("NOMINMAX")
add_syslinks("winmm", "synchronization")
end

add_deps("cmake")
add_deps("concurrentqueue")

on_install("windows|x64", "linux", "macosx", "bsd", "mingw", "msys", "android", "iphoneos", "cross", "wasm", function (package)
local configs = {}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DDISPENSO_SHARED_LIB=" .. (package:config("shared") and "ON" or "OFF"))

io.replace("dispenso/CMakeLists.txt", "-Werror", "", {plain = true})
io.replace("dispenso/CMakeLists.txt", "Synchronization", "Synchronization winmm", {plain = true})
import("package.tools.cmake").install(package, configs)

os.tryrm(package:installdir("include/dispenso/third-party"))
end)

on_test(function (package)
assert(package:check_cxxsnippets({test = [[
#include <dispenso/thread_pool.h>
void test() {
dispenso::ThreadPool& threadPool = dispenso::globalThreadPool();
}
]]}, {configs = {languages = "c++14"}}))
end)

4 comments on commit 095e769

@SirLynix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit broke the concurrentqueue package include (<concurrentqueue/concurrentqueue.h>) in two of my projects, this is the second time it's happening following one of your update (#2988).
Could you please try to be more careful not to break includes in the future? Even if it means create a dummy .h file with a #pragma message like:
concurrentqueue/concurrentqueue.h:

#pragma once

#pragma message this includes is no longer correct for the package concurrentqueue.h and should be updated
#include "../concurrentqueue.h"

@waruqi
Copy link
Member

@waruqi waruqi commented on 095e769 Dec 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try to open a pr to fix it?

@SirLynix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@star-hengxing
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't think it through before modifying the package.
But it's hard to avoid that xmake-repo modifications won't break the user, and I've been broken a few times at times.
Best practice might be to use package.requires_lock or a private repository to ensure compatibility

Please sign in to comment.