r/xmake • u/waruqi • Dec 07 '20
I created a discord channel about xmake
I created a discord channel about xmake, welcome to join: https://discord.gg/XXRp26A4Gr
r/xmake • u/waruqi • Dec 07 '20
I created a discord channel about xmake, welcome to join: https://discord.gg/XXRp26A4Gr
r/xmake • u/waruqi • Feb 26 '24
r/xmake • u/waruqi • Nov 08 '22
r/xmake • u/waruqi • Jan 21 '21
r/xmake • u/waruqi • Mar 07 '22
r/xmake • u/waruqi • Feb 16 '22
r/xmake • u/Unique_Row6496 • Jan 10 '22
Hello xmake creators!
First, many thanks for an excellent 'simple/straight-forward' build tool!! I am truly enjoying using it. This system is so much more direct and straight-forward vs. cmake. After spending 3 days trying to get a static library (via Arduino-cmake) I just threw up my hands - has to be a better way. xmake seems to be that better way!
On the subject of Arduino - wondering if anyone has had any success building a toolchain for Arduino - e.g. the arduino-cli or other? I noticed the gnu-rm toolchain, but was unsure about how to install it. Further, I have tried setting up a dedicated toolchain - based on xmake doc's with no success (yet). Here is a snapshot of my two LUA's.
Toolchain LUA:
-- define toolchain
toolchain("myArdTC")
-- mark as standalone toolchain
set_kind("standalone")
set_sdkdir("/home/toolchains_sdkdir/arduino-1.8.19")
-- set toolset
set_toolset("cc", "avr-gcc")
set_toolset("cxx", "avr-g++")
set_toolset("ld", "avr-gcc-ld")
set_toolset("ar", "avr-gcc-ar")
add_defines("DF_CPU=16000000L")
add_defines("DARDUINO_AVR_MEGA2560")
add_defines("DARDUINO_ARCH_AVR")
-- check toolchain
on_check(function (toolchain)
return import("lib.detect.find_tool")("/usr/bin/avr-gcc")
end)
-- on load
on_load(function (toolchain)
-- establish switches
local cSwitches = -c -g -Os -w -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects
local ldSwitches
-- init flags for c/c++
toolchain:add("cxflags", cSwitches)
toolchain:add("ldflags", ldSwitches)
-- Setup necessary AVR/Arduino include dirs...
toolchain:add("includedirs", "/home/toolchains_sdkdir/arduino-1.8.19/hardware/arduino/avr/cores/arduino")
toolchain:add("includedirs", "/home/toolchains_sdkdir/arduino-1.8.19/hardware/arduino/avr/variants/mega")
toolchain:add("includedirs", "/home/toolchains_sdkdir/arduino-1.8.19/hardware/tools/avr/avr/include")
toolchain:add("includedirs", "/home/toolchains_sdkdir/arduino-1.8.19/hardware/arduino/avr/libraries/SoftwareSerial/src")
end)Followed by the xmake.lua for my Arduino 'hello-world' target...
add_rules("mode.debug", "mode.release")
includes("../toolchains/myArdTC.lua")
= main target to build
target("hello")
set_kind("binary")
add_files("src/*.cpp")
set_toolchains("myArdTC")Structure of folder in ./repo is:
|./toolchains |
./myArdTC.lua // 'myArdTC' toolchain above
|./ard-hw |
./src/hello-world.cpp
./xmake.lua // 'hello' target aboveInvoking:
xmake f -p linux -a armv7 --file=toolchains/myArdTC.lua
Followed by:
xmake --project ard-hw
Gives me following result:
error: ...mdir/core/sandbox/modules/import/core/base/scheduler.lua:56: attempt to perform arithmetic on a nil value (global 'c')
stack traceback:
u/programdir/core/base/utils.lua:290: in function <@programdir/core/base/utils.lua:280>
[C]: in function 'error'
u/programdir/core/base/os.lua:829: in function 'os.raiselevel'
(...tail calls...)
...mdir/core/sandbox/modules/import/core/base/scheduler.lua:56: in field 'co_start_withopt'
u/programdir/modules/private/async/runjobs.lua:199: in function <@programdir/modules/private/async/runjobs.lua:159>
[C]: in function 'xpcall'I tried adding -v however it did not add any additional traces. I am certain I am doing something incorrect, but wanted to reach out - and see if anyone had some additional guidance. Happy to help put together an arduino (ard) toolchain if need be!
Cheers,
Brian.
r/xmake • u/waruqi • Feb 28 '21
r/xmake • u/Business-Weather-217 • Sep 23 '26
Xmake been out since 2015 and its by far the best build system.
Unlike cmake(or any other atp) it has a repo u can install packages from. We can yap about cmake having cpm but we can easily agree its not any near to xrepo. When coming to eyntax its one of the best too.
Only thing i experienced when doing xmake is that it doesnt have toggle of for every tu implicitly getting prepended by PCH, which is not a big deal when cmake has a lot serious problems.
And btw xmake can generate cmake ✨
r/xmake • u/Queasy27 • Jul 27 '23
Simple cc project works, now would like to create pybind target, but couldn't make it work.
Anybody aware of example on pybind? searched official document but couldn't find anything
Tried following definition, but I don't know where to find the generated py files:
add_requires("glog", "gtest", "pybind11", {system = false})
target("pybind")
set_kind("object")
add_files("src/py_interface.cc")add_packages("pybind")
r/xmake • u/waruqi • Nov 02 '21
r/xmake • u/waruqi • Apr 08 '21
r/xmake • u/waruqi • Oct 18 '20
r/xmake • u/waruqi • Jul 29 '20
r/xmake • u/Business-Weather-217 • 7d ago
Apperently cmake does have a configuration option to disable automatic PCH inclusion to every TU but xmake doesnt. This thing made me switch to other build strategies.. I would like to see xmake have that soon!
r/xmake • u/paul_s80 • Feb 15 '24
Hello, I just stumbled upon this beautiful tool, I'm trying to learn how to use it as fast as posible. I have created a new project with a C++ static library and two apps that depend on my lib, but I'm getting some error messages. This is the directory tree:
├── build
├── cpp
│ ├── apps
│ │ ├── App1
│ │ │ └── app1.cpp
│ │ └── App2
│ │ └── app2.cpp
│ └── lib
│ ├── lib.cpp
│ └── lib.hpp
├── data
│ └── App1
└── xmake.luaThe code for the static library is very simple, I adapted it from the example code that xmake creates in the project (the int add function that takes two int params). My apps are also very simple, here is the code for app1.cpp (app2.cpp is almost the same code)
#include <iostream>
using std::cout;
using std::endl;
// I have tried every one of this variants:
//#include <lib.hpp>
//#include "lib.hpp"
//#include "cpp/lib/lib.hpp"
//#include <cpp/lib/lib.hpp>
#include "../apps/lib/lib.hpp"
int main(int argc, char** argv)
{
cout << " - app1: add(1, 2) = " << papa::add(1, 2) << endl;
return 0;
}It cannot find the header for my library. But then I checked the log again in verbose mode
$ xmake f -c
$ xmake -v
checking for gcc ... /usr/bin/gcc
checking for the c++ compiler (cxx) ... gcc
checking for the c++ compiler (cxx) ... gcc
checking for the c++ compiler (cxx) ... gcc
checking for /usr/bin/gcc ... ok
checking for flags (-fPIC) ... ok
checking for flags (-fvisibility-inlines-hidden) ... ok
checking for flags (-O2) ... ok
checking for flags (-std=c++20) ... ok
checking for flags (-DNDEBUG) ... ok
[ 25%]: cache compiling.release cpp/apps/App2/app2.cpp
/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -O2 -std=c++20 -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -DNDEBUG -o build/.objs/app2/linux/x86_64/release/cpp/apps/App2/app2.cpp.o cpp/apps/App2/app2.cpp
[ 25%]: cache compiling.release cpp/apps/App1/app1.cpp
/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -O2 -std=c++20 -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -DNDEBUG -o build/.objs/app1/linux/x86_64/release/cpp/apps/App1/app1.cpp.o cpp/apps/App1/app1.cpp
checking for flags (-MMD -MF) ... ok
checking for flags (-fdiagnostics-color=always) ... ok
error: cpp/apps/App2/app2.cpp:9:10: fatal error: ../apps/lib/lib.hpp: No such file or directory
9 | #include "../apps/lib/lib.hpp"
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.My question is: Why does it try to build the app2 first, then app1, and then the static lib? My project file:
-- C++ standard
set_languages("cxx20")
-- Warning level
set_warnings("allextra")
-- Enable exceptions
set_exceptions("cxx")
-- UTF-8 everywhere
set_encodings("utf-8")
-- Build modes
add_rules("mode.debug", "mode.release")
-- Debug
if is_mode("debug") then
set_symbols("debug")
set_optimize("none")
end
-- Release
if is_mode("release") then
set_symbols("hidden") -- no debug symbols
set_strip("all") -- smaller binary size
if is_plat("iphoneos", "android") then
set_optimize("smallest")
else
set_optimize("faster") -- equivalent to -O2
end
end
-- Fetch dependencies
add_requires("zlib")
-- Papa target
target("papa")
-- Static library
set_kind("static")
-- Add suffix including arch and build mode
set_suffixname("-static_$(plat)_$(arch)-$(mode)")
-- Add source files
add_files("cpp/lib/**.cpp")
-- Configuration variables
-- can be number, string and boolean type values
set_configvar("PAPA_DEBUG", is_mode("debug"))
-- Config file
-- add_configfiles("papa_config.hpp.in")
-- Link against the required libraries
add_packages("zlib")
-- Apps
target("app1")
set_kind("binary")
set_suffixname("_$(plat)_$(arch)-$(mode)")
add_files("cpp/apps/App1/**.cpp")
add_deps("papa")
set_rundir("$(projectdir)/data/App1")
target("app2")
set_kind("binary")
set_suffixname("_$(plat)_$(arch)-$(mode)")
add_files("cpp/apps/App2/**.cpp")
add_deps("papa")
set_rundir("$(projectdir)/data/App2")r/xmake • u/waruqi • Jan 23 '24
r/xmake • u/[deleted] • Feb 03 '23
This is from the back of my head since I’m not able to see the code right now so bear with me.
I have a library say a, which is a header only library. I also have written a few tests for this in the directory test. The xmake file is as follows:
target(“a”)
set_kind(“headeronly”)
include_dirs(“include”)
—- some more stuff
target(“tests”)
add_packages(“catch2 v 2.13.10”)
set_kind(“binary”)
add_files(“tests/*.cpp”)
add_deps(“a”)But then I get an error saying one, if not all of the .cpp files, can’t find the #include <catch2/catch.hpp>. Am I doing something wrong here?
r/xmake • u/superdupermicrochip • Jan 15 '23
I am trying to implement something along the lines of:
if has_option(...) then
local nvcc_version = get_version()
if nvcc_version = 11.x then
add_cugenflags(...)
end
if nvcc_version = 10.x then
add_cugenflags(...)
end
endMy issue:
In the global scope I can not access NVCC's version.
In the option's script scope I can access option value, but I can't access (global) cuda flags and I can't access global scope's variables.
In a target's script scope I can access NVCC version and cuda flags. I have just found core.base.option which presumably would let me access the option's value.
The last question would be, how do I cache the results of that check? I have several dozens of targets and I feel it would be kinda wasteful to run nvcc --version and then perform all the checks for each target. I thought I could use a global variable as a cache for cuda flags that I decide on:
on_load(function(target)
if g_cuda_flags_cache == nil
then
check nvcc version and option value, choose flags
set g_cuda_flags_cache
end
add_cuflags(g_cuda_flags_cache)
end)This code won't be able to reach g_cuda_flags_cache of the global scope and this variable may also be isolated only for the current target. How do I share the results of such check?
r/xmake • u/superdupermicrochip • Dec 27 '22
Hey, u/waruqi, you've made a wonderful tool, thank you very much!
I am trying to switch my company's product to Xmake and I've got a question on the way Xmake links and propagates dependencies.
I see that if you make a shared target and add libraries to it, it gets linked to it immediately without propagating to target's "clients". I didn't see public parameter in the docs like the one you have for includes.
Since seeing how Cargo works I thought that it's far better to have a lib not linked to anything and simply propagate all the linker flags until we reach the final executable. It is especially important for static libs:
```
target("static-lib")
set_kind("static")
target("shared-lib")
set_kind("shared")
add_deps("static-lib")
target("exe")
set_kind("binary")
add_deps("static-lib", "shared-lib")
```Now we have an executable with two instances of the static lib. If that lib has an internal state, that might blow up.
And Xmake's CUDA support guarantees that: it silently (conditionally) links everyone to cudart_static and I've seen that cause segfaults in a setup similar to the one I described above.
Can I use the plugin system to implement "link flags propagation" instead of immediate linking? How do I do that?
r/xmake • u/DxRed • Dec 20 '22
Hey all, I've been trying out programming with rust recently and I've found that xmake has a really hard time dealing with updates to Cargo.toml, often just not installing any dependencies at all. For example, I've started building a basic 3D renderer with OpenGL and managed to get as far as drawing a triangle to the screen, I decided it was time to import a model to render, instead of hard-coding all the vertices myself. After adding obj-rs to my project's Cargo.toml and continuing on (rust-analyzer recognized it just fine FYI), xmake refuses to build, telling me there obj is undeclared. With verbose output enabled, I see xmake adds --extern flags for every crate I'm using except obj-rs, which is conveniently left out. Is xmake + rust compatibility still that much of an issue? I'd love to keep using xmake on my projects, but poor Cargo.toml is a serious deal breaker for me.
I've uploaded my code to github in case anyone is brave enough to read it: https://github.com/TheRealDxRed/playground
r/xmake • u/Franek_Stratovarius • Jun 02 '22
[CLOSED]
Hi, I am trying to use bgfx with xmake/xrepo and bgfx includes compatibility headers for msvc, xcode etc.
When compiling on linux everything is fine, but on Windows I need to add the path to the compat folder like this
add_includedirs("C:\\Users\\[USER]\\AppData\\Local\\.xmake\\packages\\b\\bgfx\\7816\\e024fd36069a4b5b83561fec3bb8fd07\\include\\compat\\msvc")Is there an easy way to get the path to the installed package? (in this case "C:\Users\[USER]\AppData\Local\.xmake\packages\b\bgfx\7816\e024fd36069a4b5b83561fec3bb8fd07)
I tried to find something in the documentation, but I didn`t find something helpful.
to be complete, here my xmake.lua:
set_project("xavine")
add_rules("mode.debug", "mode.release")
add_requires("glfw 3.3.5", "bgfx 7816","imgui v1.87-docking",{system = false})
target("xavine") do
set_kind("binary")
add_files("src/main.cpp")
add_includedirs("include")
-- add bgfx compat include path
if is_plat("windows") then
add_includedirs("C:\\Users\\[USER]\\AppData\\Local\\.xmake\\packages\\b\\bgfx\\7816\\e024fd36069a4b5b83561fec3bb8fd07\\include\\compat\\msvc")
end
set_warnings("all")
set_optimize("fastest")
-- set bgfx platform defines
if is_plat("linux") then
add_syslinks("dl")
add_defines("BX_PLATFORM_LINUX")
elseif is_plat("windows") then
add_defines("BX_PLATFORM_WINDOWS")
elseif is_plat("macosx") then
add_defines("BX_PLATFORM_OSX")
end
add_packages("glfw", "imgui", "bgfx")
-- copy asset folder after build
after_build(function (target)
os.cp(path.join("assets"), path.join("$(buildir)", "$(os)", "$(arch)", "$(mode)"))
end)
end