export const data = { "examples/winsdk/usbview": [ { "name": "xmake.lua", "code": "target(\"usbview\")\n add_rules(\"win.sdk.application\")\n add_files(\"src/*.c\", \"src/*.rc\")\n add_files(\"src/xmlhelper.cpp\", {rules = \"win.sdk.dotnet\"})\n", "language": "lua", "highlightedCode": "
target(\"usbview\")\n    add_rules(\"win.sdk.application\")\n    add_files(\"src/*.c\", \"src/*.rc\")\n    add_files(\"src/xmlhelper.cpp\", {rules = \"win.sdk.dotnet\"})\n
" }, { "name": "src/usbview.c", "code": "#include \n#include \n\nint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {\n MessageBox(NULL, _T(\"Hello WinSDK!\"), _T(\"USBView\"), MB_OK);\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <windows.h>\n#include <tchar.h>\n\nint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {\n    MessageBox(NULL, _T(\"Hello WinSDK!\"), _T(\"USBView\"), MB_OK);\n    return 0;\n}\n
" }, { "name": "src/usbview.rc", "code": "#include \n\n// Resource script content\n// IDI_ICON1 ICON \"icon.ico\"\n", "language": "text" }, { "name": "src/xmlhelper.cpp", "code": "#using \n#using \n\nusing namespace System;\nusing namespace System::Xml;\n\npublic ref class XmlHelper {\npublic:\n static void Parse(String^ path) {\n XmlDocument^ doc = gcnew XmlDocument();\n doc->Load(path);\n Console::WriteLine(doc->OuterXml);\n }\n};\n", "language": "cpp", "highlightedCode": "
#using <System.dll>\n#using <System.Xml.dll>\n\nusing namespace System;\nusing namespace System::Xml;\n\npublic ref class XmlHelper {\npublic:\n    static void Parse(String^ path) {\n        XmlDocument^ doc = gcnew XmlDocument();\n        doc->Load(path);\n        Console::WriteLine(doc->OuterXml);\n    }\n};\n
" } ], "examples/wdk/umdf": [ { "name": "xmake.lua", "code": "target(\"echo\")\n add_rules(\"wdk.driver\", \"wdk.env.umdf\")\n add_files(\"driver/*.c\")\n add_files(\"driver/*.inx\")\n add_includedirs(\"exe\")\n\ntarget(\"app\")\n add_rules(\"wdk.binary\", \"wdk.env.umdf\")\n add_files(\"exe/*.cpp\")\n", "language": "lua", "highlightedCode": "
target(\"echo\")\n    add_rules(\"wdk.driver\", \"wdk.env.umdf\")\n    add_files(\"driver/*.c\")\n    add_files(\"driver/*.inx\")\n    add_includedirs(\"exe\")\n\ntarget(\"app\")\n    add_rules(\"wdk.binary\", \"wdk.env.umdf\")\n    add_files(\"exe/*.cpp\")\n
" }, { "name": "driver/echo.c", "code": "#include \n#include \n\n// Minimal UMDF driver entry point\nNTSTATUS DriverEntry(\n _In_ PDRIVER_OBJECT DriverObject,\n _In_ PUNICODE_STRING RegistryPath\n)\n{\n // ...\n return STATUS_SUCCESS;\n}\n", "language": "cpp", "highlightedCode": "
#include <windows.h>\n#include <wdf.h>\n\n// Minimal UMDF driver entry point\nNTSTATUS DriverEntry(\n    _In_ PDRIVER_OBJECT  DriverObject,\n    _In_ PUNICODE_STRING RegistryPath\n)\n{\n    // ...\n    return STATUS_SUCCESS;\n}\n
" }, { "name": "driver/echo.inx", "code": "; echo.inx\n[Version]\nSignature=\"$Windows NT$\"\nClass=System\nClassGuid={4d36e97d-e325-11ce-bfc1-08002be10318}\nProvider=%ProviderString%\nDriverVer=01/01/2024,1.0.0.1\n", "language": "text" }, { "name": "exe/main.cpp", "code": "#include \n#include \n\nint main() {\n std::cout << \"UMDF App\" << std::endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <windows.h>\n#include <iostream>\n\nint main() {\n    std::cout << \"UMDF App\" << std::endl;\n    return 0;\n}\n
" } ], "examples/wdk/kmdf": [ { "name": "xmake.lua", "code": "target(\"nonpnp\")\n add_rules(\"wdk.driver\", \"wdk.env.kmdf\")\n add_values(\"wdk.tracewpp.flags\", \"-func:TraceEvents(LEVEL,FLAGS,MSG,...)\", \"-func:Hexdump((LEVEL,FLAGS,MSG,...))\")\n add_files(\"driver/*.c\", {rule = \"wdk.tracewpp\"})\n add_files(\"driver/*.rc\")\n\ntarget(\"app\")\n add_rules(\"wdk.binary\", \"wdk.env.kmdf\")\n add_files(\"exe/*.c\")\n add_files(\"exe/*.inf\")\n", "language": "lua", "highlightedCode": "
target(\"nonpnp\")\n    add_rules(\"wdk.driver\", \"wdk.env.kmdf\")\n    add_values(\"wdk.tracewpp.flags\", \"-func:TraceEvents(LEVEL,FLAGS,MSG,...)\", \"-func:Hexdump((LEVEL,FLAGS,MSG,...))\")\n    add_files(\"driver/*.c\", {rule = \"wdk.tracewpp\"})\n    add_files(\"driver/*.rc\")\n\ntarget(\"app\")\n    add_rules(\"wdk.binary\", \"wdk.env.kmdf\")\n    add_files(\"exe/*.c\")\n    add_files(\"exe/*.inf\")\n
" }, { "name": "driver/nonpnp.c", "code": "#include \n#include \n#include \"nonpnp.tmh\" // Generated by WPP\n\nNTSTATUS DriverEntry(\n _In_ PDRIVER_OBJECT DriverObject,\n _In_ PUNICODE_STRING RegistryPath\n)\n{\n // ...\n TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, \"%!FUNC! Entry\");\n return STATUS_SUCCESS;\n}\n", "language": "cpp", "highlightedCode": "
#include <ntddk.h>\n#include <wdf.h>\n#include \"nonpnp.tmh\" // Generated by WPP\n\nNTSTATUS DriverEntry(\n    _In_ PDRIVER_OBJECT  DriverObject,\n    _In_ PUNICODE_STRING RegistryPath\n)\n{\n    // ...\n    TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, \"%!FUNC! Entry\");\n    return STATUS_SUCCESS;\n}\n
" }, { "name": "driver/nonpnp.rc", "code": "#include \n\n#define VER_FILETYPE VFT_DRV\n#define VER_FILESUBTYPE VFT2_DRV_SYSTEM\n#define VER_FILEDESCRIPTION_STR \"KMDF Driver\"\n#define VER_INTERNALNAME_STR \"nonpnp.sys\"\n#define VER_ORIGINALFILENAME_STR \"nonpnp.sys\"\n\n#include \"common.ver\"\n", "language": "text" }, { "name": "exe/testapp.c", "code": "#include \n#include \n\nint main() {\n printf(\"KMDF App\\n\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <windows.h>\n#include <stdio.h>\n\nint main() {\n    printf(\"KMDF App\\n\");\n    return 0;\n}\n
" }, { "name": "exe/testapp.inf", "code": "; testapp.inf\n[Version]\nSignature=\"$Windows NT$\"\nClass=System\nClassGuid={4d36e97d-e325-11ce-bfc1-08002be10318}\nProvider=%ProviderString%\nDriverVer=01/01/2024,1.0.0.1\n", "language": "text" } ], "examples/wasm/preload": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_values(\"wasm.preloadfiles\", \"src/assets/file1.txt\")\n add_values(\"wasm.preloadfiles\", \"src/assets/file2.txt\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_values(\"wasm.preloadfiles\", \"src/assets/file1.txt\")\n    add_values(\"wasm.preloadfiles\", \"src/assets/file2.txt\")\n
" }, { "name": "src/assets/file1.txt", "code": "Hello from file1!", "language": "txt", "highlightedCode": "
Hello from file1!
" }, { "name": "src/assets/file2.txt", "code": "Hello from file2!", "language": "txt", "highlightedCode": "
Hello from file2!
" }, { "name": "src/main.cpp", "code": "#include \n#include \n#include \n\nint main() {\n std::ifstream file1(\"src/assets/file1.txt\");\n if (file1.is_open()) {\n std::string line;\n while (getline(file1, line)) {\n std::cout << line << '\\n';\n }\n file1.close();\n } else {\n std::cout << \"Unable to open file1.txt\\n\";\n }\n\n std::ifstream file2(\"src/assets/file2.txt\");\n if (file2.is_open()) {\n std::string line;\n while (getline(file2, line)) {\n std::cout << line << '\\n';\n }\n file2.close();\n } else {\n std::cout << \"Unable to open file2.txt\\n\";\n }\n\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n#include <fstream>\n#include <string>\n\nint main() {\n    std::ifstream file1(\"src/assets/file1.txt\");\n    if (file1.is_open()) {\n        std::string line;\n        while (getline(file1, line)) {\n            std::cout << line << '\\n';\n        }\n        file1.close();\n    } else {\n        std::cout << \"Unable to open file1.txt\\n\";\n    }\n\n    std::ifstream file2(\"src/assets/file2.txt\");\n    if (file2.is_open()) {\n        std::string line;\n        while (getline(file2, line)) {\n            std::cout << line << '\\n';\n        }\n        file2.close();\n    } else {\n        std::cout << \"Unable to open file2.txt\\n\";\n    }\n\n    return 0;\n}\n
" } ], "examples/protobuf/cpp": [ { "name": "xmake.lua", "code": "add_requires(\"protobuf-cpp\")\n\ntarget(\"console_cpp\")\n set_kind(\"binary\")\n set_languages(\"c++11\")\n add_packages(\"protobuf-cpp\")\n add_rules(\"protobuf.cpp\")\n add_files(\"src/*.cpp\")\n add_files(\"src/*.proto\")\n", "language": "lua", "highlightedCode": "
add_requires(\"protobuf-cpp\")\n\ntarget(\"console_cpp\")\n    set_kind(\"binary\")\n    set_languages(\"c++11\")\n    add_packages(\"protobuf-cpp\")\n    add_rules(\"protobuf.cpp\")\n    add_files(\"src/*.cpp\")\n    add_files(\"src/*.proto\")\n
" }, { "name": "src/main.cpp", "code": "#include \n#include \n#include \"test.pb.h\"\n\nint main() {\n test::Request req;\n req.set_query(\"hello world\");\n\n std::string output;\n if (req.SerializeToString(&output)) {\n std::cout << \"Serialized data: \" << output << std::endl;\n }\n\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n#include <string>\n#include \"test.pb.h\"\n\nint main() {\n    test::Request req;\n    req.set_query(\"hello world\");\n\n    std::string output;\n    if (req.SerializeToString(&output)) {\n        std::cout << \"Serialized data: \" << output << std::endl;\n    }\n\n    return 0;\n}\n
" }, { "name": "src/test.proto", "code": "syntax = \"proto3\";\n\npackage test;\n\nmessage Request {\n string query = 1;\n}\n\nmessage Response {\n int32 code = 1;\n string result = 2;\n}\n", "language": "text" } ], "examples/protobuf/c": [ { "name": "xmake.lua", "code": "add_requires(\"protobuf-c\")\n\ntarget(\"console_c\")\n set_kind(\"binary\")\n add_packages(\"protobuf-c\")\n add_rules(\"protobuf.c\")\n add_files(\"src/*.c\")\n add_files(\"src/*.proto\")\n", "language": "lua", "highlightedCode": "
add_requires(\"protobuf-c\")\n\ntarget(\"console_c\")\n    set_kind(\"binary\")\n    add_packages(\"protobuf-c\")\n    add_rules(\"protobuf.c\")\n    add_files(\"src/*.c\")\n    add_files(\"src/*.proto\")\n
" }, { "name": "src/main.c", "code": "#include \n#include \n#include \"test.pb-c.h\"\n\nint main(int argc, char** argv) {\n Test__Request msg = TEST__REQUEST__INIT;\n void *buf;\n unsigned len;\n\n msg.query = \"hello world\";\n len = test__request__get_packed_size(&msg);\n\n buf = malloc(len);\n test__request__pack(&msg, buf);\n\n fprintf(stderr,\"Writing %d serialized bytes\\n\",len); // See the length of message\n fwrite(buf,len,1,stdout); // Write to stdout to allow direct command line piping\n\n free(buf);\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n#include <stdlib.h>\n#include \"test.pb-c.h\"\n\nint main(int argc, char** argv) {\n    Test__Request msg = TEST__REQUEST__INIT;\n    void *buf;\n    unsigned len;\n\n    msg.query = \"hello world\";\n    len = test__request__get_packed_size(&msg);\n\n    buf = malloc(len);\n    test__request__pack(&msg, buf);\n\n    fprintf(stderr,\"Writing %d serialized bytes\\n\",len); // See the length of message\n    fwrite(buf,len,1,stdout); // Write to stdout to allow direct command line piping\n\n    free(buf);\n    return 0;\n}\n
" }, { "name": "src/test.proto", "code": "syntax = \"proto3\";\n\npackage test;\n\nmessage Request {\n string query = 1;\n}\n\nmessage Response {\n int32 code = 1;\n string result = 2;\n}\n", "language": "text" } ], "examples/utils/bin2c": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_rules(\"utils.bin2c\", {extensions = \".png\"})\n add_files(\"src/*.c\")\n add_files(\"res/*.png\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_rules(\"utils.bin2c\", {extensions = \".png\"})\n    add_files(\"src/*.c\")\n    add_files(\"res/*.png\")\n
" }, { "name": "res/test.png", "code": "PNG...DATA", "language": "text" }, { "name": "src/main.c", "code": "#include \n\nstatic unsigned char g_png_data[] = {\n #include \"test.png.h\"\n};\n\nint main(int argc, char** argv) {\n printf(\"image size: %d\\n\", (int)sizeof(g_png_data));\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n\nstatic unsigned char g_png_data[] = {\n    #include \"test.png.h\"\n};\n\nint main(int argc, char** argv) {\n    printf(\"image size: %d\\n\", (int)sizeof(g_png_data));\n    return 0;\n}\n
" } ], "examples/utils/bin2obj": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_rules(\"utils.bin2obj\", {extensions = \".png\"})\n add_files(\"src/*.c\")\n add_files(\"res/*.png\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_rules(\"utils.bin2obj\", {extensions = \".png\"})\n    add_files(\"src/*.c\")\n    add_files(\"res/*.png\")\n
" }, { "name": "res/test.png", "code": "PNG...DATA", "language": "text" }, { "name": "src/main.c", "code": "#include \n\nextern unsigned char test_png_data[];\nextern unsigned int test_png_size;\n\nint main(int argc, char** argv) {\n printf(\"image size: %d\\n\", test_png_size);\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n\nextern unsigned char test_png_data[];\nextern unsigned int test_png_size;\n\nint main(int argc, char** argv) {\n    printf(\"image size: %d\\n\", test_png_size);\n    return 0;\n}\n
" } ], "examples/packaging/xpack_basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nincludes(\"@builtin/xpack\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n\nxpack(\"test_pack\")\n set_formats(\"nsis\", \"zip\", \"targz\")\n set_title(\"Hello Xmake\")\n set_author(\"ruki\")\n add_targets(\"test\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nincludes(\"@builtin/xpack\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n\nxpack(\"test_pack\")\n    set_formats(\"nsis\", \"zip\", \"targz\")\n    set_title(\"Hello Xmake\")\n    set_author(\"ruki\")\n    add_targets(\"test\")\n
" }, { "name": "src/main.cpp", "code": "#include \n\nint main(int argc, char** argv) {\n std::cout << \"hello xpack!\" << std::endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nint main(int argc, char** argv) {\n    std::cout << \"hello xpack!\" << std::endl;\n    return 0;\n}\n
" } ], "examples/openmp/loop": [ { "name": "xmake.lua", "code": "add_requires(\"openmp\")\n\ntarget(\"loop\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_packages(\"openmp\")\n", "language": "lua", "highlightedCode": "
add_requires(\"openmp\")\n\ntarget(\"loop\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"openmp\")\n
" }, { "name": "src/main.cpp", "code": "#include \n#include \n\nint main(int argc, char** argv) {\n#pragma omp parallel for\n for (int i = 0; i < 10; ++i) {\n#pragma omp critical\n std::cout << \"Thread \" << omp_get_thread_num() << \" processing iteration \" << i << std::endl;\n }\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n#include <omp.h>\n\nint main(int argc, char** argv) {\n#pragma omp parallel for\n    for (int i = 0; i < 10; ++i) {\n#pragma omp critical\n        std::cout << \"Thread \" << omp_get_thread_num() << \" processing iteration \" << i << std::endl;\n    }\n    return 0;\n}\n
" } ], "examples/mfc/static_library": [ { "name": "xmake.lua", "code": "target(\"mfc_static_lib\")\n add_rules(\"win.sdk.mfc.static\")\n add_files(\"src/*.cpp\")\n", "language": "lua", "highlightedCode": "
target(\"mfc_static_lib\")\n    add_rules(\"win.sdk.mfc.static\")\n    add_files(\"src/*.cpp\")\n
" }, { "name": "src/lib.cpp", "code": "#include \n#include \"lib.h\"\n\nvoid HelloMfc() {\n TRACE(_T(\"Hello MFC\\n\"));\n}\n", "language": "cpp", "highlightedCode": "
#include <afx.h>\n#include \"lib.h\"\n\nvoid HelloMfc() {\n    TRACE(_T(\"Hello MFC\\n\"));\n}\n
" }, { "name": "src/lib.h", "code": "#pragma once\n\nvoid HelloMfc();\n", "language": "cpp", "highlightedCode": "
#pragma once\n\nvoid HelloMfc();\n
" } ], "examples/mfc/static_app": [ { "name": "xmake.lua", "code": "target(\"mfc_static_app\")\n add_rules(\"win.sdk.mfc.static_app\")\n add_files(\"src/*.cpp\")\n add_files(\"src/*.rc\")\n", "language": "lua", "highlightedCode": "
target(\"mfc_static_app\")\n    add_rules(\"win.sdk.mfc.static_app\")\n    add_files(\"src/*.cpp\")\n    add_files(\"src/*.rc\")\n
" }, { "name": "src/main.cpp", "code": "#include \"main.h\"\n\nCMyApp theApp;\n\nBOOL CMyApp::InitInstance() {\n m_pMainWnd = new CMyFrame();\n m_pMainWnd->ShowWindow(m_nCmdShow);\n m_pMainWnd->UpdateWindow();\n return TRUE;\n}\n\nCMyFrame::CMyFrame() {\n Create(NULL, _T(\"MFC Static App\"));\n}\n", "language": "cpp", "highlightedCode": "
#include \"main.h\"\n\nCMyApp theApp;\n\nBOOL CMyApp::InitInstance() {\n    m_pMainWnd = new CMyFrame();\n    m_pMainWnd->ShowWindow(m_nCmdShow);\n    m_pMainWnd->UpdateWindow();\n    return TRUE;\n}\n\nCMyFrame::CMyFrame() {\n    Create(NULL, _T(\"MFC Static App\"));\n}\n
" }, { "name": "src/main.h", "code": "#pragma once\n#include \n\nclass CMyApp : public CWinApp {\npublic:\n virtual BOOL InitInstance();\n};\n\nclass CMyFrame : public CFrameWnd {\npublic:\n CMyFrame();\n};\n", "language": "cpp", "highlightedCode": "
#pragma once\n#include <afxwin.h>\n\nclass CMyApp : public CWinApp {\npublic:\n    virtual BOOL InitInstance();\n};\n\nclass CMyFrame : public CFrameWnd {\npublic:\n    CMyFrame();\n};\n
" }, { "name": "src/mfcapp.rc", "code": "#include \"afxres.h\"\n", "language": "text" } ], "examples/mfc/shared_library": [ { "name": "xmake.lua", "code": "target(\"mfc_shared_lib\")\n add_rules(\"win.sdk.mfc.shared\")\n add_files(\"src/*.cpp\")\n", "language": "lua", "highlightedCode": "
target(\"mfc_shared_lib\")\n    add_rules(\"win.sdk.mfc.shared\")\n    add_files(\"src/*.cpp\")\n
" }, { "name": "src/lib.cpp", "code": "#include \n#include \"lib.h\"\n\nvoid HelloMfc() {\n TRACE(_T(\"Hello MFC\\n\"));\n}\n", "language": "cpp", "highlightedCode": "
#include <afx.h>\n#include \"lib.h\"\n\nvoid HelloMfc() {\n    TRACE(_T(\"Hello MFC\\n\"));\n}\n
" }, { "name": "src/lib.h", "code": "#pragma once\n\n__declspec(dllexport) void HelloMfc();\n", "language": "cpp", "highlightedCode": "
#pragma once\n\n__declspec(dllexport) void HelloMfc();\n
" } ], "examples/mfc/shared_app": [ { "name": "xmake.lua", "code": "target(\"mfc_shared_app\")\n add_rules(\"win.sdk.mfc.shared_app\")\n add_files(\"src/*.cpp\")\n add_files(\"src/*.rc\")\n", "language": "lua", "highlightedCode": "
target(\"mfc_shared_app\")\n    add_rules(\"win.sdk.mfc.shared_app\")\n    add_files(\"src/*.cpp\")\n    add_files(\"src/*.rc\")\n
" }, { "name": "src/main.cpp", "code": "#include \"main.h\"\n\nCMyApp theApp;\n\nBOOL CMyApp::InitInstance() {\n m_pMainWnd = new CMyFrame();\n m_pMainWnd->ShowWindow(m_nCmdShow);\n m_pMainWnd->UpdateWindow();\n return TRUE;\n}\n\nCMyFrame::CMyFrame() {\n Create(NULL, _T(\"MFC Shared App\"));\n}\n", "language": "cpp", "highlightedCode": "
#include \"main.h\"\n\nCMyApp theApp;\n\nBOOL CMyApp::InitInstance() {\n    m_pMainWnd = new CMyFrame();\n    m_pMainWnd->ShowWindow(m_nCmdShow);\n    m_pMainWnd->UpdateWindow();\n    return TRUE;\n}\n\nCMyFrame::CMyFrame() {\n    Create(NULL, _T(\"MFC Shared App\"));\n}\n
" }, { "name": "src/main.h", "code": "#pragma once\n#include \n\nclass CMyApp : public CWinApp {\npublic:\n virtual BOOL InitInstance();\n};\n\nclass CMyFrame : public CFrameWnd {\npublic:\n CMyFrame();\n};\n", "language": "cpp", "highlightedCode": "
#pragma once\n#include <afxwin.h>\n\nclass CMyApp : public CWinApp {\npublic:\n    virtual BOOL InitInstance();\n};\n\nclass CMyFrame : public CFrameWnd {\npublic:\n    CMyFrame();\n};\n
" }, { "name": "src/mfcapp.rc", "code": "#include \"afxres.h\"\n", "language": "text" } ], "examples/cpp/shared_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n set_kind(\"shared\")\n add_files(\"src/foo.cpp\")\n\ntarget(\"demo\")\n set_kind(\"binary\")\n add_deps(\"foo\")\n add_files(\"src/main.cpp\")\n\n\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n    set_kind(\"shared\")\n    add_files(\"src/foo.cpp\")\n\ntarget(\"demo\")\n    set_kind(\"binary\")\n    add_deps(\"foo\")\n    add_files(\"src/main.cpp\")\n\n\n
" }, { "name": "src/foo.cpp", "code": "#include \"foo.h\"\n\nint add(int a, int b) {\n return a + b;\n}\n", "language": "cpp", "highlightedCode": "
#include \"foo.h\"\n\nint add(int a, int b) {\n    return a + b;\n}\n
" }, { "name": "src/foo.h", "code": "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#if defined(_WIN32)\n#define __export __declspec(dllexport)\n#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))\n#define __export __attribute__((visibility(\"default\")))\n#else\n#define __export\n#endif\n\n__export int add(int a, int b);\n\n#ifdef __cplusplus\n}\n#endif\n", "language": "cpp", "highlightedCode": "
#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#if defined(_WIN32)\n#define __export __declspec(dllexport)\n#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))\n#define __export __attribute__((visibility(\"default\")))\n#else\n#define __export\n#endif\n\n__export int add(int a, int b);\n\n#ifdef __cplusplus\n}\n#endif\n
" }, { "name": "src/main.cpp", "code": "#include \"foo.h\"\n#include \n\nusing namespace std;\n\nint main(int argc, char **argv) {\n cout << \"add(1, 2) = \" << add(1, 2) << endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include \"foo.h\"\n#include <iostream>\n\nusing namespace std;\n\nint main(int argc, char **argv) {\n    cout << \"add(1, 2) = \" << add(1, 2) << endl;\n    return 0;\n}\n
" } ], "examples/cpp/static_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n set_kind(\"static\")\n add_files(\"src/foo.cpp\")\n\ntarget(\"demo\")\n set_kind(\"binary\")\n add_deps(\"foo\")\n add_files(\"src/main.cpp\")\n\n\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n    set_kind(\"static\")\n    add_files(\"src/foo.cpp\")\n\ntarget(\"demo\")\n    set_kind(\"binary\")\n    add_deps(\"foo\")\n    add_files(\"src/main.cpp\")\n\n\n
" }, { "name": "src/foo.cpp", "code": "#include \"foo.h\"\n\nint add(int a, int b) {\n return a + b;\n}\n", "language": "cpp", "highlightedCode": "
#include \"foo.h\"\n\nint add(int a, int b) {\n    return a + b;\n}\n
" }, { "name": "src/foo.h", "code": "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\nint add(int a, int b);\n\n#ifdef __cplusplus\n}\n#endif\n", "language": "cpp", "highlightedCode": "
#ifdef __cplusplus\nextern \"C\" {\n#endif\n\nint add(int a, int b);\n\n#ifdef __cplusplus\n}\n#endif\n
" }, { "name": "src/main.cpp", "code": "#include \"foo.h\"\n#include \n\nusing namespace std;\n\nint main(int argc, char **argv) {\n cout << \"add(1, 2) = \" << add(1, 2) << endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include \"foo.h\"\n#include <iostream>\n\nusing namespace std;\n\nint main(int argc, char **argv) {\n    cout << \"add(1, 2) = \" << add(1, 2) << endl;\n    return 0;\n}\n
" } ], "examples/cpp/console": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n\n
" }, { "name": "src/main.cpp", "code": "#include \n\nint main(int argc, char** argv) {\n std::cout << \"hello world!\" << std::endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nint main(int argc, char** argv) {\n    std::cout << \"hello world!\" << std::endl;\n    return 0;\n}\n
" } ], "examples/wdk/wdm/msdsm": [ { "name": "xmake.lua", "code": "target(\"msdsm\")\n add_rules(\"wdk.driver\", \"wdk.env.wdm\")\n add_values(\"wdk.tracewpp.flags\", \"-func:TracePrint((LEVEL,FLAGS,MSG,...))\")\n add_files(\"*.c\", {rule = \"wdk.tracewpp\"})\n add_files(\"*.rc\", \"*.inf\")\n add_files(\"*.mof|msdsm.mof\")\n add_files(\"msdsm.mof\", {values = {wdk_mof_header = \"msdsmwmi.h\"}})\n", "language": "lua", "highlightedCode": "
target(\"msdsm\")\n    add_rules(\"wdk.driver\", \"wdk.env.wdm\")\n    add_values(\"wdk.tracewpp.flags\", \"-func:TracePrint((LEVEL,FLAGS,MSG,...))\")\n    add_files(\"*.c\", {rule = \"wdk.tracewpp\"})\n    add_files(\"*.rc\", \"*.inf\")\n    add_files(\"*.mof|msdsm.mof\")\n    add_files(\"msdsm.mof\", {values = {wdk_mof_header = \"msdsmwmi.h\"}})\n
" }, { "name": "driver.c", "code": "#include \n#include \"msdsm.tmh\" // Generated by WPP\n#include \"msdsmwmi.h\" // Generated from MOF\n\nNTSTATUS DriverEntry(\n _In_ PDRIVER_OBJECT DriverObject,\n _In_ PUNICODE_STRING RegistryPath\n)\n{\n // ...\n return STATUS_SUCCESS;\n}\n", "language": "cpp", "highlightedCode": "
#include <ntddk.h>\n#include \"msdsm.tmh\" // Generated by WPP\n#include \"msdsmwmi.h\" // Generated from MOF\n\nNTSTATUS DriverEntry(\n    _In_ PDRIVER_OBJECT  DriverObject,\n    _In_ PUNICODE_STRING RegistryPath\n)\n{\n    // ...\n    return STATUS_SUCCESS;\n}\n
" }, { "name": "msdsm.inf", "code": "; msdsm.inf\n[Version]\nSignature=\"$Windows NT$\"\nClass=System\nClassGuid={4d36e97d-e325-11ce-bfc1-08002be10318}\nProvider=%ProviderString%\nDriverVer=01/01/2024,1.0.0.1\n", "language": "text" }, { "name": "msdsm.mof", "code": "[Dynamic, Provider(\"WMIProv\"), WMI, Description(\"MSDSM WMI\")]\nclass MSDSM_WMI\n{\n [key, read]\n string InstanceName;\n [read]\n boolean Active;\n};\n", "language": "text" }, { "name": "msdsm.rc", "code": "#include \n#include \"msdsmwmi.h\"\n// Resource definition\n", "language": "text" } ], "examples/wdk/wdm/kcs": [ { "name": "xmake.lua", "code": "target(\"kcs\")\n add_rules(\"wdk.driver\", \"wdk.env.wdm\")\n add_values(\"wdk.man.flags\", \"-prefix Kcs\")\n add_values(\"wdk.man.resource\", \"kcsCounters.rc\")\n add_values(\"wdk.man.header\", \"kcsCounters.h\")\n add_values(\"wdk.man.counter_header\", \"kcsCounters_counters.h\")\n add_files(\"*.c\", \"*.rc\", \"*.man\")\n", "language": "lua", "highlightedCode": "
target(\"kcs\")\n    add_rules(\"wdk.driver\", \"wdk.env.wdm\")\n    add_values(\"wdk.man.flags\", \"-prefix Kcs\")\n    add_values(\"wdk.man.resource\", \"kcsCounters.rc\")\n    add_values(\"wdk.man.header\", \"kcsCounters.h\")\n    add_values(\"wdk.man.counter_header\", \"kcsCounters_counters.h\")\n    add_files(\"*.c\", \"*.rc\", \"*.man\")\n
" }, { "name": "driver.c", "code": "#include \n#include \"kcsCounters.h\"\n\nNTSTATUS DriverEntry(\n _In_ PDRIVER_OBJECT DriverObject,\n _In_ PUNICODE_STRING RegistryPath\n)\n{\n // ...\n return STATUS_SUCCESS;\n}\n", "language": "cpp", "highlightedCode": "
#include <ntddk.h>\n#include \"kcsCounters.h\"\n\nNTSTATUS DriverEntry(\n    _In_ PDRIVER_OBJECT  DriverObject,\n    _In_ PUNICODE_STRING RegistryPath\n)\n{\n    // ...\n    return STATUS_SUCCESS;\n}\n
" }, { "name": "kcsCounters.man", "code": "\n\n \n \n \n \n \n \n \n \n \n\n", "language": "text" }, { "name": "kcsCounters.rc", "code": "#include \n#include \"kcsCounters.h\"\n\n// Resource definition\n", "language": "text" } ], "examples/other-languages/swift/cxx_interop": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"cxx_interop\")\n set_kind(\"binary\")\n set_languages(\"cxx20\")\n add_files(\"lib/**.swift\", {public = true})\n add_files(\"src/**.cpp\")\n set_values(\"swift.modulename\", \"SwiftFibonacci\")\n set_values(\"swift.interop\", \"cxx\")\n set_values(\"swift.interop.headername\", \"fibonacci-Swift.h\")\n set_values(\"swift.interop.cxxmain\", true)\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"cxx_interop\")\n    set_kind(\"binary\")\n    set_languages(\"cxx20\")\n    add_files(\"lib/**.swift\", {public = true})\n    add_files(\"src/**.cpp\")\n    set_values(\"swift.modulename\", \"SwiftFibonacci\")\n    set_values(\"swift.interop\", \"cxx\")\n    set_values(\"swift.interop.headername\", \"fibonacci-Swift.h\")\n    set_values(\"swift.interop.cxxmain\", true)\n
" }, { "name": "lib/fibonacci.swift", "code": "public func fibonacci(_ n: Int) -> Int {\n if n <= 1 { return n }\n return fibonacci(n - 1) + fibonacci(n - 2)\n}\n", "language": "text" }, { "name": "src/main.cpp", "code": "#include \n#include \"fibonacci-Swift.h\"\n\nint main() {\n std::cout << \"fibonacci(10) = \" << SwiftFibonacci::fibonacci(10) << std::endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n#include \"fibonacci-Swift.h\"\n\nint main() {\n    std::cout << \"fibonacci(10) = \" << SwiftFibonacci::fibonacci(10) << std::endl;\n    return 0;\n}\n
" } ], "examples/other-languages/zig/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.zig\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.zig\")\n
" }, { "name": "src/main.zig", "code": "const std = @import(\"std\");\n\npub fn main() void {\n std.debug.print(\"Hello, World!\\n\", .{});\n}\n", "language": "text" } ], "examples/other-languages/swift/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.swift\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.swift\")\n
" }, { "name": "src/main.swift", "code": "print(\"Hello, World!\")\n", "language": "text" } ], "examples/other-languages/vala/static_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\n\nadd_requires(\"glib\")\n\ntarget(\"mymath\")\n set_kind(\"static\")\n add_rules(\"vala\")\n add_files(\"src/mymath.vala\")\n add_values(\"vala.header\", \"mymath.h\")\n add_values(\"vala.vapi\", \"mymath-1.0.vapi\")\n add_packages(\"glib\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_deps(\"mymath\")\n add_rules(\"vala\")\n add_files(\"src/main.vala\")\n add_packages(\"glib\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\n\nadd_requires(\"glib\")\n\ntarget(\"mymath\")\n    set_kind(\"static\")\n    add_rules(\"vala\")\n    add_files(\"src/mymath.vala\")\n    add_values(\"vala.header\", \"mymath.h\")\n    add_values(\"vala.vapi\", \"mymath-1.0.vapi\")\n    add_packages(\"glib\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_deps(\"mymath\")\n    add_rules(\"vala\")\n    add_files(\"src/main.vala\")\n    add_packages(\"glib\")\n
" }, { "name": "src/main.vala", "code": "void main() {\n print(\"add(1, 2) = %d\\n\", MyMath.add(1, 2));\n}\n", "language": "text" }, { "name": "src/mymath.vala", "code": "namespace MyMath {\n public int add(int a, int b) {\n return a + b;\n }\n}\n", "language": "text" } ], "examples/other-languages/vala/shared_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\n\nadd_requires(\"glib\")\n\ntarget(\"mymath\")\n set_kind(\"shared\")\n add_rules(\"vala\")\n add_files(\"src/mymath.vala\")\n add_values(\"vala.header\", \"mymath.h\")\n add_values(\"vala.vapi\", \"mymath-1.0.vapi\")\n add_packages(\"glib\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_deps(\"mymath\")\n add_rules(\"vala\")\n add_files(\"src/main.vala\")\n add_packages(\"glib\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\n\nadd_requires(\"glib\")\n\ntarget(\"mymath\")\n    set_kind(\"shared\")\n    add_rules(\"vala\")\n    add_files(\"src/mymath.vala\")\n    add_values(\"vala.header\", \"mymath.h\")\n    add_values(\"vala.vapi\", \"mymath-1.0.vapi\")\n    add_packages(\"glib\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_deps(\"mymath\")\n    add_rules(\"vala\")\n    add_files(\"src/main.vala\")\n    add_packages(\"glib\")\n
" }, { "name": "src/main.vala", "code": "void main() {\n print(\"add(1, 2) = %d\\n\", MyMath.add(1, 2));\n}\n", "language": "text" }, { "name": "src/mymath.vala", "code": "namespace MyMath {\n public int add(int a, int b) {\n return a + b;\n }\n}\n", "language": "text" } ], "examples/other-languages/vala/console": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\n\nadd_requires(\"lua\", \"glib\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_rules(\"vala\")\n add_files(\"src/*.vala\")\n add_packages(\"lua\", \"glib\")\n add_values(\"vala.packages\", \"lua\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\n\nadd_requires(\"lua\", \"glib\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_rules(\"vala\")\n    add_files(\"src/*.vala\")\n    add_packages(\"lua\", \"glib\")\n    add_values(\"vala.packages\", \"lua\")\n
" }, { "name": "src/main.vala", "code": "using GLib;\n\npublic static int main (string[] args) {\n stdout.printf (\"Hello World\\n\");\n return 0;\n}\n", "language": "text" } ], "examples/other-languages/rust/rust_call_cxx_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n set_kind(\"static\")\n add_files(\"src/foo.cc\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_deps(\"foo\")\n add_files(\"src/main.rs\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n    set_kind(\"static\")\n    add_files(\"src/foo.cc\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_deps(\"foo\")\n    add_files(\"src/main.rs\")\n
" }, { "name": "src/foo.cc", "code": "extern \"C\" int add(int a, int b) {\n return a + b;\n}\n", "language": "cpp", "highlightedCode": "
extern \"C\" int add(int a, int b) {\n    return a + b;\n}\n
" }, { "name": "src/main.rs", "code": "extern \"C\" {\n\tfn add(a: i32, b: i32) -> i32;\n}\n\nfn main() {\n unsafe {\n\t println!(\"add(1, 2) = {}\", add(1, 2));\n }\n}\n", "language": "text" } ], "examples/other-languages/rust/cxx_call_rust_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"cargo::cxx 1.0\")\n\ntarget(\"foo\")\n set_kind(\"static\")\n add_files(\"src/foo.rs\")\n set_values(\"rust.cratetype\", \"staticlib\")\n add_packages(\"cargo::cxx\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_rules(\"rust.cxxbridge\")\n add_deps(\"foo\")\n add_files(\"src/main.cc\")\n add_files(\"src/bridge.rsx\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"cargo::cxx 1.0\")\n\ntarget(\"foo\")\n    set_kind(\"static\")\n    add_files(\"src/foo.rs\")\n    set_values(\"rust.cratetype\", \"staticlib\")\n    add_packages(\"cargo::cxx\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_rules(\"rust.cxxbridge\")\n    add_deps(\"foo\")\n    add_files(\"src/main.cc\")\n    add_files(\"src/bridge.rsx\")\n
" }, { "name": "src/bridge.rsx", "code": "#[cxx::bridge]\nmod foo {\n extern \"Rust\" {\n fn add(a: i32, b: i32) -> i32;\n }\n}\n", "language": "text" }, { "name": "src/foo.rs", "code": "#[cxx::bridge]\nmod foo {\n extern \"Rust\" {\n fn add(a: i32, b: i32) -> i32;\n }\n}\n\npub fn add(a: i32, b: i32) -> i32 {\n return a + b;\n}\n", "language": "text" }, { "name": "src/main.cc", "code": "#include \n#include \"bridge.rs.h\"\n\nint main(int argc, char** argv) {\n printf(\"add(1, 2) == %d\\n\", add(1, 2));\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n#include \"bridge.rs.h\"\n\nint main(int argc, char** argv) {\n    printf(\"add(1, 2) == %d\\n\", add(1, 2));\n    return 0;\n}\n
" } ], "examples/other-languages/rust/cargo_deps_with_toml": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\n\nadd_requires(\"cargo::test\", {configs = {cargo_toml = path.join(os.projectdir(), \"Cargo.toml\")}})\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/main.rs\")\n add_packages(\"cargo::test\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\n\nadd_requires(\"cargo::test\", {configs = {cargo_toml = path.join(os.projectdir(), \"Cargo.toml\")}})\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/main.rs\")\n    add_packages(\"cargo::test\")\n
" }, { "name": "Cargo.toml", "code": "[package]\nname = \"test\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[dependencies]\nbase64 = \"0.13.0\"\nflate2 = { version = \"1.0.17\", features = [\"zlib\"] }\n", "language": "toml", "highlightedCode": "
[package]\nname = \"test\"\nversion = \"0.1.0\"\nedition = \"2018\"\n\n[dependencies]\nbase64 = \"0.13.0\"\nflate2 = { version = \"1.0.17\", features = [\"zlib\"] }\n
" }, { "name": "src/main.rs", "code": "extern crate base64;\nextern crate flate2;\n\nuse base64::{encode, decode};\nuse flate2::Compression;\nuse flate2::write::ZlibEncoder;\nuse std::io::prelude::*;\n\nfn main() {\n let a = b\"hello world\";\n println!(\"base64: {}\", encode(a));\n let mut e = ZlibEncoder::new(Vec::new(), Compression::default());\n e.write_all(a).unwrap();\n println!(\"zlib: {:?}\", e.finish().unwrap());\n}\n", "language": "text" } ], "examples/other-languages/rust/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/main.rs\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/main.rs\")\n
" }, { "name": "src/main.rs", "code": "fn main() {\n println!(\"Hello World!\");\n}\n", "language": "text" } ], "examples/other-languages/rust/cargo_deps": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\n\nadd_requires(\"cargo::base64 0.13.0\")\nadd_requires(\"cargo::flate2 1.0.17\", {configs = {features = \"zlib\"}})\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/main.rs\")\n add_packages(\"cargo::base64\", \"cargo::flate2\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\n\nadd_requires(\"cargo::base64 0.13.0\")\nadd_requires(\"cargo::flate2 1.0.17\", {configs = {features = \"zlib\"}})\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/main.rs\")\n    add_packages(\"cargo::base64\", \"cargo::flate2\")\n
" }, { "name": "src/main.rs", "code": "extern crate base64;\nextern crate flate2;\n\nuse base64::{encode, decode};\nuse flate2::Compression;\nuse flate2::write::ZlibEncoder;\nuse std::io::prelude::*;\n\nfn main() {\n let a = b\"hello world\";\n println!(\"base64: {}\", encode(a));\n let mut e = ZlibEncoder::new(Vec::new(), Compression::default());\n e.write_all(a).unwrap();\n println!(\"zlib: {:?}\", e.finish().unwrap());\n}\n", "language": "text" } ], "examples/other-languages/pascal/shared_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n set_kind(\"shared\")\n add_files(\"src/foo.pas\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_deps(\"foo\")\n add_files(\"src/main.pas\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n    set_kind(\"shared\")\n    add_files(\"src/foo.pas\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_deps(\"foo\")\n    add_files(\"src/main.pas\")\n
" }, { "name": "src/foo.pas", "code": "library foo;\n\nfunction add(a, b: Integer): Integer; cdecl; export;\nbegin\n add := a + b;\nend;\n\nexports\n add;\n\nbegin\nend.\n", "language": "text" }, { "name": "src/main.pas", "code": "program main;\n\nfunction add(a, b: Integer): Integer; cdecl; external 'foo';\n\nbegin\n Writeln('add(1, 1) = ', add(1, 1));\nend.\n", "language": "text" } ], "examples/other-languages/pascal/console": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.pas\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.pas\")\n
" }, { "name": "src/main.pas", "code": "program Hello;\nbegin\n writeln ('Hello World')\nend.\n", "language": "text" } ], "examples/other-languages/nim/static_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n set_kind(\"static\")\n add_files(\"src/foo.nim\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_deps(\"foo\")\n add_files(\"src/main.nim\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n    set_kind(\"static\")\n    add_files(\"src/foo.nim\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_deps(\"foo\")\n    add_files(\"src/main.nim\")\n
" }, { "name": "src/foo.nim", "code": "proc add*(a, b: int): int =\n result = a + b\n", "language": "text" }, { "name": "src/main.nim", "code": "import foo\n\necho add(1, 2)\n", "language": "text" } ], "examples/other-languages/nim/shared_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n set_kind(\"shared\")\n add_files(\"src/foo.nim\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_deps(\"foo\")\n add_files(\"src/main.nim\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n    set_kind(\"shared\")\n    add_files(\"src/foo.nim\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_deps(\"foo\")\n    add_files(\"src/main.nim\")\n
" }, { "name": "src/foo.nim", "code": "proc add*(a, b: int): int {.exportc, dynlib.} =\n result = a + b\n", "language": "text" }, { "name": "src/main.nim", "code": "import foo\n\necho add(1, 2)\n", "language": "text" } ], "examples/other-languages/nim/nimble_package": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"nimble::zip >0.3\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/main.nim\")\n add_packages(\"nimble::zip\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"nimble::zip >0.3\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/main.nim\")\n    add_packages(\"nimble::zip\")\n
" }, { "name": "src/main.nim", "code": "import zip/zlib\n\necho zlibVersion()\n", "language": "text" } ], "examples/other-languages/nim/native_package": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"zlib\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/main.nim\")\n add_packages(\"zlib\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"zlib\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/main.nim\")\n    add_packages(\"zlib\")\n
" }, { "name": "src/main.nim", "code": "proc zlibVersion(): cstring {.cdecl, importc.}\n\necho zlibVersion()\n", "language": "text" } ], "examples/other-languages/nim/mix_c": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n set_kind(\"static\")\n add_files(\"src/*.c\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_deps(\"foo\")\n add_files(\"src/main.nim\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n    set_kind(\"static\")\n    add_files(\"src/*.c\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_deps(\"foo\")\n    add_files(\"src/main.nim\")\n
" }, { "name": "src/foo.c", "code": "#include \n\nvoid foo() {\n printf(\"hello from c\\n\");\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n\nvoid foo() {\n    printf(\"hello from c\\n\");\n}\n
" }, { "name": "src/main.nim", "code": "proc foo() {.importc.}\n\nfoo()\n", "language": "text" } ], "examples/other-languages/nim/console": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/main.nim\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/main.nim\")\n
" }, { "name": "src/main.nim", "code": "echo \"Hello World!\"\n", "language": "text" } ], "examples/other-languages/objc/framework": [ { "name": "xmake.lua", "code": "target(\"test\")\n add_rules(\"xcode.framework\")\n add_files(\"src/*.m\")\n add_files(\"src/Info.plist\")\n", "language": "lua", "highlightedCode": "
target(\"test\")\n    add_rules(\"xcode.framework\")\n    add_files(\"src/*.m\")\n    add_files(\"src/Info.plist\")\n
" }, { "name": "src/Info.plist", "code": "\n\n\n\n CFBundleName\n test\n CFBundleIdentifier\n com.example.test.framework\n CFBundleVersion\n 1.0\n CFBundlePackageType\n FMWK\n\n\n", "language": "text" }, { "name": "src/test.m", "code": "#import \n\n@interface Test : NSObject\n- (void)hello;\n@end\n\n@implementation Test\n- (void)hello {\n NSLog(@\"Hello Framework\");\n}\n@end\n", "language": "text" } ], "examples/other-languages/objc/console": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.m\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.m\")\n
" }, { "name": "src/main.m", "code": "#import \n\nint main(int argc, const char * argv[]) {\n @autoreleasepool {\n NSLog(@\"Hello, World!\");\n }\n return 0;\n}\n", "language": "text" } ], "examples/other-languages/objc/bundle": [ { "name": "xmake.lua", "code": "target(\"test\")\n add_rules(\"xcode.bundle\")\n add_files(\"src/*.m\")\n add_files(\"src/Info.plist\")\n", "language": "lua", "highlightedCode": "
target(\"test\")\n    add_rules(\"xcode.bundle\")\n    add_files(\"src/*.m\")\n    add_files(\"src/Info.plist\")\n
" }, { "name": "src/Info.plist", "code": "\n\n\n\n CFBundleName\n test\n CFBundleIdentifier\n com.example.test.bundle\n CFBundleVersion\n 1.0\n CFBundlePackageType\n BNDL\n\n\n", "language": "text" }, { "name": "src/test.m", "code": "#import \n\n@interface Test : NSObject\n- (void)hello;\n@end\n\n@implementation Test\n- (void)hello {\n NSLog(@\"Hello Bundle\");\n}\n@end\n", "language": "text" } ], "examples/other-languages/lex_yacc/basic": [ { "name": "xmake.lua", "code": "target(\"calc\")\n set_kind(\"binary\")\n add_rules(\"lex\", \"yacc\")\n add_files(\"src/*.l\", \"src/*.y\")\n", "language": "lua", "highlightedCode": "
target(\"calc\")\n    set_kind(\"binary\")\n    add_rules(\"lex\", \"yacc\")\n    add_files(\"src/*.l\", \"src/*.y\")\n
" }, { "name": "src/main.l", "code": "%{\n#include \n#include \"xmake.tab.h\"\n%}\n\n%%\n[0-9]+ return NUMBER;\n\\n return NEWLINE;\n. return CHARACTER;\n%%\n", "language": "text" }, { "name": "src/main.y", "code": "%{\n#include \nint yylex();\nvoid yyerror(const char *s);\n%}\n\n%token NUMBER NEWLINE CHARACTER\n\n%%\nlines: /* empty */\n | lines line\n ;\n\nline: NEWLINE\n | NUMBER NEWLINE { printf(\"Number: %d\\n\", $1); }\n | CHARACTER NEWLINE { printf(\"Character: %c\\n\", $1); }\n ;\n%%\n\nvoid yyerror(const char *s) {\n fprintf(stderr, \"%s\\n\", s);\n}\n\nint main(void) {\n yyparse();\n return 0;\n}\n", "language": "text" } ], "examples/other-languages/objc/application": [ { "name": "xmake.lua", "code": "target(\"test\")\n add_rules(\"xcode.application\")\n add_files(\"src/*.m\")\n add_files(\"src/Info.plist\")\n", "language": "lua", "highlightedCode": "
target(\"test\")\n    add_rules(\"xcode.application\")\n    add_files(\"src/*.m\")\n    add_files(\"src/Info.plist\")\n
" }, { "name": "src/Info.plist", "code": "\n\n\n\n CFBundleDisplayName\n Test\n CFBundleExecutable\n test\n CFBundleIdentifier\n com.example.test\n CFBundleName\n test\n CFBundleVersion\n 1.0\n\n\n", "language": "text" }, { "name": "src/main.m", "code": "#import \n\nint main(int argc, char * argv[]) {\n @autoreleasepool {\n NSLog(@\"Hello World\");\n }\n return 0;\n}\n", "language": "text" } ], "examples/other-languages/golang/modules": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"go::github.com/sirupsen/logrus\", {alias = \"logrus\"})\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.go\")\n add_packages(\"logrus\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"go::github.com/sirupsen/logrus\", {alias = \"logrus\"})\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.go\")\n    add_packages(\"logrus\")\n
" }, { "name": "src/main.go", "code": "package main\n\nimport (\n log \"github.com/sirupsen/logrus\"\n)\n\nfunc main() {\n log.Info(\"Hello World!\")\n}\n", "language": "text" } ], "examples/other-languages/fortran/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.f90\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.f90\")\n
" }, { "name": "src/main.f90", "code": "program hello\n print *, \"Hello World!\"\nend program hello\n", "language": "text" } ], "examples/other-languages/golang/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.go\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.go\")\n
" }, { "name": "src/main.go", "code": "package main\n\nimport \"fmt\"\n\nfunc main() {\n fmt.Println(\"Hello World!\")\n}\n", "language": "text" } ], "examples/other-languages/dlang/dub": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"dub::log 0.4.3\", {alias = \"log\"})\nadd_requires(\"dub::dateparser\", {alias = \"dateparser\"})\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.d\")\n add_packages(\"log\", \"dateparser\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"dub::log 0.4.3\", {alias = \"log\"})\nadd_requires(\"dub::dateparser\", {alias = \"dateparser\"})\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.d\")\n    add_packages(\"log\", \"dateparser\")\n
" }, { "name": "src/main.d", "code": "import std.stdio;\nimport log;\n\nvoid main() {\n info(\"Hello World!\");\n}\n", "language": "text" } ], "examples/other-languages/dlang/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.d\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.d\")\n
" }, { "name": "src/main.d", "code": "import std.stdio;\n\nvoid main() {\n writeln(\"Hello World!\");\n}\n", "language": "text" } ], "examples/other-languages/cuda/basic": [ { "name": "xmake.lua", "code": "target(\"cuda_console\")\n set_kind(\"binary\")\n add_files(\"src/*.cu\")\n -- generate SASS code for SM architecture of current host\n add_cugencodes(\"native\")\n -- generate PTX code for the virtual architecture to guarantee compatibility\n add_cugencodes(\"compute_30\")\n", "language": "lua", "highlightedCode": "
target(\"cuda_console\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cu\")\n    -- generate SASS code for SM architecture of current host\n    add_cugencodes(\"native\")\n    -- generate PTX code for the virtual architecture to guarantee compatibility\n    add_cugencodes(\"compute_30\")\n
" }, { "name": "src/main.cu", "code": "#include \n\n__global__ void hello(void) {\n printf(\"Hello World from GPU!\\n\");\n}\n\nint main() {\n hello<<<1, 10>>>();\n cudaDeviceReset();\n return 0;\n}\n", "language": "text" } ], "examples/embed/verilog/verilator": [ { "name": "xmake.lua", "code": "add_requires(\"verilator\")\n\ntarget(\"hello\")\n add_rules(\"verilator.binary\")\n set_toolchains(\"@verilator\")\n add_files(\"src/*.v\")\n add_files(\"src/*.cpp\")\n add_values(\"verilator.flags\", \"--trace\", \"--timing\")\n", "language": "lua", "highlightedCode": "
add_requires(\"verilator\")\n\ntarget(\"hello\")\n    add_rules(\"verilator.binary\")\n    set_toolchains(\"@verilator\")\n    add_files(\"src/*.v\")\n    add_files(\"src/*.cpp\")\n    add_values(\"verilator.flags\", \"--trace\", \"--timing\")\n
" }, { "name": "src/main.v", "code": "module hello(\n input clk,\n output reg [7:0] count\n);\n\n always @(posedge clk) begin\n count <= count + 1;\n end\n\nendmodule\n", "language": "text" }, { "name": "src/sim_main.cpp", "code": "#include \"hello.h\"\n#include \"verilated.h\"\n\nint main(int argc, char** argv) {\n VerilatedContext* contextp = new VerilatedContext;\n contextp->commandArgs(argc, argv);\n hello* top = new hello{contextp};\n while (!contextp->gotFinish()) { top->eval(); }\n delete top;\n delete contextp;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include \"hello.h\"\n#include \"verilated.h\"\n\nint main(int argc, char** argv) {\n    VerilatedContext* contextp = new VerilatedContext;\n    contextp->commandArgs(argc, argv);\n    hello* top = new hello{contextp};\n    while (!contextp->gotFinish()) { top->eval(); }\n    delete top;\n    delete contextp;\n    return 0;\n}\n
" } ], "examples/embed/verilog/iverilog": [ { "name": "xmake.lua", "code": "add_requires(\"iverilog\")\n\ntarget(\"hello\")\n add_rules(\"iverilog.binary\")\n set_toolchains(\"@iverilog\")\n add_files(\"src/*.v\")\n add_defines(\"TEST\")\n set_languages(\"v1800-2009\")\n", "language": "lua", "highlightedCode": "
add_requires(\"iverilog\")\n\ntarget(\"hello\")\n    add_rules(\"iverilog.binary\")\n    set_toolchains(\"@iverilog\")\n    add_files(\"src/*.v\")\n    add_defines(\"TEST\")\n    set_languages(\"v1800-2009\")\n
" }, { "name": "src/main.v", "code": "module hello;\n initial begin\n $display(\"Hello, World!\");\n $finish;\n end\nendmodule\n", "language": "text" } ], "examples/embed/keil_mdk/static_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n add_rules(\"mdk.static\")\n add_files(\"src/foo/*.c\")\n set_runtimes(\"microlib\")\n\ntarget(\"hello\")\n add_rules(\"mdk.console\")\n add_deps(\"foo\")\n add_files(\"src/*.c\")\n add_includedirs(\"src/foo\")\n set_runtimes(\"microlib\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"foo\")\n    add_rules(\"mdk.static\")\n    add_files(\"src/foo/*.c\")\n    set_runtimes(\"microlib\")\n\ntarget(\"hello\")\n    add_rules(\"mdk.console\")\n    add_deps(\"foo\")\n    add_files(\"src/*.c\")\n    add_includedirs(\"src/foo\")\n    set_runtimes(\"microlib\")\n
" }, { "name": "src/foo/foo.c", "code": "#include \n\nvoid foo() {\n printf(\"hello foo!\\n\");\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n\nvoid foo() {\n    printf(\"hello foo!\\n\");\n}\n
" }, { "name": "src/foo/foo.h", "code": "void foo();\n", "language": "cpp", "highlightedCode": "
void foo();\n
" }, { "name": "src/main.c", "code": "#include \n#include \"foo.h\"\n\nint main() {\n foo();\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n#include \"foo.h\"\n\nint main() {\n    foo();\n    return 0;\n}\n
" } ], "examples/embed/keil_mdk/binary": [ { "name": "xmake.lua", "code": "target(\"hello\")\n add_rules(\"mdk.console\")\n add_files(\"src/*.c\")\n set_runtimes(\"microlib\")\n", "language": "lua", "highlightedCode": "
target(\"hello\")\n    add_rules(\"mdk.console\")\n    add_files(\"src/*.c\")\n    set_runtimes(\"microlib\")\n
" }, { "name": "src/main.c", "code": "#include \n\nint main() {\n printf(\"hello world!\\n\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n\nint main() {\n    printf(\"hello world!\\n\");\n    return 0;\n}\n
" } ], "examples/embed/keil_c51/basic": [ { "name": "xmake.lua", "code": "target(\"hello\")\n add_rules(\"c51.binary\")\n set_toolchains(\"c51\")\n add_files(\"src/main.c\")\n", "language": "lua", "highlightedCode": "
target(\"hello\")\n    add_rules(\"c51.binary\")\n    set_toolchains(\"c51\")\n    add_files(\"src/main.c\")\n
" }, { "name": "src/main.c", "code": "#include \n\nvoid main() {\n while (1) {\n // ...\n }\n}\n", "language": "cpp", "highlightedCode": "
#include <reg51.h>\n\nvoid main() {\n    while (1) {\n        // ...\n    }\n}\n
" } ], "examples/cpp/packages/zlib": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"zlib 1.3.1\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.c\")\n add_packages(\"zlib\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"zlib 1.3.1\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.c\")\n    add_packages(\"zlib\")\n
" }, { "name": "src/main.c", "code": "#include \n#include \n\nint main(int argc, char** argv) {\n printf(\"zlib version: %s\\n\", zlibVersion());\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n#include <zlib.h>\n\nint main(int argc, char** argv) {\n    printf(\"zlib version: %s\\n\", zlibVersion());\n    return 0;\n}\n
" } ], "examples/cpp/packages/openssl": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"openssl\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.c\")\n add_packages(\"openssl\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"openssl\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.c\")\n    add_packages(\"openssl\")\n
" }, { "name": "src/main.c", "code": "#include \n#include \n\nint main() {\n printf(\"OpenSSL Version: %s\\n\", SSLeay_version(SSLEAY_VERSION));\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <openssl/ssl.h>\n#include <stdio.h>\n\nint main() {\n    printf(\"OpenSSL Version: %s\\n\", SSLeay_version(SSLEAY_VERSION));\n    return 0;\n}\n
" } ], "examples/cpp/packages/gflags": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"gflags\", {configs = {shared = true}})\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_packages(\"gflags\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"gflags\", {configs = {shared = true}})\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"gflags\")\n
" }, { "name": "src/main.cpp", "code": "#include \n#include \n\nDEFINE_bool(big_menu, true, \"Include 'advanced' options in the menu listing\");\n\nint main(int argc, char** argv) {\n gflags::ParseCommandLineFlags(&argc, &argv, true);\n if (FLAGS_big_menu) {\n std::cout << \"big menu is enabled\" << std::endl;\n }\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n#include <gflags/gflags.h>\n\nDEFINE_bool(big_menu, true, \"Include 'advanced' options in the menu listing\");\n\nint main(int argc, char** argv) {\n    gflags::ParseCommandLineFlags(&argc, &argv, true);\n    if (FLAGS_big_menu) {\n        std::cout << \"big menu is enabled\" << std::endl;\n    }\n    return 0;\n}\n
" } ], "examples/cpp/packages/fmt": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"fmt\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_packages(\"fmt\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"fmt\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"fmt\")\n
" }, { "name": "src/main.cpp", "code": "#include \n\nint main() {\n fmt::print(\"Hello, world!\\n\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <fmt/core.h>\n\nint main() {\n    fmt::print(\"Hello, world!\\n\");\n    return 0;\n}\n
" } ], "examples/cpp/packages/boost": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"boost\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_packages(\"boost\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"boost\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"boost\")\n
" }, { "name": "src/main.cpp", "code": "#include \n#include \n#include \n#include \n\nint main() {\n std::string s = \"Hello,World\";\n std::vector strs;\n boost::split(strs, s, boost::is_any_of(\",\"));\n for (const auto& str : strs) {\n std::cout << str << std::endl;\n }\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <boost/algorithm/string.hpp>\n#include <iostream>\n#include <string>\n#include <vector>\n\nint main() {\n    std::string s = \"Hello,World\";\n    std::vector<std::string> strs;\n    boost::split(strs, s, boost::is_any_of(\",\"));\n    for (const auto& str : strs) {\n        std::cout << str << std::endl;\n    }\n    return 0;\n}\n
" } ], "examples/cpp/modules/stdmodules": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\nset_languages(\"c++latest\")\n\ntarget(\"mod\")\n set_kind(\"static\")\n add_files(\"src/*.cpp\")\n add_files(\"src/*.mpp\", {public = true})\n\ntarget(\"stdmodules\")\n set_kind(\"binary\")\n add_files(\"test/*.cpp\")\n add_deps(\"mod\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\nset_languages(\"c++latest\")\n\ntarget(\"mod\")\n    set_kind(\"static\")\n    add_files(\"src/*.cpp\")\n    add_files(\"src/*.mpp\", {public = true})\n\ntarget(\"stdmodules\")\n    set_kind(\"binary\")\n    add_files(\"test/*.cpp\")\n    add_deps(\"mod\")\n
" }, { "name": "src/my_module.cpp", "code": "module my_module;\n\nimport std;\n\nauto my_sum(std::size_t a, std::size_t b) -> std::size_t {\n return a + b;\n}\n", "language": "cpp", "highlightedCode": "
module my_module;\n\nimport std;\n\nauto my_sum(std::size_t a, std::size_t b) -> std::size_t {\n    return a + b;\n}\n
" }, { "name": "src/my_module.mpp", "code": "export module my_module;\n\nimport std;\n\nexport auto my_sum(std::size_t a, std::size_t b) -> std::size_t;\n", "language": "text" }, { "name": "test/test.cpp", "code": "import std;\n\nimport my_module;\n\nusing namespace std;\n\nint main(int argc, char **argv) {\n cout << my_sum(1, 1) << endl;\n}\n", "language": "cpp", "highlightedCode": "
import std;\n\nimport my_module;\n\nusing namespace std;\n\nint main(int argc, char **argv) {\n    cout << my_sum(1, 1) << endl;\n}\n
" } ], "examples/cpp/modules/shared_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"foo\")\n set_kind(\"shared\")\n add_files(\"src/foo.mpp\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_deps(\"foo\")\n add_files(\"src/main.cpp\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"foo\")\n    set_kind(\"shared\")\n    add_files(\"src/foo.mpp\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_deps(\"foo\")\n    add_files(\"src/main.cpp\")\n
" }, { "name": "src/foo.mpp", "code": "export module foo;\n\nimport ;\n\nexport void hello() {\n std::cout << \"hello shared module!\" << std::endl;\n}\n", "language": "text" }, { "name": "src/main.cpp", "code": "import foo;\n\nint main() {\n hello();\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
import foo;\n\nint main() {\n    hello();\n    return 0;\n}\n
" } ], "examples/cpp/modules/private_fragment": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"box\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_files(\"src/*.mpp\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"box\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_files(\"src/*.mpp\")\n
" }, { "name": "src/box.mpp", "code": "export module box;\n\nexport class Box {\npublic:\n void open();\n};\n\nmodule :private;\nimport ;\n\nvoid Box::open() {\n std::cout << \"box opened\" << std::endl;\n}\n", "language": "text" }, { "name": "src/main.cpp", "code": "import box;\n\nint main() {\n Box b;\n b.open();\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
import box;\n\nint main() {\n    Box b;\n    b.open();\n    return 0;\n}\n
" } ], "examples/cpp/modules/implementation_unit": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"app\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_files(\"src/*.mpp\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"app\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_files(\"src/*.mpp\")\n
" }, { "name": "src/implementation.cpp", "code": "module foo;\n\nimport ;\n\nvoid hello() {\n std::cout << \"hello implementation unit!\" << std::endl;\n}\n", "language": "cpp", "highlightedCode": "
module foo;\n\nimport <iostream>;\n\nvoid hello() {\n    std::cout << \"hello implementation unit!\" << std::endl;\n}\n
" }, { "name": "src/interface.mpp", "code": "export module foo;\n\nexport void hello();\n", "language": "text" }, { "name": "src/main.cpp", "code": "import foo;\n\nint main() {\n hello();\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
import foo;\n\nint main() {\n    hello();\n    return 0;\n}\n
" } ], "examples/cpp/modules/partition": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"partition_test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_files(\"src/*.mpp\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"partition_test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_files(\"src/*.mpp\")\n
" }, { "name": "src/hello_say.mpp", "code": "export module hello:say;\n\nimport ;\n\nexport void say() {\n std::cout << \"hello partition!\" << std::endl;\n}\n", "language": "text" }, { "name": "src/hello.mpp", "code": "export module hello;\nexport import :say;\n", "language": "text" }, { "name": "src/main.cpp", "code": "import hello;\n\nint main() {\n say();\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
import hello;\n\nint main() {\n    say();\n    return 0;\n}\n
" } ], "examples/cpp/modules/integration": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\nset_languages(\"c++20\")\n\nadd_repositories(\"my-repo repo\") \nadd_requires(\"foo\")\n\ntarget(\"app\")\n set_kind(\"binary\")\n add_packages(\"foo\")\n add_files(\"src/*.cpp\")\n set_policy(\"build.c++.modules\", true)\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\nset_languages(\"c++20\")\n\nadd_repositories(\"my-repo repo\") \nadd_requires(\"foo\")\n\ntarget(\"app\")\n    set_kind(\"binary\")\n    add_packages(\"foo\")\n    add_files(\"src/*.cpp\")\n    set_policy(\"build.c++.modules\", true)\n
" }, { "name": "src/main.cpp", "code": "import foo;\n\nint main() {\n foo::say(\"hello module!\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
import foo;\n\nint main() {\n    foo::say(\"hello module!\");\n    return 0;\n}\n
" } ], "examples/cpp/modules/headerunits": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\nset_languages(\"c++20\")\n\ntarget(\"stl_headerunit\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\", \"src/*.mpp\")\n\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\nset_languages(\"c++20\")\n\ntarget(\"stl_headerunit\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\", \"src/*.mpp\")\n\n
" }, { "name": "src/hello.mpp", "code": "module;\n\nexport module hello;\n\nimport ;\n\nexport namespace hello {\n void say(const char* str) {\n std::cout << str << std::endl;\n }\n}\n", "language": "text" }, { "name": "src/main.cpp", "code": "import hello;\n\nint main() {\n hello::say(\"hello module!\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
import hello;\n\nint main() {\n    hello::say(\"hello module!\");\n    return 0;\n}\n
" } ], "examples/cpp/modules/cross_target": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"bar\")\n set_kind(\"static\")\n add_files(\"src/bar.mpp\")\n\ntarget(\"app\")\n set_kind(\"binary\")\n add_deps(\"bar\")\n add_files(\"src/main.cpp\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"bar\")\n    set_kind(\"static\")\n    add_files(\"src/bar.mpp\")\n\ntarget(\"app\")\n    set_kind(\"binary\")\n    add_deps(\"bar\")\n    add_files(\"src/main.cpp\")\n
" }, { "name": "src/bar.mpp", "code": "export module bar;\n\nexport int add(int a, int b) {\n return a + b;\n}\n", "language": "text" }, { "name": "src/main.cpp", "code": "import bar;\nimport ;\n\nint main() {\n std::cout << \"add(1, 2) = \" << add(1, 2) << std::endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
import bar;\nimport <iostream>;\n\nint main() {\n    std::cout << \"add(1, 2) = \" << add(1, 2) << std::endl;\n    return 0;\n}\n
" } ], "examples/cpp/modules/cpp_only": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++latest\")\n\ntarget(\"stdmodules_cpp_only\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n set_policy(\"build.c++.modules\", true)\n\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++latest\")\n\ntarget(\"stdmodules_cpp_only\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    set_policy(\"build.c++.modules\", true)\n\n
" }, { "name": "src/main.cpp", "code": "import std;\n\nusing namespace std;\n\nint main(int argc, char **argv) {\n cout << \"hello world!\" << endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
import std;\n\nusing namespace std;\n\nint main(int argc, char **argv) {\n    cout << \"hello world!\" << endl;\n    return 0;\n}\n
" } ], "examples/cpp/modules/distribution": [ { "name": "xmake.lua", "code": "package(\"foo\")\n set_sourcedir(path.join(os.scriptdir(), \"src\"))\n on_install(function(package)\n import(\"package.tools.xmake\").install(package, {})\n end)\n", "language": "lua", "highlightedCode": "
package(\"foo\")\n    set_sourcedir(path.join(os.scriptdir(), \"src\"))\n    on_install(function(package)\n        import(\"package.tools.xmake\").install(package, {})\n    end)\n
" }, { "name": "src/foo.cpp", "code": "module foo;\nimport ;\n\nnamespace foo {\n void say(const char *msg) {\n std::cout << \"foo: \" << msg << std::endl;\n }\n}\n", "language": "cpp", "highlightedCode": "
module foo;\nimport <iostream>;\n\nnamespace foo {\n    void say(const char *msg) {\n        std::cout << \"foo: \" << msg << std::endl;\n    }\n}\n
" }, { "name": "src/foo.mpp", "code": "export module foo;\n\nexport namespace foo {\n#ifdef FOO_EXPORT\n void say(const char *msg);\n#endif\n}\n", "language": "text" }, { "name": "src/main.cpp", "code": "#include \n\nint main() {\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nint main() {\n    return 0;\n}\n
" }, { "name": "src/xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\nset_languages(\"c++20\")\n\ntarget(\"foo\")\n set_kind(\"static\")\n add_files(\"*.cpp\")\n add_files(\"*.mpp\", {\n defines = \"FOO_EXPORT\", \n public = true\n })\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\nset_languages(\"c++20\")\n\ntarget(\"foo\")\n    set_kind(\"static\")\n    add_files(\"*.cpp\")\n    add_files(\"*.mpp\", {\n        defines = \"FOO_EXPORT\", \n        public = true\n    })\n
" } ], "examples/cpp/modules/class": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"class_test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_files(\"src/*.mpp\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"class_test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_files(\"src/*.mpp\")\n
" }, { "name": "src/main.cpp", "code": "import math;\nimport ;\n\nint main() {\n Math m;\n std::cout << \"1 + 2 = \" << m.add(1, 2) << std::endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
import math;\nimport <iostream>;\n\nint main() {\n    Math m;\n    std::cout << \"1 + 2 = \" << m.add(1, 2) << std::endl;\n    return 0;\n}\n
" }, { "name": "src/math.mpp", "code": "export module math;\n\nexport class Math {\npublic:\n Math() {}\n \n int add(int a, int b) {\n return a + b;\n }\n};\n", "language": "text" } ], "examples/cpp/modules/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\nset_languages(\"c++20\")\n\ntarget(\"hello\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\", \"src/*.mpp\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\nset_languages(\"c++20\")\n\ntarget(\"hello\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\", \"src/*.mpp\")\n
" }, { "name": "src/hello.mpp", "code": "module;\n#include \n\nexport module hello;\n\nexport namespace hello {\n void say(const char* str) {\n printf(\"%s\\n\", str);\n }\n}\n", "language": "text" }, { "name": "src/main.cpp", "code": "import hello;\n\nint main() {\n hello::say(\"hello module!\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
import hello;\n\nint main() {\n    hello::say(\"hello module!\");\n    return 0;\n}\n
" } ], "examples/cpp/cppfront/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"cppfront\")\n\ntarget(\"test\")\n add_rules(\"cppfront\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp2\")\n add_packages(\"cppfront\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"cppfront\")\n\ntarget(\"test\")\n    add_rules(\"cppfront\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp2\")\n    add_packages(\"cppfront\")\n
" }, { "name": "src/main.cpp2", "code": "main: () -> int = {\n std::cout << \"Hello from Cppfront!\\n\";\n return 0;\n}\n", "language": "text" } ], "examples/cpp/modules/aggregation": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"app\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_files(\"src/*.mpp\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nset_languages(\"c++20\")\n\ntarget(\"app\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_files(\"src/*.mpp\")\n
" }, { "name": "src/circle.mpp", "code": "export module shape.circle;\n\nexport float area(float r) {\n return 3.14159f * r * r;\n}\n", "language": "text" }, { "name": "src/main.cpp", "code": "import shape;\nimport ;\n\nint main() {\n std::cout << \"circle area: \" << area(2.0f) << std::endl;\n std::cout << \"rect area: \" << area(2.0f, 3.0f) << std::endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
import shape;\nimport <iostream>;\n\nint main() {\n    std::cout << \"circle area: \" << area(2.0f) << std::endl;\n    std::cout << \"rect area: \" << area(2.0f, 3.0f) << std::endl;\n    return 0;\n}\n
" }, { "name": "src/rect.mpp", "code": "export module shape.rect;\n\nexport float area(float w, float h) {\n return w * h;\n}\n", "language": "text" }, { "name": "src/shape.mpp", "code": "export module shape;\n\nexport import shape.circle;\nexport import shape.rect;\n", "language": "text" } ], "examples/cpp/graphics/vulkan": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"vulkan-headers\", \"vulkan-loader\")\nadd_requires(\"glfw\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_packages(\"vulkan-headers\", \"vulkan-loader\", \"glfw\")\n set_languages(\"c++17\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"vulkan-headers\", \"vulkan-loader\")\nadd_requires(\"glfw\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"vulkan-headers\", \"vulkan-loader\", \"glfw\")\n    set_languages(\"c++17\")\n
" }, { "name": "src/main.cpp", "code": "#define GLFW_INCLUDE_VULKAN\n#include \n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nconst uint32_t WIDTH = 800;\nconst uint32_t HEIGHT = 600;\n\nconst std::vector deviceExtensions = {\n VK_KHR_SWAPCHAIN_EXTENSION_NAME\n};\n\n#ifdef NDEBUG\nconst bool enableValidationLayers = false;\n#else\nconst bool enableValidationLayers = true;\n#endif\n\nconst std::vector validationLayers = {\n \"VK_LAYER_KHRONOS_validation\"\n};\n\nstruct QueueFamilyIndices {\n std::optional graphicsFamily;\n std::optional presentFamily;\n\n bool isComplete() {\n return graphicsFamily.has_value() && presentFamily.has_value();\n }\n};\n\nstruct SwapChainSupportDetails {\n VkSurfaceCapabilitiesKHR capabilities;\n std::vector formats;\n std::vector presentModes;\n};\n\nclass HelloVulkanApplication {\npublic:\n void run() {\n initWindow();\n initVulkan();\n mainLoop();\n cleanup();\n }\n\nprivate:\n GLFWwindow* window;\n\n VkInstance instance;\n VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;\n VkDevice device;\n VkQueue graphicsQueue;\n VkQueue presentQueue;\n VkSurfaceKHR surface;\n\n VkSwapchainKHR swapChain;\n std::vector swapChainImages;\n VkFormat swapChainImageFormat;\n VkExtent2D swapChainExtent;\n std::vector swapChainImageViews;\n std::vector swapChainFramebuffers;\n\n VkRenderPass renderPass;\n VkCommandPool commandPool;\n VkCommandBuffer commandBuffer;\n\n VkSemaphore imageAvailableSemaphore;\n VkSemaphore renderFinishedSemaphore;\n VkFence inFlightFence;\n\n void initWindow() {\n glfwInit();\n glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);\n glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);\n window = glfwCreateWindow(WIDTH, HEIGHT, \"Vulkan\", nullptr, nullptr);\n }\n\n void initVulkan() {\n createInstance();\n createSurface();\n pickPhysicalDevice();\n createLogicalDevice();\n createSwapChain();\n createImageViews();\n createRenderPass();\n createFramebuffers();\n createCommandPool();\n createCommandBuffer();\n createSyncObjects();\n }\n\n void mainLoop() {\n while (!glfwWindowShouldClose(window)) {\n glfwPollEvents();\n drawFrame();\n }\n vkDeviceWaitIdle(device);\n }\n\n void cleanup() {\n vkDestroySemaphore(device, renderFinishedSemaphore, nullptr);\n vkDestroySemaphore(device, imageAvailableSemaphore, nullptr);\n vkDestroyFence(device, inFlightFence, nullptr);\n\n vkDestroyCommandPool(device, commandPool, nullptr);\n\n for (auto framebuffer : swapChainFramebuffers) {\n vkDestroyFramebuffer(device, framebuffer, nullptr);\n }\n\n vkDestroyRenderPass(device, renderPass, nullptr);\n\n for (auto imageView : swapChainImageViews) {\n vkDestroyImageView(device, imageView, nullptr);\n }\n\n vkDestroySwapchainKHR(device, swapChain, nullptr);\n vkDestroyDevice(device, nullptr);\n vkDestroySurfaceKHR(instance, surface, nullptr);\n vkDestroyInstance(instance, nullptr);\n glfwDestroyWindow(window);\n glfwTerminate();\n }\n\n void createInstance() {\n if (enableValidationLayers && !checkValidationLayerSupport()) {\n throw std::runtime_error(\"validation layers requested, but not available!\");\n }\n\n VkApplicationInfo appInfo{};\n appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;\n appInfo.pApplicationName = \"Hello Vulkan\";\n appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);\n appInfo.pEngineName = \"No Engine\";\n appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);\n appInfo.apiVersion = VK_API_VERSION_1_0;\n\n VkInstanceCreateInfo createInfo{};\n createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;\n createInfo.pApplicationInfo = &appInfo;\n\n uint32_t glfwExtensionCount = 0;\n const char** glfwExtensions;\n glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);\n\n std::vector extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);\n if (enableValidationLayers) {\n extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);\n }\n // MacOS compatibility\n extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);\n createInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;\n\n createInfo.enabledExtensionCount = static_cast(extensions.size());\n createInfo.ppEnabledExtensionNames = extensions.data();\n\n if (enableValidationLayers) {\n createInfo.enabledLayerCount = static_cast(validationLayers.size());\n createInfo.ppEnabledLayerNames = validationLayers.data();\n } else {\n createInfo.enabledLayerCount = 0;\n }\n\n if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to create instance!\");\n }\n }\n\n void createSurface() {\n if (glfwCreateWindowSurface(instance, window, nullptr, &surface) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to create window surface!\");\n }\n }\n\n void pickPhysicalDevice() {\n uint32_t deviceCount = 0;\n vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);\n if (deviceCount == 0) {\n throw std::runtime_error(\"failed to find GPUs with Vulkan support!\");\n }\n std::vector devices(deviceCount);\n vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data());\n for (const auto& device : devices) {\n if (isDeviceSuitable(device)) {\n physicalDevice = device;\n break;\n }\n }\n if (physicalDevice == VK_NULL_HANDLE) {\n throw std::runtime_error(\"failed to find a suitable GPU!\");\n }\n }\n\n void createLogicalDevice() {\n QueueFamilyIndices indices = findQueueFamilies(physicalDevice);\n\n std::vector queueCreateInfos;\n std::set uniqueQueueFamilies = {indices.graphicsFamily.value(), indices.presentFamily.value()};\n\n float queuePriority = 1.0f;\n for (uint32_t queueFamily : uniqueQueueFamilies) {\n VkDeviceQueueCreateInfo queueCreateInfo{};\n queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;\n queueCreateInfo.queueFamilyIndex = queueFamily;\n queueCreateInfo.queueCount = 1;\n queueCreateInfo.pQueuePriorities = &queuePriority;\n queueCreateInfos.push_back(queueCreateInfo);\n }\n\n VkDeviceCreateInfo createInfo{};\n createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;\n createInfo.queueCreateInfoCount = static_cast(queueCreateInfos.size());\n createInfo.pQueueCreateInfos = queueCreateInfos.data();\n createInfo.enabledExtensionCount = static_cast(deviceExtensions.size());\n createInfo.ppEnabledExtensionNames = deviceExtensions.data();\n \n // MacOS/MoltenVK compatibility\n std::vector extensions = deviceExtensions;\n extensions.push_back(\"VK_KHR_portability_subset\");\n createInfo.enabledExtensionCount = static_cast(extensions.size());\n createInfo.ppEnabledExtensionNames = extensions.data();\n\n if (vkCreateDevice(physicalDevice, &createInfo, nullptr, &device) != VK_SUCCESS) {\n // Fallback without portability subset if failed (e.g. not on macos)\n createInfo.enabledExtensionCount = static_cast(deviceExtensions.size());\n createInfo.ppEnabledExtensionNames = deviceExtensions.data();\n if (vkCreateDevice(physicalDevice, &createInfo, nullptr, &device) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to create logical device!\");\n }\n }\n\n vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue);\n vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue);\n }\n\n void createSwapChain() {\n SwapChainSupportDetails swapChainSupport = querySwapChainSupport(physicalDevice);\n VkSurfaceFormatKHR surfaceFormat = chooseSwapSurfaceFormat(swapChainSupport.formats);\n VkPresentModeKHR presentMode = chooseSwapPresentMode(swapChainSupport.presentModes);\n VkExtent2D extent = chooseSwapExtent(swapChainSupport.capabilities);\n\n uint32_t imageCount = swapChainSupport.capabilities.minImageCount + 1;\n if (swapChainSupport.capabilities.maxImageCount > 0 && imageCount > swapChainSupport.capabilities.maxImageCount) {\n imageCount = swapChainSupport.capabilities.maxImageCount;\n }\n\n VkSwapchainCreateInfoKHR createInfo{};\n createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;\n createInfo.surface = surface;\n createInfo.minImageCount = imageCount;\n createInfo.imageFormat = surfaceFormat.format;\n createInfo.imageColorSpace = surfaceFormat.colorSpace;\n createInfo.imageExtent = extent;\n createInfo.imageArrayLayers = 1;\n createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;\n\n QueueFamilyIndices indices = findQueueFamilies(physicalDevice);\n uint32_t queueFamilyIndices[] = {indices.graphicsFamily.value(), indices.presentFamily.value()};\n\n if (indices.graphicsFamily != indices.presentFamily) {\n createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;\n createInfo.queueFamilyIndexCount = 2;\n createInfo.pQueueFamilyIndices = queueFamilyIndices;\n } else {\n createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;\n }\n\n createInfo.preTransform = swapChainSupport.capabilities.currentTransform;\n createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;\n createInfo.presentMode = presentMode;\n createInfo.clipped = VK_TRUE;\n createInfo.oldSwapchain = VK_NULL_HANDLE;\n\n if (vkCreateSwapchainKHR(device, &createInfo, nullptr, &swapChain) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to create swap chain!\");\n }\n\n vkGetSwapchainImagesKHR(device, swapChain, &imageCount, nullptr);\n swapChainImages.resize(imageCount);\n vkGetSwapchainImagesKHR(device, swapChain, &imageCount, swapChainImages.data());\n\n swapChainImageFormat = surfaceFormat.format;\n swapChainExtent = extent;\n }\n\n void createImageViews() {\n swapChainImageViews.resize(swapChainImages.size());\n for (size_t i = 0; i < swapChainImages.size(); i++) {\n VkImageViewCreateInfo createInfo{};\n createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;\n createInfo.image = swapChainImages[i];\n createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;\n createInfo.format = swapChainImageFormat;\n createInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;\n createInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;\n createInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;\n createInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;\n createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;\n createInfo.subresourceRange.baseMipLevel = 0;\n createInfo.subresourceRange.levelCount = 1;\n createInfo.subresourceRange.baseArrayLayer = 0;\n createInfo.subresourceRange.layerCount = 1;\n\n if (vkCreateImageView(device, &createInfo, nullptr, &swapChainImageViews[i]) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to create image views!\");\n }\n }\n }\n\n void createRenderPass() {\n VkAttachmentDescription colorAttachment{};\n colorAttachment.format = swapChainImageFormat;\n colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;\n colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;\n colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;\n colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;\n colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;\n colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;\n colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;\n\n VkAttachmentReference colorAttachmentRef{};\n colorAttachmentRef.attachment = 0;\n colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;\n\n VkSubpassDescription subpass{};\n subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;\n subpass.colorAttachmentCount = 1;\n subpass.pColorAttachments = &colorAttachmentRef;\n\n VkSubpassDependency dependency{};\n dependency.srcSubpass = VK_SUBPASS_EXTERNAL;\n dependency.dstSubpass = 0;\n dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;\n dependency.srcAccessMask = 0;\n dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;\n dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;\n\n VkRenderPassCreateInfo renderPassInfo{};\n renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;\n renderPassInfo.attachmentCount = 1;\n renderPassInfo.pAttachments = &colorAttachment;\n renderPassInfo.subpassCount = 1;\n renderPassInfo.pSubpasses = &subpass;\n renderPassInfo.dependencyCount = 1;\n renderPassInfo.pDependencies = &dependency;\n\n if (vkCreateRenderPass(device, &renderPassInfo, nullptr, &renderPass) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to create render pass!\");\n }\n }\n\n void createFramebuffers() {\n swapChainFramebuffers.resize(swapChainImageViews.size());\n for (size_t i = 0; i < swapChainImageViews.size(); i++) {\n VkImageView attachments[] = {\n swapChainImageViews[i]\n };\n\n VkFramebufferCreateInfo framebufferInfo{};\n framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;\n framebufferInfo.renderPass = renderPass;\n framebufferInfo.attachmentCount = 1;\n framebufferInfo.pAttachments = attachments;\n framebufferInfo.width = swapChainExtent.width;\n framebufferInfo.height = swapChainExtent.height;\n framebufferInfo.layers = 1;\n\n if (vkCreateFramebuffer(device, &framebufferInfo, nullptr, &swapChainFramebuffers[i]) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to create framebuffer!\");\n }\n }\n }\n\n void createCommandPool() {\n QueueFamilyIndices queueFamilyIndices = findQueueFamilies(physicalDevice);\n VkCommandPoolCreateInfo poolInfo{};\n poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;\n poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;\n poolInfo.queueFamilyIndex = queueFamilyIndices.graphicsFamily.value();\n\n if (vkCreateCommandPool(device, &poolInfo, nullptr, &commandPool) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to create command pool!\");\n }\n }\n\n void createCommandBuffer() {\n VkCommandBufferAllocateInfo allocInfo{};\n allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;\n allocInfo.commandPool = commandPool;\n allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;\n allocInfo.commandBufferCount = 1;\n\n if (vkAllocateCommandBuffers(device, &allocInfo, &commandBuffer) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to allocate command buffers!\");\n }\n }\n\n void createSyncObjects() {\n VkSemaphoreCreateInfo semaphoreInfo{};\n semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;\n\n VkFenceCreateInfo fenceInfo{};\n fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;\n fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;\n\n if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &imageAvailableSemaphore) != VK_SUCCESS ||\n vkCreateSemaphore(device, &semaphoreInfo, nullptr, &renderFinishedSemaphore) != VK_SUCCESS ||\n vkCreateFence(device, &fenceInfo, nullptr, &inFlightFence) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to create synchronization objects!\");\n }\n }\n\n void drawFrame() {\n vkWaitForFences(device, 1, &inFlightFence, VK_TRUE, UINT64_MAX);\n vkResetFences(device, 1, &inFlightFence);\n\n uint32_t imageIndex;\n vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, imageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex);\n\n vkResetCommandBuffer(commandBuffer, /*VkCommandBufferResetFlagBits*/ 0);\n recordCommandBuffer(commandBuffer, imageIndex);\n\n VkSubmitInfo submitInfo{};\n submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;\n\n VkSemaphore waitSemaphores[] = {imageAvailableSemaphore};\n VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};\n submitInfo.waitSemaphoreCount = 1;\n submitInfo.pWaitSemaphores = waitSemaphores;\n submitInfo.pWaitDstStageMask = waitStages;\n\n submitInfo.commandBufferCount = 1;\n submitInfo.pCommandBuffers = &commandBuffer;\n\n VkSemaphore signalSemaphores[] = {renderFinishedSemaphore};\n submitInfo.signalSemaphoreCount = 1;\n submitInfo.pSignalSemaphores = signalSemaphores;\n\n if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFence) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to submit draw command buffer!\");\n }\n\n VkPresentInfoKHR presentInfo{};\n presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;\n\n presentInfo.waitSemaphoreCount = 1;\n presentInfo.pWaitSemaphores = signalSemaphores;\n\n VkSwapchainKHR swapChains[] = {swapChain};\n presentInfo.swapchainCount = 1;\n presentInfo.pSwapchains = swapChains;\n presentInfo.pImageIndices = &imageIndex;\n\n vkQueuePresentKHR(presentQueue, &presentInfo);\n }\n\n void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {\n VkCommandBufferBeginInfo beginInfo{};\n beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;\n\n if (vkBeginCommandBuffer(commandBuffer, &beginInfo) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to begin recording command buffer!\");\n }\n\n VkRenderPassBeginInfo renderPassInfo{};\n renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;\n renderPassInfo.renderPass = renderPass;\n renderPassInfo.framebuffer = swapChainFramebuffers[imageIndex];\n renderPassInfo.renderArea.offset = {0, 0};\n renderPassInfo.renderArea.extent = swapChainExtent;\n\n // Cycle colors\n static float time = 0.0f;\n time += 0.01f;\n float r = (sin(time) + 1.0f) / 2.0f;\n float g = (cos(time) + 1.0f) / 2.0f;\n float b = (sin(time + 3.14f) + 1.0f) / 2.0f;\n\n VkClearValue clearColor = {{{r, g, b, 1.0f}}};\n renderPassInfo.clearValueCount = 1;\n renderPassInfo.pClearValues = &clearColor;\n\n vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);\n vkCmdEndRenderPass(commandBuffer);\n\n if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) {\n throw std::runtime_error(\"failed to record command buffer!\");\n }\n }\n\n bool isDeviceSuitable(VkPhysicalDevice device) {\n QueueFamilyIndices indices = findQueueFamilies(device);\n bool extensionsSupported = checkDeviceExtensionSupport(device);\n bool swapChainAdequate = false;\n if (extensionsSupported) {\n SwapChainSupportDetails swapChainSupport = querySwapChainSupport(device);\n swapChainAdequate = !swapChainSupport.formats.empty() && !swapChainSupport.presentModes.empty();\n }\n return indices.isComplete() && extensionsSupported && swapChainAdequate;\n }\n\n bool checkDeviceExtensionSupport(VkPhysicalDevice device) {\n uint32_t extensionCount;\n vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr);\n std::vector availableExtensions(extensionCount);\n vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, availableExtensions.data());\n\n std::set requiredExtensions(deviceExtensions.begin(), deviceExtensions.end());\n \n // Add portability subset if required (checked during creation, but here we just check standard ones)\n // For simple check we only check what we requested.\n\n for (const auto& extension : availableExtensions) {\n requiredExtensions.erase(extension.extensionName);\n }\n\n return requiredExtensions.empty();\n }\n\n QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device) {\n QueueFamilyIndices indices;\n uint32_t queueFamilyCount = 0;\n vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr);\n std::vector queueFamilies(queueFamilyCount);\n vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, queueFamilies.data());\n\n int i = 0;\n for (const auto& queueFamily : queueFamilies) {\n if (queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) {\n indices.graphicsFamily = i;\n }\n VkBool32 presentSupport = false;\n vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport);\n if (presentSupport) {\n indices.presentFamily = i;\n }\n if (indices.isComplete()) {\n break;\n }\n i++;\n }\n return indices;\n }\n\n SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device) {\n SwapChainSupportDetails details;\n vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities);\n uint32_t formatCount;\n vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);\n if (formatCount != 0) {\n details.formats.resize(formatCount);\n vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, details.formats.data());\n }\n uint32_t presentModeCount;\n vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, nullptr);\n if (presentModeCount != 0) {\n details.presentModes.resize(presentModeCount);\n vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, details.presentModes.data());\n }\n return details;\n }\n\n VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector& availableFormats) {\n for (const auto& availableFormat : availableFormats) {\n if (availableFormat.format == VK_FORMAT_B8G8R8A8_SRGB && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {\n return availableFormat;\n }\n }\n return availableFormats[0];\n }\n\n VkPresentModeKHR chooseSwapPresentMode(const std::vector& availablePresentModes) {\n for (const auto& availablePresentMode : availablePresentModes) {\n if (availablePresentMode == VK_PRESENT_MODE_MAILBOX_KHR) {\n return availablePresentMode;\n }\n }\n return VK_PRESENT_MODE_FIFO_KHR;\n }\n\n VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities) {\n if (capabilities.currentExtent.width != UINT32_MAX) {\n return capabilities.currentExtent;\n } else {\n int width, height;\n glfwGetFramebufferSize(window, &width, &height);\n VkExtent2D actualExtent = {\n static_cast(width),\n static_cast(height)\n };\n actualExtent.width = std::clamp(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);\n actualExtent.height = std::clamp(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);\n return actualExtent;\n }\n }\n\n bool checkValidationLayerSupport() {\n uint32_t layerCount;\n vkEnumerateInstanceLayerProperties(&layerCount, nullptr);\n std::vector availableLayers(layerCount);\n vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());\n for (const char* layerName : validationLayers) {\n bool layerFound = false;\n for (const auto& layerProperties : availableLayers) {\n if (strcmp(layerName, layerProperties.layerName) == 0) {\n layerFound = true;\n break;\n }\n }\n if (!layerFound) {\n return false;\n }\n }\n return true;\n }\n};\n\nint main() {\n HelloVulkanApplication app;\n try {\n app.run();\n } catch (const std::exception& e) {\n std::cerr << e.what() << std::endl;\n return EXIT_FAILURE;\n }\n return EXIT_SUCCESS;\n}\n", "language": "cpp", "highlightedCode": "
#define GLFW_INCLUDE_VULKAN\n#include <GLFW/glfw3.h>\n\n#include <iostream>\n#include <stdexcept>\n#include <cstdlib>\n#include <vector>\n#include <cstring>\n#include <optional>\n#include <set>\n#include <algorithm>\n#include <cmath>\n\nconst uint32_t WIDTH = 800;\nconst uint32_t HEIGHT = 600;\n\nconst std::vector<const char*> deviceExtensions = {\n    VK_KHR_SWAPCHAIN_EXTENSION_NAME\n};\n\n#ifdef NDEBUG\nconst bool enableValidationLayers = false;\n#else\nconst bool enableValidationLayers = true;\n#endif\n\nconst std::vector<const char*> validationLayers = {\n    \"VK_LAYER_KHRONOS_validation\"\n};\n\nstruct QueueFamilyIndices {\n    std::optional<uint32_t> graphicsFamily;\n    std::optional<uint32_t> presentFamily;\n\n    bool isComplete() {\n        return graphicsFamily.has_value() && presentFamily.has_value();\n    }\n};\n\nstruct SwapChainSupportDetails {\n    VkSurfaceCapabilitiesKHR capabilities;\n    std::vector<VkSurfaceFormatKHR> formats;\n    std::vector<VkPresentModeKHR> presentModes;\n};\n\nclass HelloVulkanApplication {\npublic:\n    void run() {\n        initWindow();\n        initVulkan();\n        mainLoop();\n        cleanup();\n    }\n\nprivate:\n    GLFWwindow* window;\n\n    VkInstance instance;\n    VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;\n    VkDevice device;\n    VkQueue graphicsQueue;\n    VkQueue presentQueue;\n    VkSurfaceKHR surface;\n\n    VkSwapchainKHR swapChain;\n    std::vector<VkImage> swapChainImages;\n    VkFormat swapChainImageFormat;\n    VkExtent2D swapChainExtent;\n    std::vector<VkImageView> swapChainImageViews;\n    std::vector<VkFramebuffer> swapChainFramebuffers;\n\n    VkRenderPass renderPass;\n    VkCommandPool commandPool;\n    VkCommandBuffer commandBuffer;\n\n    VkSemaphore imageAvailableSemaphore;\n    VkSemaphore renderFinishedSemaphore;\n    VkFence inFlightFence;\n\n    void initWindow() {\n        glfwInit();\n        glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);\n        glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);\n        window = glfwCreateWindow(WIDTH, HEIGHT, \"Vulkan\", nullptr, nullptr);\n    }\n\n    void initVulkan() {\n        createInstance();\n        createSurface();\n        pickPhysicalDevice();\n        createLogicalDevice();\n        createSwapChain();\n        createImageViews();\n        createRenderPass();\n        createFramebuffers();\n        createCommandPool();\n        createCommandBuffer();\n        createSyncObjects();\n    }\n\n    void mainLoop() {\n        while (!glfwWindowShouldClose(window)) {\n            glfwPollEvents();\n            drawFrame();\n        }\n        vkDeviceWaitIdle(device);\n    }\n\n    void cleanup() {\n        vkDestroySemaphore(device, renderFinishedSemaphore, nullptr);\n        vkDestroySemaphore(device, imageAvailableSemaphore, nullptr);\n        vkDestroyFence(device, inFlightFence, nullptr);\n\n        vkDestroyCommandPool(device, commandPool, nullptr);\n\n        for (auto framebuffer : swapChainFramebuffers) {\n            vkDestroyFramebuffer(device, framebuffer, nullptr);\n        }\n\n        vkDestroyRenderPass(device, renderPass, nullptr);\n\n        for (auto imageView : swapChainImageViews) {\n            vkDestroyImageView(device, imageView, nullptr);\n        }\n\n        vkDestroySwapchainKHR(device, swapChain, nullptr);\n        vkDestroyDevice(device, nullptr);\n        vkDestroySurfaceKHR(instance, surface, nullptr);\n        vkDestroyInstance(instance, nullptr);\n        glfwDestroyWindow(window);\n        glfwTerminate();\n    }\n\n    void createInstance() {\n        if (enableValidationLayers && !checkValidationLayerSupport()) {\n            throw std::runtime_error(\"validation layers requested, but not available!\");\n        }\n\n        VkApplicationInfo appInfo{};\n        appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;\n        appInfo.pApplicationName = \"Hello Vulkan\";\n        appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);\n        appInfo.pEngineName = \"No Engine\";\n        appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);\n        appInfo.apiVersion = VK_API_VERSION_1_0;\n\n        VkInstanceCreateInfo createInfo{};\n        createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;\n        createInfo.pApplicationInfo = &appInfo;\n\n        uint32_t glfwExtensionCount = 0;\n        const char** glfwExtensions;\n        glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);\n\n        std::vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);\n        if (enableValidationLayers) {\n            extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);\n        }\n        // MacOS compatibility\n        extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);\n        createInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;\n\n        createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());\n        createInfo.ppEnabledExtensionNames = extensions.data();\n\n        if (enableValidationLayers) {\n            createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());\n            createInfo.ppEnabledLayerNames = validationLayers.data();\n        } else {\n            createInfo.enabledLayerCount = 0;\n        }\n\n        if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) {\n            throw std::runtime_error(\"failed to create instance!\");\n        }\n    }\n\n    void createSurface() {\n        if (glfwCreateWindowSurface(instance, window, nullptr, &surface) != VK_SUCCESS) {\n            throw std::runtime_error(\"failed to create window surface!\");\n        }\n    }\n\n    void pickPhysicalDevice() {\n        uint32_t deviceCount = 0;\n        vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);\n        if (deviceCount == 0) {\n            throw std::runtime_error(\"failed to find GPUs with Vulkan support!\");\n        }\n        std::vector<VkPhysicalDevice> devices(deviceCount);\n        vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data());\n        for (const auto& device : devices) {\n            if (isDeviceSuitable(device)) {\n                physicalDevice = device;\n                break;\n            }\n        }\n        if (physicalDevice == VK_NULL_HANDLE) {\n            throw std::runtime_error(\"failed to find a suitable GPU!\");\n        }\n    }\n\n    void createLogicalDevice() {\n        QueueFamilyIndices indices = findQueueFamilies(physicalDevice);\n\n        std::vector<VkDeviceQueueCreateInfo> queueCreateInfos;\n        std::set<uint32_t> uniqueQueueFamilies = {indices.graphicsFamily.value(), indices.presentFamily.value()};\n\n        float queuePriority = 1.0f;\n        for (uint32_t queueFamily : uniqueQueueFamilies) {\n            VkDeviceQueueCreateInfo queueCreateInfo{};\n            queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;\n            queueCreateInfo.queueFamilyIndex = queueFamily;\n            queueCreateInfo.queueCount = 1;\n            queueCreateInfo.pQueuePriorities = &queuePriority;\n            queueCreateInfos.push_back(queueCreateInfo);\n        }\n\n        VkDeviceCreateInfo createInfo{};\n        createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;\n        createInfo.queueCreateInfoCount = static_cast<uint32_t>(queueCreateInfos.size());\n        createInfo.pQueueCreateInfos = queueCreateInfos.data();\n        createInfo.enabledExtensionCount = static_cast<uint32_t>(deviceExtensions.size());\n        createInfo.ppEnabledExtensionNames = deviceExtensions.data();\n        \n        // MacOS/MoltenVK compatibility\n        std::vector<const char*> extensions = deviceExtensions;\n        extensions.push_back(\"VK_KHR_portability_subset\");\n        createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());\n        createInfo.ppEnabledExtensionNames = extensions.data();\n\n        if (vkCreateDevice(physicalDevice, &createInfo, nullptr, &device) != VK_SUCCESS) {\n            // Fallback without portability subset if failed (e.g. not on macos)\n             createInfo.enabledExtensionCount = static_cast<uint32_t>(deviceExtensions.size());\n             createInfo.ppEnabledExtensionNames = deviceExtensions.data();\n             if (vkCreateDevice(physicalDevice, &createInfo, nullptr, &device) != VK_SUCCESS) {\n                throw std::runtime_error(\"failed to create logical device!\");\n             }\n        }\n\n        vkGetDeviceQueue(device, indices.graphicsFamily.value(), 0, &graphicsQueue);\n        vkGetDeviceQueue(device, indices.presentFamily.value(), 0, &presentQueue);\n    }\n\n    void createSwapChain() {\n        SwapChainSupportDetails swapChainSupport = querySwapChainSupport(physicalDevice);\n        VkSurfaceFormatKHR surfaceFormat = chooseSwapSurfaceFormat(swapChainSupport.formats);\n        VkPresentModeKHR presentMode = chooseSwapPresentMode(swapChainSupport.presentModes);\n        VkExtent2D extent = chooseSwapExtent(swapChainSupport.capabilities);\n\n        uint32_t imageCount = swapChainSupport.capabilities.minImageCount + 1;\n        if (swapChainSupport.capabilities.maxImageCount > 0 && imageCount > swapChainSupport.capabilities.maxImageCount) {\n            imageCount = swapChainSupport.capabilities.maxImageCount;\n        }\n\n        VkSwapchainCreateInfoKHR createInfo{};\n        createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;\n        createInfo.surface = surface;\n        createInfo.minImageCount = imageCount;\n        createInfo.imageFormat = surfaceFormat.format;\n        createInfo.imageColorSpace = surfaceFormat.colorSpace;\n        createInfo.imageExtent = extent;\n        createInfo.imageArrayLayers = 1;\n        createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;\n\n        QueueFamilyIndices indices = findQueueFamilies(physicalDevice);\n        uint32_t queueFamilyIndices[] = {indices.graphicsFamily.value(), indices.presentFamily.value()};\n\n        if (indices.graphicsFamily != indices.presentFamily) {\n            createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;\n            createInfo.queueFamilyIndexCount = 2;\n            createInfo.pQueueFamilyIndices = queueFamilyIndices;\n        } else {\n            createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;\n        }\n\n        createInfo.preTransform = swapChainSupport.capabilities.currentTransform;\n        createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;\n        createInfo.presentMode = presentMode;\n        createInfo.clipped = VK_TRUE;\n        createInfo.oldSwapchain = VK_NULL_HANDLE;\n\n        if (vkCreateSwapchainKHR(device, &createInfo, nullptr, &swapChain) != VK_SUCCESS) {\n            throw std::runtime_error(\"failed to create swap chain!\");\n        }\n\n        vkGetSwapchainImagesKHR(device, swapChain, &imageCount, nullptr);\n        swapChainImages.resize(imageCount);\n        vkGetSwapchainImagesKHR(device, swapChain, &imageCount, swapChainImages.data());\n\n        swapChainImageFormat = surfaceFormat.format;\n        swapChainExtent = extent;\n    }\n\n    void createImageViews() {\n        swapChainImageViews.resize(swapChainImages.size());\n        for (size_t i = 0; i < swapChainImages.size(); i++) {\n            VkImageViewCreateInfo createInfo{};\n            createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;\n            createInfo.image = swapChainImages[i];\n            createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;\n            createInfo.format = swapChainImageFormat;\n            createInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;\n            createInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;\n            createInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;\n            createInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;\n            createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;\n            createInfo.subresourceRange.baseMipLevel = 0;\n            createInfo.subresourceRange.levelCount = 1;\n            createInfo.subresourceRange.baseArrayLayer = 0;\n            createInfo.subresourceRange.layerCount = 1;\n\n            if (vkCreateImageView(device, &createInfo, nullptr, &swapChainImageViews[i]) != VK_SUCCESS) {\n                throw std::runtime_error(\"failed to create image views!\");\n            }\n        }\n    }\n\n    void createRenderPass() {\n        VkAttachmentDescription colorAttachment{};\n        colorAttachment.format = swapChainImageFormat;\n        colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;\n        colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;\n        colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;\n        colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;\n        colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;\n        colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;\n        colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;\n\n        VkAttachmentReference colorAttachmentRef{};\n        colorAttachmentRef.attachment = 0;\n        colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;\n\n        VkSubpassDescription subpass{};\n        subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;\n        subpass.colorAttachmentCount = 1;\n        subpass.pColorAttachments = &colorAttachmentRef;\n\n        VkSubpassDependency dependency{};\n        dependency.srcSubpass = VK_SUBPASS_EXTERNAL;\n        dependency.dstSubpass = 0;\n        dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;\n        dependency.srcAccessMask = 0;\n        dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;\n        dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;\n\n        VkRenderPassCreateInfo renderPassInfo{};\n        renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;\n        renderPassInfo.attachmentCount = 1;\n        renderPassInfo.pAttachments = &colorAttachment;\n        renderPassInfo.subpassCount = 1;\n        renderPassInfo.pSubpasses = &subpass;\n        renderPassInfo.dependencyCount = 1;\n        renderPassInfo.pDependencies = &dependency;\n\n        if (vkCreateRenderPass(device, &renderPassInfo, nullptr, &renderPass) != VK_SUCCESS) {\n            throw std::runtime_error(\"failed to create render pass!\");\n        }\n    }\n\n    void createFramebuffers() {\n        swapChainFramebuffers.resize(swapChainImageViews.size());\n        for (size_t i = 0; i < swapChainImageViews.size(); i++) {\n            VkImageView attachments[] = {\n                swapChainImageViews[i]\n            };\n\n            VkFramebufferCreateInfo framebufferInfo{};\n            framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;\n            framebufferInfo.renderPass = renderPass;\n            framebufferInfo.attachmentCount = 1;\n            framebufferInfo.pAttachments = attachments;\n            framebufferInfo.width = swapChainExtent.width;\n            framebufferInfo.height = swapChainExtent.height;\n            framebufferInfo.layers = 1;\n\n            if (vkCreateFramebuffer(device, &framebufferInfo, nullptr, &swapChainFramebuffers[i]) != VK_SUCCESS) {\n                throw std::runtime_error(\"failed to create framebuffer!\");\n            }\n        }\n    }\n\n    void createCommandPool() {\n        QueueFamilyIndices queueFamilyIndices = findQueueFamilies(physicalDevice);\n        VkCommandPoolCreateInfo poolInfo{};\n        poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;\n        poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;\n        poolInfo.queueFamilyIndex = queueFamilyIndices.graphicsFamily.value();\n\n        if (vkCreateCommandPool(device, &poolInfo, nullptr, &commandPool) != VK_SUCCESS) {\n            throw std::runtime_error(\"failed to create command pool!\");\n        }\n    }\n\n    void createCommandBuffer() {\n        VkCommandBufferAllocateInfo allocInfo{};\n        allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;\n        allocInfo.commandPool = commandPool;\n        allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;\n        allocInfo.commandBufferCount = 1;\n\n        if (vkAllocateCommandBuffers(device, &allocInfo, &commandBuffer) != VK_SUCCESS) {\n            throw std::runtime_error(\"failed to allocate command buffers!\");\n        }\n    }\n\n    void createSyncObjects() {\n        VkSemaphoreCreateInfo semaphoreInfo{};\n        semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;\n\n        VkFenceCreateInfo fenceInfo{};\n        fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;\n        fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;\n\n        if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &imageAvailableSemaphore) != VK_SUCCESS ||\n            vkCreateSemaphore(device, &semaphoreInfo, nullptr, &renderFinishedSemaphore) != VK_SUCCESS ||\n            vkCreateFence(device, &fenceInfo, nullptr, &inFlightFence) != VK_SUCCESS) {\n            throw std::runtime_error(\"failed to create synchronization objects!\");\n        }\n    }\n\n    void drawFrame() {\n        vkWaitForFences(device, 1, &inFlightFence, VK_TRUE, UINT64_MAX);\n        vkResetFences(device, 1, &inFlightFence);\n\n        uint32_t imageIndex;\n        vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, imageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex);\n\n        vkResetCommandBuffer(commandBuffer, /*VkCommandBufferResetFlagBits*/ 0);\n        recordCommandBuffer(commandBuffer, imageIndex);\n\n        VkSubmitInfo submitInfo{};\n        submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;\n\n        VkSemaphore waitSemaphores[] = {imageAvailableSemaphore};\n        VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};\n        submitInfo.waitSemaphoreCount = 1;\n        submitInfo.pWaitSemaphores = waitSemaphores;\n        submitInfo.pWaitDstStageMask = waitStages;\n\n        submitInfo.commandBufferCount = 1;\n        submitInfo.pCommandBuffers = &commandBuffer;\n\n        VkSemaphore signalSemaphores[] = {renderFinishedSemaphore};\n        submitInfo.signalSemaphoreCount = 1;\n        submitInfo.pSignalSemaphores = signalSemaphores;\n\n        if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFence) != VK_SUCCESS) {\n            throw std::runtime_error(\"failed to submit draw command buffer!\");\n        }\n\n        VkPresentInfoKHR presentInfo{};\n        presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;\n\n        presentInfo.waitSemaphoreCount = 1;\n        presentInfo.pWaitSemaphores = signalSemaphores;\n\n        VkSwapchainKHR swapChains[] = {swapChain};\n        presentInfo.swapchainCount = 1;\n        presentInfo.pSwapchains = swapChains;\n        presentInfo.pImageIndices = &imageIndex;\n\n        vkQueuePresentKHR(presentQueue, &presentInfo);\n    }\n\n    void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {\n        VkCommandBufferBeginInfo beginInfo{};\n        beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;\n\n        if (vkBeginCommandBuffer(commandBuffer, &beginInfo) != VK_SUCCESS) {\n            throw std::runtime_error(\"failed to begin recording command buffer!\");\n        }\n\n        VkRenderPassBeginInfo renderPassInfo{};\n        renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;\n        renderPassInfo.renderPass = renderPass;\n        renderPassInfo.framebuffer = swapChainFramebuffers[imageIndex];\n        renderPassInfo.renderArea.offset = {0, 0};\n        renderPassInfo.renderArea.extent = swapChainExtent;\n\n        // Cycle colors\n        static float time = 0.0f;\n        time += 0.01f;\n        float r = (sin(time) + 1.0f) / 2.0f;\n        float g = (cos(time) + 1.0f) / 2.0f;\n        float b = (sin(time + 3.14f) + 1.0f) / 2.0f;\n\n        VkClearValue clearColor = {{{r, g, b, 1.0f}}};\n        renderPassInfo.clearValueCount = 1;\n        renderPassInfo.pClearValues = &clearColor;\n\n        vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);\n        vkCmdEndRenderPass(commandBuffer);\n\n        if (vkEndCommandBuffer(commandBuffer) != VK_SUCCESS) {\n            throw std::runtime_error(\"failed to record command buffer!\");\n        }\n    }\n\n    bool isDeviceSuitable(VkPhysicalDevice device) {\n        QueueFamilyIndices indices = findQueueFamilies(device);\n        bool extensionsSupported = checkDeviceExtensionSupport(device);\n        bool swapChainAdequate = false;\n        if (extensionsSupported) {\n            SwapChainSupportDetails swapChainSupport = querySwapChainSupport(device);\n            swapChainAdequate = !swapChainSupport.formats.empty() && !swapChainSupport.presentModes.empty();\n        }\n        return indices.isComplete() && extensionsSupported && swapChainAdequate;\n    }\n\n    bool checkDeviceExtensionSupport(VkPhysicalDevice device) {\n        uint32_t extensionCount;\n        vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr);\n        std::vector<VkExtensionProperties> availableExtensions(extensionCount);\n        vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, availableExtensions.data());\n\n        std::set<std::string> requiredExtensions(deviceExtensions.begin(), deviceExtensions.end());\n        \n        // Add portability subset if required (checked during creation, but here we just check standard ones)\n        // For simple check we only check what we requested.\n\n        for (const auto& extension : availableExtensions) {\n            requiredExtensions.erase(extension.extensionName);\n        }\n\n        return requiredExtensions.empty();\n    }\n\n    QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device) {\n        QueueFamilyIndices indices;\n        uint32_t queueFamilyCount = 0;\n        vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr);\n        std::vector<VkQueueFamilyProperties> queueFamilies(queueFamilyCount);\n        vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, queueFamilies.data());\n\n        int i = 0;\n        for (const auto& queueFamily : queueFamilies) {\n            if (queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) {\n                indices.graphicsFamily = i;\n            }\n            VkBool32 presentSupport = false;\n            vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport);\n            if (presentSupport) {\n                indices.presentFamily = i;\n            }\n            if (indices.isComplete()) {\n                break;\n            }\n            i++;\n        }\n        return indices;\n    }\n\n    SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device) {\n        SwapChainSupportDetails details;\n        vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities);\n        uint32_t formatCount;\n        vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);\n        if (formatCount != 0) {\n            details.formats.resize(formatCount);\n            vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, details.formats.data());\n        }\n        uint32_t presentModeCount;\n        vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, nullptr);\n        if (presentModeCount != 0) {\n            details.presentModes.resize(presentModeCount);\n            vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, details.presentModes.data());\n        }\n        return details;\n    }\n\n    VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats) {\n        for (const auto& availableFormat : availableFormats) {\n            if (availableFormat.format == VK_FORMAT_B8G8R8A8_SRGB && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {\n                return availableFormat;\n            }\n        }\n        return availableFormats[0];\n    }\n\n    VkPresentModeKHR chooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes) {\n        for (const auto& availablePresentMode : availablePresentModes) {\n            if (availablePresentMode == VK_PRESENT_MODE_MAILBOX_KHR) {\n                return availablePresentMode;\n            }\n        }\n        return VK_PRESENT_MODE_FIFO_KHR;\n    }\n\n    VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities) {\n        if (capabilities.currentExtent.width != UINT32_MAX) {\n            return capabilities.currentExtent;\n        } else {\n            int width, height;\n            glfwGetFramebufferSize(window, &width, &height);\n            VkExtent2D actualExtent = {\n                static_cast<uint32_t>(width),\n                static_cast<uint32_t>(height)\n            };\n            actualExtent.width = std::clamp(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);\n            actualExtent.height = std::clamp(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);\n            return actualExtent;\n        }\n    }\n\n    bool checkValidationLayerSupport() {\n        uint32_t layerCount;\n        vkEnumerateInstanceLayerProperties(&layerCount, nullptr);\n        std::vector<VkLayerProperties> availableLayers(layerCount);\n        vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());\n        for (const char* layerName : validationLayers) {\n            bool layerFound = false;\n            for (const auto& layerProperties : availableLayers) {\n                if (strcmp(layerName, layerProperties.layerName) == 0) {\n                    layerFound = true;\n                    break;\n                }\n            }\n            if (!layerFound) {\n                return false;\n            }\n        }\n        return true;\n    }\n};\n\nint main() {\n    HelloVulkanApplication app;\n    try {\n        app.run();\n    } catch (const std::exception& e) {\n        std::cerr << e.what() << std::endl;\n        return EXIT_FAILURE;\n    }\n    return EXIT_SUCCESS;\n}\n
" } ], "examples/cpp/graphics/sdl": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"libsdl2\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.c\")\n add_packages(\"libsdl2\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"libsdl2\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.c\")\n    add_packages(\"libsdl2\")\n
" }, { "name": "src/main.c", "code": "#include \n#include \n\nint main(int argc, char* args[]) {\n SDL_Window* window = NULL;\n SDL_Surface* screenSurface = NULL;\n\n if (SDL_Init(SDL_INIT_VIDEO) < 0) {\n printf(\"SDL could not initialize! SDL_Error: %s\\n\", SDL_GetError());\n } else {\n window = SDL_CreateWindow(\"SDL Tutorial\", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);\n if (window == NULL) {\n printf(\"Window could not be created! SDL_Error: %s\\n\", SDL_GetError());\n } else {\n screenSurface = SDL_GetWindowSurface(window);\n\n SDL_Event e;\n int quit = 0;\n int x = 0;\n int y = 0;\n int dx = 2;\n int dy = 2;\n\n while (!quit) {\n while (SDL_PollEvent(&e)) {\n if (e.type == SDL_QUIT) {\n quit = 1;\n }\n }\n\n // Update position\n x += dx;\n y += dy;\n\n // Bounce off walls\n if (x < 0 || x > 640 - 50) dx = -dx;\n if (y < 0 || y > 480 - 50) dy = -dy;\n\n // Fill the surface white\n SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));\n\n // Draw a red rectangle\n SDL_Rect rect;\n rect.x = x;\n rect.y = y;\n rect.w = 50;\n rect.h = 50;\n SDL_FillRect(screenSurface, &rect, SDL_MapRGB(screenSurface->format, 0xFF, 0x00, 0x00));\n\n SDL_UpdateWindowSurface(window);\n SDL_Delay(10);\n }\n }\n }\n SDL_DestroyWindow(window);\n SDL_Quit();\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <SDL.h>\n#include <stdio.h>\n\nint main(int argc, char* args[]) {\n    SDL_Window* window = NULL;\n    SDL_Surface* screenSurface = NULL;\n\n    if (SDL_Init(SDL_INIT_VIDEO) < 0) {\n        printf(\"SDL could not initialize! SDL_Error: %s\\n\", SDL_GetError());\n    } else {\n        window = SDL_CreateWindow(\"SDL Tutorial\", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);\n        if (window == NULL) {\n            printf(\"Window could not be created! SDL_Error: %s\\n\", SDL_GetError());\n        } else {\n            screenSurface = SDL_GetWindowSurface(window);\n\n            SDL_Event e;\n            int quit = 0;\n            int x = 0;\n            int y = 0;\n            int dx = 2;\n            int dy = 2;\n\n            while (!quit) {\n                while (SDL_PollEvent(&e)) {\n                    if (e.type == SDL_QUIT) {\n                        quit = 1;\n                    }\n                }\n\n                // Update position\n                x += dx;\n                y += dy;\n\n                // Bounce off walls\n                if (x < 0 || x > 640 - 50) dx = -dx;\n                if (y < 0 || y > 480 - 50) dy = -dy;\n\n                // Fill the surface white\n                SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));\n\n                // Draw a red rectangle\n                SDL_Rect rect;\n                rect.x = x;\n                rect.y = y;\n                rect.w = 50;\n                rect.h = 50;\n                SDL_FillRect(screenSurface, &rect, SDL_MapRGB(screenSurface->format, 0xFF, 0x00, 0x00));\n\n                SDL_UpdateWindowSurface(window);\n                SDL_Delay(10);\n            }\n        }\n    }\n    SDL_DestroyWindow(window);\n    SDL_Quit();\n    return 0;\n}\n
" } ], "examples/cpp/graphics/raylib": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"raylib\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_packages(\"raylib\")\n set_languages(\"c++11\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"raylib\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"raylib\")\n    set_languages(\"c++11\")\n
" }, { "name": "src/main.cpp", "code": "#include \"raylib.h\"\n\nint main(void) {\n const int screenWidth = 800;\n const int screenHeight = 450;\n\n InitWindow(screenWidth, screenHeight, \"raylib [core] example - basic window\");\n\n SetTargetFPS(60);\n\n while (!WindowShouldClose()) {\n BeginDrawing();\n\n ClearBackground(RAYWHITE);\n DrawText(\"Congrats! You created your first window!\", 190, 200, 20, LIGHTGRAY);\n\n EndDrawing();\n }\n\n CloseWindow();\n\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include \"raylib.h\"\n\nint main(void) {\n    const int screenWidth = 800;\n    const int screenHeight = 450;\n\n    InitWindow(screenWidth, screenHeight, \"raylib [core] example - basic window\");\n\n    SetTargetFPS(60);\n\n    while (!WindowShouldClose()) {\n        BeginDrawing();\n\n            ClearBackground(RAYWHITE);\n            DrawText(\"Congrats! You created your first window!\", 190, 200, 20, LIGHTGRAY);\n\n        EndDrawing();\n    }\n\n    CloseWindow();\n\n    return 0;\n}\n
" } ], "examples/cpp/graphics/opengl": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"glfw\")\nadd_requires(\"opengl\", {optional = true})\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_packages(\"glfw\", \"opengl\")\n set_languages(\"c++11\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"glfw\")\nadd_requires(\"opengl\", {optional = true})\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"glfw\", \"opengl\")\n    set_languages(\"c++11\")\n
" }, { "name": "src/main.cpp", "code": "#if defined(__APPLE__)\n#include \n#else\n#include \n#endif\n#include \n\nint main(void) {\n GLFWwindow* window;\n\n /* Initialize the library */\n if (!glfwInit())\n return -1;\n\n /* Create a windowed mode window and its OpenGL context */\n window = glfwCreateWindow(640, 480, \"Hello World\", NULL, NULL);\n if (!window) {\n glfwTerminate();\n return -1;\n }\n\n /* Make the window's context current */\n glfwMakeContextCurrent(window);\n\n /* Loop until the user closes the window */\n while (!glfwWindowShouldClose(window)) {\n /* Render here */\n glClear(GL_COLOR_BUFFER_BIT);\n\n glBegin(GL_TRIANGLES);\n glColor3f(1.0f, 0.0f, 0.0f);\n glVertex2f(-0.6f, -0.4f);\n glColor3f(0.0f, 1.0f, 0.0f);\n glVertex2f(0.6f, -0.4f);\n glColor3f(0.0f, 0.0f, 1.0f);\n glVertex2f(0.0f, 0.6f);\n glEnd();\n\n /* Swap front and back buffers */\n glfwSwapBuffers(window);\n\n /* Poll for and process events */\n glfwPollEvents();\n }\n\n glfwTerminate();\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#if defined(__APPLE__)\n#include <OpenGL/gl.h>\n#else\n#include <GL/gl.h>\n#endif\n#include <GLFW/glfw3.h>\n\nint main(void) {\n    GLFWwindow* window;\n\n    /* Initialize the library */\n    if (!glfwInit())\n        return -1;\n\n    /* Create a windowed mode window and its OpenGL context */\n    window = glfwCreateWindow(640, 480, \"Hello World\", NULL, NULL);\n    if (!window) {\n        glfwTerminate();\n        return -1;\n    }\n\n    /* Make the window's context current */\n    glfwMakeContextCurrent(window);\n\n    /* Loop until the user closes the window */\n    while (!glfwWindowShouldClose(window)) {\n        /* Render here */\n        glClear(GL_COLOR_BUFFER_BIT);\n\n        glBegin(GL_TRIANGLES);\n        glColor3f(1.0f, 0.0f, 0.0f);\n        glVertex2f(-0.6f, -0.4f);\n        glColor3f(0.0f, 1.0f, 0.0f);\n        glVertex2f(0.6f, -0.4f);\n        glColor3f(0.0f, 0.0f, 1.0f);\n        glVertex2f(0.0f, 0.6f);\n        glEnd();\n\n        /* Swap front and back buffers */\n        glfwSwapBuffers(window);\n\n        /* Poll for and process events */\n        glfwPollEvents();\n    }\n\n    glfwTerminate();\n    return 0;\n}\n
" } ], "examples/cpp/graphics/metal_app": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"metal_app\")\n add_rules(\"xcode.application\")\n add_includedirs(\"Renderer\")\n add_frameworks(\"MetalKit\")\n add_mflags(\"-fmodules\")\n add_files(\"Renderer/*.m\", \"Renderer/*.metal\")\n add_files(\"Application/main.m\")\n add_files(\"Application/AAPLViewController.m\")\n add_files(\"Application/macOS/Info.plist\")\n add_files(\"Application/macOS/Base.lproj/*.storyboard\")\n add_defines(\"TARGET_MACOS\")\n add_frameworks(\"AppKit\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"metal_app\")\n    add_rules(\"xcode.application\")\n    add_includedirs(\"Renderer\")\n    add_frameworks(\"MetalKit\")\n    add_mflags(\"-fmodules\")\n    add_files(\"Renderer/*.m\", \"Renderer/*.metal\")\n    add_files(\"Application/main.m\")\n    add_files(\"Application/AAPLViewController.m\")\n    add_files(\"Application/macOS/Info.plist\")\n    add_files(\"Application/macOS/Base.lproj/*.storyboard\")\n    add_defines(\"TARGET_MACOS\")\n    add_frameworks(\"AppKit\")\n
" }, { "name": "Application/AAPLViewController.h", "code": "/*\nSee LICENSE folder for this sample’s licensing information.\n\nAbstract:\nHeader for our our cross-platform view controller\n*/\n\n#if defined(TARGET_IOS) || defined(TARGET_TVOS)\n@import UIKit;\n#define PlatformViewController UIViewController\n#else\n@import AppKit;\n#define PlatformViewController NSViewController\n#endif\n\n@import MetalKit;\n\n#import \"AAPLRenderer.h\"\n\n// Our view controller\n@interface AAPLViewController : PlatformViewController\n\n@end\n", "language": "cpp", "highlightedCode": "
/*\nSee LICENSE folder for this sample’s licensing information.\n\nAbstract:\nHeader for our our cross-platform view controller\n*/\n\n#if defined(TARGET_IOS) || defined(TARGET_TVOS)\n@import UIKit;\n#define PlatformViewController UIViewController\n#else\n@import AppKit;\n#define PlatformViewController NSViewController\n#endif\n\n@import MetalKit;\n\n#import \"AAPLRenderer.h\"\n\n// Our view controller\n@interface AAPLViewController : PlatformViewController\n\n@end\n
" }, { "name": "Application/AAPLViewController.m", "code": "/*\nSee LICENSE folder for this sample’s licensing information.\n\nAbstract:\nImplementation of our cross-platform view controller\n*/\n\n#import \"AAPLViewController.h\"\n#import \"AAPLRenderer.h\"\n\n@implementation AAPLViewController\n{\n MTKView *_view;\n\n AAPLRenderer *_renderer;\n}\n\n- (void)viewDidLoad\n{\n [super viewDidLoad];\n\n // Set the view to use the default device\n _view = (MTKView *)self.view;\n\n _view.device = MTLCreateSystemDefaultDevice();\n\n NSAssert(_view.device, @\"Metal is not supported on this device\");\n\n _renderer = [[AAPLRenderer alloc] initWithMetalKitView:_view];\n\n NSAssert(_renderer, @\"Renderer failed initialization\");\n\n // Initialize our renderer with the view size\n [_renderer mtkView:_view drawableSizeWillChange:_view.drawableSize];\n\n _view.delegate = _renderer;\n}\n\n@end\n", "language": "text" }, { "name": "Application/macOS/Base.lproj/Main.storyboard", "code": "\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \tDefault\n \n \n \n \n \n \n \tLeft to Right\n \n \n \n \n \n \n \tRight to Left\n \n \n \n \n \n \n \n \n \n \n \tDefault\n \n \n \n \n \n \n \tLeft to Right\n \n \n \n \n \n \n \tRight to Left\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", "language": "text" }, { "name": "Application/macOS/Info.plist", "code": "\n\n\n\n\tCFBundleDevelopmentRegion\n\ten\n\tCFBundleExecutable\n\t$(EXECUTABLE_NAME)\n\tCFBundleIconFile\n\t\n\tCFBundleIdentifier\n\t$(PRODUCT_BUNDLE_IDENTIFIER)\n\tCFBundleInfoDictionaryVersion\n\t6.0\n\tCFBundleName\n\t$(PRODUCT_NAME)\n\tCFBundlePackageType\n\tAPPL\n\tCFBundleShortVersionString\n\t1.0\n\tCFBundleVersion\n\t1\n\tLSMinimumSystemVersion\n\t$(MACOSX_DEPLOYMENT_TARGET)\n\tNSMainStoryboardFile\n\tMain\n\tNSPrincipalClass\n\tNSApplication\n\n\n", "language": "text" }, { "name": "Application/main.m", "code": "/*\nSee LICENSE folder for this sample’s licensing information.\n\nAbstract:\nApplication entry point for all platforms\n*/\n\n#if defined(TARGET_IOS) || defined(TARGET_TVOS)\n#import \n#import \n#import \n#import \"AAPLAppDelegate.h\"\n#else\n#import \n#endif\n\n#if defined(TARGET_IOS) || defined(TARGET_TVOS)\n\nint main(int argc, char * argv[]) {\n\n#if TARGET_OS_SIMULATOR && (!defined(__IPHONE_13_0) || !defined(__TVOS_13_0))\n#error No simulator support for Metal API for this SDK version. Must build for a device\n#endif\n\n @autoreleasepool {\n return UIApplicationMain(argc, argv, nil, NSStringFromClass([AAPLAppDelegate class]));\n }\n}\n\n#elif defined(TARGET_MACOS)\n\nint main(int argc, const char * argv[]) {\n return NSApplicationMain(argc, argv);\n}\n\n#endif\n", "language": "text" }, { "name": "Renderer/AAPLRenderer.h", "code": "/*\nSee LICENSE folder for this sample’s licensing information.\n\nAbstract:\nHeader for a platform independent renderer class, which performs Metal setup and per frame rendering.\n*/\n\n@import MetalKit;\n\n@interface AAPLRenderer : NSObject\n\n- (nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)mtkView;\n\n@end\n", "language": "cpp", "highlightedCode": "
/*\nSee LICENSE folder for this sample’s licensing information.\n\nAbstract:\nHeader for a platform independent renderer class, which performs Metal setup and per frame rendering.\n*/\n\n@import MetalKit;\n\n@interface AAPLRenderer : NSObject<MTKViewDelegate>\n\n- (nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)mtkView;\n\n@end\n
" }, { "name": "Renderer/AAPLRenderer.m", "code": "/*\nSee LICENSE folder for this sample’s licensing information.\n\nAbstract:\nImplementation of a platform independent renderer class, which performs Metal setup and per frame rendering\n*/\n\n@import simd;\n@import MetalKit;\n\n#import \"AAPLRenderer.h\"\n\n// Header shared between C code here, which executes Metal API commands, and .metal files, which\n// uses these types as inputs to the shaders.\n#import \"AAPLShaderTypes.h\"\n\n// Main class performing the rendering\n@implementation AAPLRenderer\n{\n id _device;\n\n // The render pipeline generated from the vertex and fragment shaders in the .metal shader file.\n id _pipelineState;\n\n // The command queue used to pass commands to the device.\n id _commandQueue;\n\n // The current size of the view, used as an input to the vertex shader.\n vector_uint2 _viewportSize;\n}\n\n- (nonnull instancetype)initWithMetalKitView:(nonnull MTKView *)mtkView\n{\n self = [super init];\n if(self)\n {\n NSError *error;\n\n _device = mtkView.device;\n\n // Load all the shader files with a .metal file extension in the project.\n id defaultLibrary = [_device newDefaultLibrary];\n\n id vertexFunction = [defaultLibrary newFunctionWithName:@\"vertexShader\"];\n id fragmentFunction = [defaultLibrary newFunctionWithName:@\"fragmentShader\"];\n\n // Configure a pipeline descriptor that is used to create a pipeline state.\n MTLRenderPipelineDescriptor *pipelineStateDescriptor = [[MTLRenderPipelineDescriptor alloc] init];\n pipelineStateDescriptor.label = @\"Simple Pipeline\";\n pipelineStateDescriptor.vertexFunction = vertexFunction;\n pipelineStateDescriptor.fragmentFunction = fragmentFunction;\n pipelineStateDescriptor.colorAttachments[0].pixelFormat = mtkView.colorPixelFormat;\n\n _pipelineState = [_device newRenderPipelineStateWithDescriptor:pipelineStateDescriptor\n error:&error];\n\n // Pipeline State creation could fail if the pipeline descriptor isn't set up properly.\n // If the Metal API validation is enabled, you can find out more information about what\n // went wrong. (Metal API validation is enabled by default when a debug build is run\n // from Xcode.)\n NSAssert(_pipelineState, @\"Failed to create pipeline state: %@\", error);\n\n // Create the command queue\n _commandQueue = [_device newCommandQueue];\n }\n\n return self;\n}\n\n/// Called whenever view changes orientation or is resized\n- (void)mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size\n{\n // Save the size of the drawable to pass to the vertex shader.\n _viewportSize.x = size.width;\n _viewportSize.y = size.height;\n}\n\n/// Called whenever the view needs to render a frame.\n- (void)drawInMTKView:(nonnull MTKView *)view\n{\n static const AAPLVertex triangleVertices[] =\n {\n // 2D positions, RGBA colors\n { { 250, -250 }, { 1, 0, 0, 1 } },\n { { -250, -250 }, { 0, 1, 0, 1 } },\n { { 0, 250 }, { 0, 0, 1, 1 } },\n };\n\n // Create a new command buffer for each render pass to the current drawable.\n id commandBuffer = [_commandQueue commandBuffer];\n commandBuffer.label = @\"MyCommand\";\n\n // Obtain a renderPassDescriptor generated from the view's drawable textures.\n MTLRenderPassDescriptor *renderPassDescriptor = view.currentRenderPassDescriptor;\n\n if(renderPassDescriptor != nil)\n {\n // Create a render command encoder.\n id renderEncoder =\n [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];\n renderEncoder.label = @\"MyRenderEncoder\";\n\n // Set the region of the drawable to draw into.\n [renderEncoder setViewport:(MTLViewport){0.0, 0.0, _viewportSize.x, _viewportSize.y, 0.0, 1.0 }];\n\n [renderEncoder setRenderPipelineState:_pipelineState];\n\n // Pass in the parameter data.\n [renderEncoder setVertexBytes:triangleVertices\n length:sizeof(triangleVertices)\n atIndex:AAPLVertexInputIndexVertices];\n\n [renderEncoder setVertexBytes:&_viewportSize\n length:sizeof(_viewportSize)\n atIndex:AAPLVertexInputIndexViewportSize];\n\n // Draw the triangle.\n [renderEncoder drawPrimitives:MTLPrimitiveTypeTriangle\n vertexStart:0\n vertexCount:3];\n\n [renderEncoder endEncoding];\n\n // Schedule a present once the framebuffer is complete using the current drawable.\n [commandBuffer presentDrawable:view.currentDrawable];\n }\n\n // Finalize rendering here & push the command buffer to the GPU.\n [commandBuffer commit];\n}\n\n@end\n", "language": "text" }, { "name": "Renderer/AAPLShaders.metal", "code": "/*\nSee LICENSE folder for this sample’s licensing information.\n\nAbstract:\nMetal shaders used for this sample\n*/\n\n#include \n\nusing namespace metal;\n\n// Include header shared between this Metal shader code and C code executing Metal API commands.\n#include \"AAPLShaderTypes.h\"\n\n// Vertex shader outputs and fragment shader inputs\nstruct RasterizerData\n{\n // The [[position]] attribute of this member indicates that this value\n // is the clip space position of the vertex when this structure is\n // returned from the vertex function.\n float4 position [[position]];\n\n // Since this member does not have a special attribute, the rasterizer\n // interpolates its value with the values of the other triangle vertices\n // and then passes the interpolated value to the fragment shader for each\n // fragment in the triangle.\n float4 color;\n};\n\nvertex RasterizerData\nvertexShader(uint vertexID [[vertex_id]],\n constant AAPLVertex *vertices [[buffer(AAPLVertexInputIndexVertices)]],\n constant vector_uint2 *viewportSizePointer [[buffer(AAPLVertexInputIndexViewportSize)]])\n{\n RasterizerData out;\n\n // Index into the array of positions to get the current vertex.\n // The positions are specified in pixel dimensions (i.e. a value of 100\n // is 100 pixels from the origin).\n float2 pixelSpacePosition = vertices[vertexID].position.xy;\n\n // Get the viewport size and cast to float.\n vector_float2 viewportSize = vector_float2(*viewportSizePointer);\n \n\n // To convert from positions in pixel space to positions in clip-space,\n // divide the pixel coordinates by half the size of the viewport.\n out.position = vector_float4(0.0, 0.0, 0.0, 1.0);\n out.position.xy = pixelSpacePosition / (viewportSize / 2.0);\n\n // Pass the input color directly to the rasterizer.\n out.color = vertices[vertexID].color;\n\n return out;\n}\n\nfragment float4 fragmentShader(RasterizerData in [[stage_in]])\n{\n // Return the interpolated color.\n return in.color;\n}\n\n", "language": "text" }, { "name": "Renderer/AAPLShaderTypes.h", "code": "/*\nSee LICENSE folder for this sample’s licensing information.\n\nAbstract:\nHeader containing types and enum constants shared between Metal shaders and C/ObjC source\n*/\n\n#ifndef AAPLShaderTypes_h\n#define AAPLShaderTypes_h\n\n#include \n\n// Buffer index values shared between shader and C code to ensure Metal shader buffer inputs\n// match Metal API buffer set calls.\ntypedef enum AAPLVertexInputIndex\n{\n AAPLVertexInputIndexVertices = 0,\n AAPLVertexInputIndexViewportSize = 1,\n} AAPLVertexInputIndex;\n\n// This structure defines the layout of vertices sent to the vertex\n// shader. This header is shared between the .metal shader and C code, to guarantee that\n// the layout of the vertex array in the C code matches the layout that the .metal\n// vertex shader expects.\ntypedef struct\n{\n vector_float2 position;\n vector_float4 color;\n} AAPLVertex;\n\n#endif /* AAPLShaderTypes_h */\n", "language": "cpp", "highlightedCode": "
/*\nSee LICENSE folder for this sample’s licensing information.\n\nAbstract:\nHeader containing types and enum constants shared between Metal shaders and C/ObjC source\n*/\n\n#ifndef AAPLShaderTypes_h\n#define AAPLShaderTypes_h\n\n#include <simd/simd.h>\n\n// Buffer index values shared between shader and C code to ensure Metal shader buffer inputs\n// match Metal API buffer set calls.\ntypedef enum AAPLVertexInputIndex\n{\n    AAPLVertexInputIndexVertices     = 0,\n    AAPLVertexInputIndexViewportSize = 1,\n} AAPLVertexInputIndex;\n\n//  This structure defines the layout of vertices sent to the vertex\n//  shader. This header is shared between the .metal shader and C code, to guarantee that\n//  the layout of the vertex array in the C code matches the layout that the .metal\n//  vertex shader expects.\ntypedef struct\n{\n    vector_float2 position;\n    vector_float4 color;\n} AAPLVertex;\n\n#endif /* AAPLShaderTypes_h */\n
" } ], "examples/cpp/graphics/mac_app": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"mac_app\")\n add_rules(\"xcode.application\")\n add_files(\"src/*.m\")\n add_files(\"src/Info.plist\")\n add_frameworks(\"Cocoa\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"mac_app\")\n    add_rules(\"xcode.application\")\n    add_files(\"src/*.m\")\n    add_files(\"src/Info.plist\")\n    add_frameworks(\"Cocoa\")\n
" }, { "name": "src/Info.plist", "code": "\n\n\n\n CFBundleDevelopmentRegion\n en\n CFBundleExecutable\n $(EXECUTABLE_NAME)\n CFBundleIdentifier\n com.example.mac-app\n CFBundleInfoDictionaryVersion\n 6.0\n CFBundleName\n $(PRODUCT_NAME)\n CFBundlePackageType\n APPL\n CFBundleShortVersionString\n 1.0\n CFBundleVersion\n 1\n LSMinimumSystemVersion\n 10.15\n NSPrincipalClass\n NSApplication\n\n\n", "language": "text" }, { "name": "src/main.m", "code": "#import \n\n@interface AppDelegate : NSObject \n@property (strong, nonatomic) NSWindow *window;\n@end\n\n@implementation AppDelegate\n\n- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {\n NSRect frame = NSMakeRect(0, 0, 480, 320);\n NSUInteger style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable | NSWindowStyleMaskMiniaturizable;\n self.window = [[NSWindow alloc] initWithContentRect:frame styleMask:style backing:NSBackingStoreBuffered defer:NO];\n [self.window setTitle:@\"Hello Mac App\"];\n [self.window makeKeyAndOrderFront:nil];\n [self.window center];\n}\n\n- (void)applicationWillTerminate:(NSNotification *)aNotification {\n}\n\n- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {\n return YES;\n}\n\n@end\n\nint main(int argc, const char * argv[]) {\n @autoreleasepool {\n NSApplication *app = [NSApplication sharedApplication];\n AppDelegate *delegate = [[AppDelegate alloc] init];\n [app setDelegate:delegate];\n [app run];\n }\n return 0;\n}\n", "language": "text" } ], "examples/cpp/graphics/ios_app": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"ios_app\")\n add_rules(\"xcode.application\")\n add_files(\"src/*.m\")\n add_files(\"src/Info.plist\")\n add_frameworks(\"UIKit\", \"Foundation\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"ios_app\")\n    add_rules(\"xcode.application\")\n    add_files(\"src/*.m\")\n    add_files(\"src/Info.plist\")\n    add_frameworks(\"UIKit\", \"Foundation\")\n
" }, { "name": "src/Info.plist", "code": "\n\n\n\n CFBundleDevelopmentRegion\n en\n CFBundleExecutable\n $(EXECUTABLE_NAME)\n CFBundleIdentifier\n com.example.ios-app\n CFBundleInfoDictionaryVersion\n 6.0\n CFBundleName\n $(PRODUCT_NAME)\n CFBundlePackageType\n APPL\n CFBundleShortVersionString\n 1.0\n CFBundleVersion\n 1\n LSRequiresIPhoneOS\n \n UIRequiredDeviceCapabilities\n \n armv7\n \n UISupportedInterfaceOrientations\n \n UIInterfaceOrientationPortrait\n UIInterfaceOrientationLandscapeLeft\n UIInterfaceOrientationLandscapeRight\n \n\n\n", "language": "text" }, { "name": "src/main.m", "code": "#import \n\n@interface ViewController : UIViewController\n@end\n\n@implementation ViewController\n\n- (void)viewDidLoad {\n [super viewDidLoad];\n self.view.backgroundColor = [UIColor redColor];\n \n UILabel *label = [[UILabel alloc] init];\n label.text = @\"Hello iOS App\";\n label.textColor = [UIColor whiteColor];\n label.font = [UIFont systemFontOfSize:24];\n label.translatesAutoresizingMaskIntoConstraints = NO;\n [self.view addSubview:label];\n \n [NSLayoutConstraint activateConstraints:@[\n [label.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],\n [label.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor]\n ]];\n}\n\n@end\n\n@interface AppDelegate : UIResponder \n@property (strong, nonatomic) UIWindow *window;\n@end\n\n@implementation AppDelegate\n\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];\n self.window.rootViewController = [[ViewController alloc] init];\n [self.window makeKeyAndVisible];\n return YES;\n}\n\n@end\n\nint main(int argc, char * argv[]) {\n @autoreleasepool {\n return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));\n }\n}\n", "language": "text" } ], "examples/cpp/graphics/imgui": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"imgui\", {configs = {glfw_opengl3 = true}})\nadd_requires(\"glfw\", \"opengl\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_packages(\"imgui\", \"glfw\", \"opengl\")\n set_languages(\"c++11\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"imgui\", {configs = {glfw_opengl3 = true}})\nadd_requires(\"glfw\", \"opengl\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"imgui\", \"glfw\", \"opengl\")\n    set_languages(\"c++11\")\n
" }, { "name": "src/main.cpp", "code": "#include \"imgui.h\"\n#include \"imgui_impl_glfw.h\"\n#include \"imgui_impl_opengl3.h\"\n#include \n#if defined(IMGUI_IMPL_OPENGL_ES2)\n#include \n#endif\n\n#if defined(__APPLE__)\n#include \n#else\n#include \n#endif\n\n#include // Will drag system OpenGL headers\n\n#if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS)\n#pragma comment(lib, \"legacy_stdio_definitions\")\n#endif\n\nstatic void glfw_error_callback(int error, const char* description)\n{\n fprintf(stderr, \"Glfw Error %d: %s\\n\", error, description);\n}\n\nint main(int, char**)\n{\n // Setup window\n glfwSetErrorCallback(glfw_error_callback);\n if (!glfwInit())\n return 1;\n\n // Decide GL+GLSL versions\n#if defined(IMGUI_IMPL_OPENGL_ES2)\n // GL ES 2.0 + GLSL 100\n const char* glsl_version = \"#version 100\";\n glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);\n glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);\n glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);\n#elif defined(__APPLE__)\n // GL 3.2 + GLSL 150\n const char* glsl_version = \"#version 150\";\n glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);\n glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);\n glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only\n glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac\n#else\n // GL 3.0 + GLSL 130\n const char* glsl_version = \"#version 130\";\n glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);\n glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);\n //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only\n //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only\n#endif\n\n // Create window with graphics context\n GLFWwindow* window = glfwCreateWindow(1280, 720, \"Dear ImGui GLFW+OpenGL3 example\", NULL, NULL);\n if (window == NULL)\n return 1;\n glfwMakeContextCurrent(window);\n glfwSwapInterval(1); // Enable vsync\n\n // Setup Dear ImGui context\n IMGUI_CHECKVERSION();\n ImGui::CreateContext();\n ImGuiIO& io = ImGui::GetIO(); (void)io;\n io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls\n io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls\n\n // Setup Dear ImGui style\n ImGui::StyleColorsDark();\n //ImGui::StyleColorsClassic();\n\n // Setup Platform/Renderer backends\n ImGui_ImplGlfw_InitForOpenGL(window, true);\n ImGui_ImplOpenGL3_Init(glsl_version);\n\n // Our state\n bool show_demo_window = true;\n bool show_another_window = false;\n ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);\n\n // Main loop\n while (!glfwWindowShouldClose(window))\n {\n // Poll and handle events (inputs, window resize, etc.)\n // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.\n // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.\n // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.\n // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.\n glfwPollEvents();\n\n // Start the Dear ImGui frame\n ImGui_ImplOpenGL3_NewFrame();\n ImGui_ImplGlfw_NewFrame();\n ImGui::NewFrame();\n\n // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).\n if (show_demo_window)\n ImGui::ShowDemoWindow(&show_demo_window);\n\n // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.\n {\n static float f = 0.0f;\n static int counter = 0;\n\n ImGui::Begin(\"Hello, world!\"); // Create a window called \"Hello, world!\" and append into it.\n\n ImGui::Text(\"This is some useful text.\"); // Display some text (you can use a format strings too)\n ImGui::Checkbox(\"Demo Window\", &show_demo_window); // Edit bools storing our window open/close state\n ImGui::Checkbox(\"Another Window\", &show_another_window);\n\n ImGui::SliderFloat(\"float\", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f\n ImGui::ColorEdit3(\"clear color\", (float*)&clear_color); // Edit 3 floats representing a color\n\n if (ImGui::Button(\"Button\")) // Buttons return true when clicked (most widgets return true when edited/activated)\n counter++;\n ImGui::SameLine();\n ImGui::Text(\"counter = %d\", counter);\n\n ImGui::Text(\"Application average %.3f ms/frame (%.1f FPS)\", 1000.0f / io.Framerate, io.Framerate);\n ImGui::End();\n }\n\n // 3. Show another simple window.\n if (show_another_window)\n {\n ImGui::Begin(\"Another Window\", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)\n ImGui::Text(\"Hello from another window!\");\n if (ImGui::Button(\"Close Me\"))\n show_another_window = false;\n ImGui::End();\n }\n\n // Rendering\n ImGui::Render();\n int display_w, display_h;\n glfwGetFramebufferSize(window, &display_w, &display_h);\n glViewport(0, 0, display_w, display_h);\n glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);\n glClear(GL_COLOR_BUFFER_BIT);\n ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());\n\n glfwSwapBuffers(window);\n }\n\n // Cleanup\n ImGui_ImplOpenGL3_Shutdown();\n ImGui_ImplGlfw_Shutdown();\n ImGui::DestroyContext();\n\n glfwDestroyWindow(window);\n glfwTerminate();\n\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include \"imgui.h\"\n#include \"imgui_impl_glfw.h\"\n#include \"imgui_impl_opengl3.h\"\n#include <stdio.h>\n#if defined(IMGUI_IMPL_OPENGL_ES2)\n#include <GLES2/gl2.h>\n#endif\n\n#if defined(__APPLE__)\n#include <OpenGL/gl.h>\n#else\n#include <GL/gl.h>\n#endif\n\n#include <GLFW/glfw3.h> // Will drag system OpenGL headers\n\n#if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS)\n#pragma comment(lib, \"legacy_stdio_definitions\")\n#endif\n\nstatic void glfw_error_callback(int error, const char* description)\n{\n    fprintf(stderr, \"Glfw Error %d: %s\\n\", error, description);\n}\n\nint main(int, char**)\n{\n    // Setup window\n    glfwSetErrorCallback(glfw_error_callback);\n    if (!glfwInit())\n        return 1;\n\n    // Decide GL+GLSL versions\n#if defined(IMGUI_IMPL_OPENGL_ES2)\n    // GL ES 2.0 + GLSL 100\n    const char* glsl_version = \"#version 100\";\n    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);\n    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);\n    glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);\n#elif defined(__APPLE__)\n    // GL 3.2 + GLSL 150\n    const char* glsl_version = \"#version 150\";\n    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);\n    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);\n    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);  // 3.2+ only\n    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);            // Required on Mac\n#else\n    // GL 3.0 + GLSL 130\n    const char* glsl_version = \"#version 130\";\n    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);\n    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);\n    //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);  // 3.2+ only\n    //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);            // 3.0+ only\n#endif\n\n    // Create window with graphics context\n    GLFWwindow* window = glfwCreateWindow(1280, 720, \"Dear ImGui GLFW+OpenGL3 example\", NULL, NULL);\n    if (window == NULL)\n        return 1;\n    glfwMakeContextCurrent(window);\n    glfwSwapInterval(1); // Enable vsync\n\n    // Setup Dear ImGui context\n    IMGUI_CHECKVERSION();\n    ImGui::CreateContext();\n    ImGuiIO& io = ImGui::GetIO(); (void)io;\n    io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;     // Enable Keyboard Controls\n    io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;      // Enable Gamepad Controls\n\n    // Setup Dear ImGui style\n    ImGui::StyleColorsDark();\n    //ImGui::StyleColorsClassic();\n\n    // Setup Platform/Renderer backends\n    ImGui_ImplGlfw_InitForOpenGL(window, true);\n    ImGui_ImplOpenGL3_Init(glsl_version);\n\n    // Our state\n    bool show_demo_window = true;\n    bool show_another_window = false;\n    ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);\n\n    // Main loop\n    while (!glfwWindowShouldClose(window))\n    {\n        // Poll and handle events (inputs, window resize, etc.)\n        // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.\n        // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.\n        // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.\n        // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.\n        glfwPollEvents();\n\n        // Start the Dear ImGui frame\n        ImGui_ImplOpenGL3_NewFrame();\n        ImGui_ImplGlfw_NewFrame();\n        ImGui::NewFrame();\n\n        // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).\n        if (show_demo_window)\n            ImGui::ShowDemoWindow(&show_demo_window);\n\n        // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.\n        {\n            static float f = 0.0f;\n            static int counter = 0;\n\n            ImGui::Begin(\"Hello, world!\");                          // Create a window called \"Hello, world!\" and append into it.\n\n            ImGui::Text(\"This is some useful text.\");               // Display some text (you can use a format strings too)\n            ImGui::Checkbox(\"Demo Window\", &show_demo_window);      // Edit bools storing our window open/close state\n            ImGui::Checkbox(\"Another Window\", &show_another_window);\n\n            ImGui::SliderFloat(\"float\", &f, 0.0f, 1.0f);            // Edit 1 float using a slider from 0.0f to 1.0f\n            ImGui::ColorEdit3(\"clear color\", (float*)&clear_color); // Edit 3 floats representing a color\n\n            if (ImGui::Button(\"Button\"))                            // Buttons return true when clicked (most widgets return true when edited/activated)\n                counter++;\n            ImGui::SameLine();\n            ImGui::Text(\"counter = %d\", counter);\n\n            ImGui::Text(\"Application average %.3f ms/frame (%.1f FPS)\", 1000.0f / io.Framerate, io.Framerate);\n            ImGui::End();\n        }\n\n        // 3. Show another simple window.\n        if (show_another_window)\n        {\n            ImGui::Begin(\"Another Window\", &show_another_window);   // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)\n            ImGui::Text(\"Hello from another window!\");\n            if (ImGui::Button(\"Close Me\"))\n                show_another_window = false;\n            ImGui::End();\n        }\n\n        // Rendering\n        ImGui::Render();\n        int display_w, display_h;\n        glfwGetFramebufferSize(window, &display_w, &display_h);\n        glViewport(0, 0, display_w, display_h);\n        glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);\n        glClear(GL_COLOR_BUFFER_BIT);\n        ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());\n\n        glfwSwapBuffers(window);\n    }\n\n    // Cleanup\n    ImGui_ImplOpenGL3_Shutdown();\n    ImGui_ImplGlfw_Shutdown();\n    ImGui::DestroyContext();\n\n    glfwDestroyWindow(window);\n    glfwTerminate();\n\n    return 0;\n}\n
" } ], "examples/c/merge_archive/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"add\")\n set_kind(\"static\")\n add_files(\"src/add.c\")\n\ntarget(\"sub\")\n set_kind(\"static\")\n add_files(\"src/sub.c\")\n\ntarget(\"mul\")\n set_kind(\"static\")\n add_deps(\"add\", \"sub\")\n add_files(\"src/mul.c\")\n set_policy(\"build.merge_archive\", true)\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"add\")\n    set_kind(\"static\")\n    add_files(\"src/add.c\")\n\ntarget(\"sub\")\n    set_kind(\"static\")\n    add_files(\"src/sub.c\")\n\ntarget(\"mul\")\n    set_kind(\"static\")\n    add_deps(\"add\", \"sub\")\n    add_files(\"src/mul.c\")\n    set_policy(\"build.merge_archive\", true)\n
" }, { "name": "src/add.c", "code": "int add(int a, int b) { return a + b; }\n", "language": "cpp", "highlightedCode": "
int add(int a, int b) { return a + b; }\n
" }, { "name": "src/mul.c", "code": "int add(int, int);\nint sub(int, int);\n\nint mul_add_sub(int a, int b) {\n return add(a, b) * sub(a, b);\n}\n", "language": "cpp", "highlightedCode": "
int add(int, int);\nint sub(int, int);\n\nint mul_add_sub(int a, int b) {\n    return add(a, b) * sub(a, b);\n}\n
" }, { "name": "src/sub.c", "code": "int sub(int a, int b) { return a - b; }\n", "language": "cpp", "highlightedCode": "
int sub(int a, int b) { return a - b; }\n
" } ], "examples/c/asn1/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"asn1c\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.c\")\n add_files(\"src/*.asn1\")\n add_rules(\"asn1c\")\n add_packages(\"asn1c\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"asn1c\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.c\")\n    add_files(\"src/*.asn1\")\n    add_rules(\"asn1c\")\n    add_packages(\"asn1c\")\n
" }, { "name": "src/main.c", "code": "#include \n#include \n#include /* This file will be generated by asn1c */\n\nint main(int ac, char **av) {\n Rectangle_t *rect; /* Type defined in Rectangle.h */\n \n rect = calloc(1, sizeof(*rect));\n if(!rect) {\n perror(\"calloc() failed\");\n return 1;\n }\n\n rect->height = 42;\n rect->width = 23;\n\n printf(\"Rectangle: height=%ld, width=%ld\\n\", \n (long)rect->height, (long)rect->width);\n \n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n#include <sys/types.h>\n#include <Rectangle.h> /* This file will be generated by asn1c */\n\nint main(int ac, char **av) {\n    Rectangle_t *rect; /* Type defined in Rectangle.h */\n    \n    rect = calloc(1, sizeof(*rect));\n    if(!rect) {\n        perror(\"calloc() failed\");\n        return 1;\n    }\n\n    rect->height = 42;\n    rect->width  = 23;\n\n    printf(\"Rectangle: height=%ld, width=%ld\\n\", \n           (long)rect->height, (long)rect->width);\n    \n    return 0;\n}\n
" }, { "name": "src/rectangle.asn1", "code": "RectangleModule DEFINITIONS ::= BEGIN\n\nRectangle ::= SEQUENCE {\n height INTEGER,\n width INTEGER\n}\n\nEND\n", "language": "text" } ], "examples/configuration/remote_toolchain/zig": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"zig\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.zig\")\n set_toolchains(\"@zig\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"zig\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.zig\")\n    set_toolchains(\"@zig\")\n
" }, { "name": "src/main.zig", "code": "const std = @import(\"std\");\n\npub fn main() !void {\n std.debug.print(\"Hello, {s}!\\n\", .{\"world\"});\n}\n", "language": "text" } ], "examples/configuration/remote_toolchain/llvm": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"llvm\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.c\")\n set_toolchains(\"@llvm\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"llvm\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.c\")\n    set_toolchains(\"@llvm\")\n
" }, { "name": "src/main.c", "code": "#include \n\nint main(int argc, char** argv) {\n printf(\"hello world!\\n\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n\nint main(int argc, char** argv) {\n    printf(\"hello world!\\n\");\n    return 0;\n}\n
" } ], "examples/c/cosmocc/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"cosmocc\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.c\")\n set_toolchains(\"@cosmocc\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"cosmocc\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.c\")\n    set_toolchains(\"@cosmocc\")\n
" }, { "name": "src/main.c", "code": "#include \n\nint main() {\n printf(\"Hello from Cosmocc!\\n\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n\nint main() {\n    printf(\"Hello from Cosmocc!\\n\");\n    return 0;\n}\n
" } ], "examples/configuration/remote_toolchain/gnu_rm": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"gnu-rm\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.c\")\n set_toolchains(\"@gnu-rm\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"gnu-rm\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.c\")\n    set_toolchains(\"@gnu-rm\")\n
" }, { "name": "src/main.c", "code": "#include \n\nint main(int argc, char** argv) {\n printf(\"hello world!\\n\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n\nint main(int argc, char** argv) {\n    printf(\"hello world!\\n\");\n    return 0;\n}\n
" } ], "examples/configuration/namespace_isolation/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nnamespace(\"ns1\", function ()\n includes(\"src1\")\nend)\n\nnamespace(\"ns2\", function ()\n includes(\"src2\")\nend)\n\ntarget(\"app\")\n set_kind(\"binary\")\n add_deps(\"ns1::lib\", \"ns2::lib\")\n add_files(\"src/main.cpp\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nnamespace(\"ns1\", function ()\n    includes(\"src1\")\nend)\n\nnamespace(\"ns2\", function ()\n    includes(\"src2\")\nend)\n\ntarget(\"app\")\n    set_kind(\"binary\")\n    add_deps(\"ns1::lib\", \"ns2::lib\")\n    add_files(\"src/main.cpp\")\n
" }, { "name": "src/main.cpp", "code": "extern void lib1_hello();\nextern void lib2_hello();\n\nint main(int argc, char** argv) {\n lib1_hello();\n lib2_hello();\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
extern void lib1_hello();\nextern void lib2_hello();\n\nint main(int argc, char** argv) {\n    lib1_hello();\n    lib2_hello();\n    return 0;\n}\n
" }, { "name": "src/test.cpp", "code": "#include \n\nvoid test() {\n std::cout << \"hello from ns1::test!\" << std::endl;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nvoid test() {\n    std::cout << \"hello from ns1::test!\" << std::endl;\n}\n
" }, { "name": "src/xmake.lua", "code": "target(\"test\")\n set_kind(\"static\")\n add_files(\"test.cpp\")\n", "language": "lua", "highlightedCode": "
target(\"test\")\n    set_kind(\"static\")\n    add_files(\"test.cpp\")\n
" }, { "name": "src1/main.cpp", "code": "#include \n\nvoid lib1_hello() {\n std::cout << \"hello from ns1::lib\" << std::endl;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nvoid lib1_hello() {\n    std::cout << \"hello from ns1::lib\" << std::endl;\n}\n
" }, { "name": "src1/xmake.lua", "code": "target(\"lib\")\n set_kind(\"static\")\n add_files(\"main.cpp\")\n add_defines(\"NS1_LIB\")\n", "language": "lua", "highlightedCode": "
target(\"lib\")\n    set_kind(\"static\")\n    add_files(\"main.cpp\")\n    add_defines(\"NS1_LIB\")\n
" }, { "name": "src2/main.cpp", "code": "#include \n\nvoid lib2_hello() {\n std::cout << \"hello from ns2::lib\" << std::endl;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nvoid lib2_hello() {\n    std::cout << \"hello from ns2::lib\" << std::endl;\n}\n
" }, { "name": "src2/xmake.lua", "code": "target(\"lib\")\n set_kind(\"static\")\n add_files(\"main.cpp\")\n add_defines(\"NS2_LIB\")\n", "language": "lua", "highlightedCode": "
target(\"lib\")\n    set_kind(\"static\")\n    add_files(\"main.cpp\")\n    add_defines(\"NS2_LIB\")\n
" } ], "examples/configuration/multi_level_directories/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nincludes(\"src\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nincludes(\"src\")\n
" }, { "name": "src/main.cpp", "code": "#include \n\nint main(int argc, char** argv) {\n std::cout << \"hello world!\" << std::endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nint main(int argc, char** argv) {\n    std::cout << \"hello world!\" << std::endl;\n    return 0;\n}\n
" }, { "name": "src/xmake.lua", "code": "target(\"test\")\n set_kind(\"binary\")\n add_files(\"main.cpp\")\n", "language": "lua", "highlightedCode": "
target(\"test\")\n    set_kind(\"binary\")\n    add_files(\"main.cpp\")\n
" } ], "examples/configuration/custom_toolchain/unknown_toolchain": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_moduledirs(\"xmake/modules\")\nadd_toolchaindirs(\"xmake/toolchains\")\n\nset_toolchains(\"my-c6000\")\n\ntarget(\"test\")\n set_kind(\"static\")\n add_files(\"src/foo.cpp\")\n\ntarget(\"demo\")\n set_kind(\"binary\")\n add_deps(\"test\")\n add_files(\"src/test.cpp\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_moduledirs(\"xmake/modules\")\nadd_toolchaindirs(\"xmake/toolchains\")\n\nset_toolchains(\"my-c6000\")\n\ntarget(\"test\")\n    set_kind(\"static\")\n    add_files(\"src/foo.cpp\")\n\ntarget(\"demo\")\n    set_kind(\"binary\")\n    add_deps(\"test\")\n    add_files(\"src/test.cpp\")\n
" }, { "name": "src/foo.cpp", "code": "void foo() {}\n", "language": "cpp", "highlightedCode": "
void foo() {}\n
" }, { "name": "src/test.cpp", "code": "int main() { return 0; }\n", "language": "cpp", "highlightedCode": "
int main() { return 0; }\n
" }, { "name": "xmake/modules/core/tools/ar6x.lua", "code": "inherit(\"core.tools.ar\")\n\nfunction init(self)\n self:set(\"arflags\", \"-r\")\nend\n", "language": "lua", "highlightedCode": "
inherit(\"core.tools.ar\")\n\nfunction init(self)\n    self:set(\"arflags\", \"-r\")\nend\n
" }, { "name": "xmake/modules/core/tools/cl6x.lua", "code": "import(\"core.base.option\")\nimport(\"core.base.global\")\nimport(\"core.project.policy\")\nimport(\"core.language.language\")\nimport(\"utils.progress\")\n\nfunction init(self)\nend\n\nfunction nf_symbol(self, level)\n local kind = self:kind()\n if language.sourcekinds()[kind] then\n local maps = _g.symbol_maps\n if not maps then\n maps =\n {\n debug = \"-g\"\n }\n _g.symbol_maps = maps\n end\n return maps[level .. '_' .. kind] or maps[level]\n end\nend\n\nfunction nf_optimize(self, level)\n local maps =\n {\n none = \"-O0\"\n , fast = \"-O1\"\n , faster = \"-O2\"\n , fastest = \"-O3\"\n , smallest = \"-m3\"\n , aggressive = \"-O3\"\n }\n return maps[level]\nend\n\nfunction nf_define(self, macro)\n return \"-D\" .. macro\nend\n\nfunction nf_undefine(self, macro)\n return \"-U\" .. macro\nend\n\nfunction nf_includedir(self, dir)\n return {\"-I\" .. dir}\nend\n\nfunction nf_sysincludedir(self, dir)\n return nf_includedir(self, dir)\nend\n\nfunction nf_link(self, lib)\n if not lib:endswith(\".a\") and not lib:endswith(\".so\") then\n lib = \"lib\" .. lib .. \".a\"\n end\n return \"-l\" .. lib\nend\n\nfunction nf_syslink(self, lib)\n return nf_link(self, lib)\nend\n\nfunction nf_linkdir(self, dir)\n return {\"-i\" .. path.translate(dir)}\nend\n", "language": "lua", "highlightedCode": "
import(\"core.base.option\")\nimport(\"core.base.global\")\nimport(\"core.project.policy\")\nimport(\"core.language.language\")\nimport(\"utils.progress\")\n\nfunction init(self)\nend\n\nfunction nf_symbol(self, level)\n    local kind = self:kind()\n    if language.sourcekinds()[kind] then\n        local maps = _g.symbol_maps\n        if not maps then\n            maps =\n            {\n                debug  = \"-g\"\n            }\n            _g.symbol_maps = maps\n        end\n        return maps[level .. '_' .. kind] or maps[level]\n    end\nend\n\nfunction nf_optimize(self, level)\n    local maps =\n    {\n        none       = \"-O0\"\n    ,   fast       = \"-O1\"\n    ,   faster     = \"-O2\"\n    ,   fastest    = \"-O3\"\n    ,   smallest   = \"-m3\"\n    ,   aggressive = \"-O3\"\n    }\n    return maps[level]\nend\n\nfunction nf_define(self, macro)\n    return \"-D\" .. macro\nend\n\nfunction nf_undefine(self, macro)\n    return \"-U\" .. macro\nend\n\nfunction nf_includedir(self, dir)\n    return {\"-I\" .. dir}\nend\n\nfunction nf_sysincludedir(self, dir)\n    return nf_includedir(self, dir)\nend\n\nfunction nf_link(self, lib)\n    if not lib:endswith(\".a\") and not lib:endswith(\".so\") then\n         lib = \"lib\" .. lib .. \".a\"\n    end\n    return \"-l\" .. lib\nend\n\nfunction nf_syslink(self, lib)\n    return nf_link(self, lib)\nend\n\nfunction nf_linkdir(self, dir)\n    return {\"-i\" .. path.translate(dir)}\nend\n
" }, { "name": "xmake/modules/core/tools/cl6x/has_flags.lua", "code": "import(\"core.cache.detectcache\")\nimport(\"core.language.language\")\n\nfunction _islinker(flags, opt)\n local toolkind = opt.toolkind or \"\"\n return toolkind == \"ld\" or toolkind == \"sh\" or toolkind:endswith(\"ld\") or toolkind:endswith(\"sh\")\nend\n\nfunction _try_running(program, argv, opt)\n local errors = nil\n return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or \"\"):trim() end }}, errors\nend\n\nfunction _check_from_knownargs(flags, opt, islinker)\n local flag = flags[1]\n if not islinker then\n if flag:startswith(\"-D\") or\n flag:startswith(\"-U\") or\n flag:startswith(\"-I\") then\n return true\n end\n end\nend\n\nfunction _check_from_arglist(flags, opt, islinker)\n local key = \"core.tools.cl6x.\" .. (islinker and \"has_ldflags\" or \"has_cflags\")\n local flagskey = opt.program .. \"_\" .. (opt.programver or \"\")\n local allflags = detectcache:get2(key, flagskey)\n if not allflags then\n allflags = {}\n local arglist = try {function () return os.iorunv(opt.program, {\"--help\"}, {envs = opt.envs}) end}\n if arglist then\n for arg in arglist:gmatch(\"%s+(%-[%-%a%d]+)%s+\") do\n allflags[arg] = true\n end\n end\n detectcache:set2(key, flagskey, allflags)\n end\n local flag = flags[1]\n return allflags[flag]\nend\n\nfunction _get_extension(opt)\n return (opt.program:endswith(\"++\") or opt.flagkind == \"cxxflags\") and \".cpp\" or (table.wrap(language.sourcekinds()[opt.toolkind or \"cc\"])[1] or \".c\")\nend\n\nfunction _check_try_running(flags, opt, islinker)\n\n local snippet = opt.snippet or \"int main(int argc, char** argv)\\n{return 0;}\\n\"\n local sourcefile = os.tmpfile(\"cl6x_has_flags:\" .. snippet) .. _get_extension(opt)\n if not os.isfile(sourcefile) then\n io.writefile(sourcefile, snippet)\n end\n\n local tmpfile = os.tmpfile()\n if islinker then\n return _try_running(opt.program, table.join(flags, \"-z\", \"--output_file=\" .. tmpfile, sourcefile), opt)\n end\n\n return _try_running(opt.program, table.join(flags, \"-c\", \"--output_file=\" .. tmpfile, sourcefile), opt)\nend\n\nfunction main(flags, opt)\n opt = opt or {}\n local islinker = _islinker(flags, opt)\n if _check_from_knownargs(flags, opt, islinker) then\n return true\n end\n if _check_from_arglist(flags, opt, islinker) then\n return true\n end\n return _check_try_running(flags, opt, islinker)\nend\n", "language": "lua", "highlightedCode": "
import(\"core.cache.detectcache\")\nimport(\"core.language.language\")\n\nfunction _islinker(flags, opt)\n    local toolkind = opt.toolkind or \"\"\n    return toolkind == \"ld\" or toolkind == \"sh\" or toolkind:endswith(\"ld\") or toolkind:endswith(\"sh\")\nend\n\nfunction _try_running(program, argv, opt)\n    local errors = nil\n    return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or \"\"):trim() end }}, errors\nend\n\nfunction _check_from_knownargs(flags, opt, islinker)\n    local flag = flags[1]\n    if not islinker then\n        if flag:startswith(\"-D\") or\n           flag:startswith(\"-U\") or\n           flag:startswith(\"-I\") then\n            return true\n        end\n    end\nend\n\nfunction _check_from_arglist(flags, opt, islinker)\n    local key = \"core.tools.cl6x.\" .. (islinker and \"has_ldflags\" or \"has_cflags\")\n    local flagskey = opt.program .. \"_\" .. (opt.programver or \"\")\n    local allflags = detectcache:get2(key, flagskey)\n    if not allflags then\n        allflags = {}\n        local arglist = try {function () return os.iorunv(opt.program, {\"--help\"}, {envs = opt.envs}) end}\n        if arglist then\n            for arg in arglist:gmatch(\"%s+(%-[%-%a%d]+)%s+\") do\n                allflags[arg] = true\n            end\n        end\n        detectcache:set2(key, flagskey, allflags)\n    end\n    local flag = flags[1]\n    return allflags[flag]\nend\n\nfunction _get_extension(opt)\n    return (opt.program:endswith(\"++\") or opt.flagkind == \"cxxflags\") and \".cpp\" or (table.wrap(language.sourcekinds()[opt.toolkind or \"cc\"])[1] or \".c\")\nend\n\nfunction _check_try_running(flags, opt, islinker)\n\n    local snippet = opt.snippet or \"int main(int argc, char** argv)\\n{return 0;}\\n\"\n    local sourcefile = os.tmpfile(\"cl6x_has_flags:\" .. snippet) .. _get_extension(opt)\n    if not os.isfile(sourcefile) then\n        io.writefile(sourcefile, snippet)\n    end\n\n    local tmpfile = os.tmpfile()\n    if islinker then\n        return _try_running(opt.program, table.join(flags, \"-z\", \"--output_file=\" .. tmpfile, sourcefile), opt)\n    end\n\n    return _try_running(opt.program, table.join(flags, \"-c\", \"--output_file=\" .. tmpfile, sourcefile), opt)\nend\n\nfunction main(flags, opt)\n    opt = opt or {}\n    local islinker = _islinker(flags, opt)\n    if _check_from_knownargs(flags, opt, islinker) then\n        return true\n    end\n    if _check_from_arglist(flags, opt, islinker) then\n        return true\n    end\n    return _check_try_running(flags, opt, islinker)\nend\n
" }, { "name": "xmake/modules/core/tools/cl6x/parse_deps.lua", "code": "import(\"core.project.config\")\nimport(\"core.project.project\")\nimport(\"core.base.hashset\")\n\nfunction _normailize_dep(dep, projectdir)\n if not is_host(\"windows\") then\n dep = dep:gsub(\"\\\\(.)\", \"%1\")\n end\n if path.is_absolute(dep) then\n dep = path.translate(dep)\n else\n dep = path.absolute(dep, projectdir)\n end\n if dep:startswith(projectdir) then\n return path.relative(dep, projectdir)\n else\n return dep\n end\nend\n\nfunction main(depsdata, opt)\n local results = hashset.new()\n local projectdir = os.projectdir()\n local line = depsdata:rtrim()\n local plain = {plain = true}\n for _, includefile in ipairs(line:split('\\n', plain)) do\n includefile = includefile:split(\": \", plain)[2]\n if includefile and #includefile > 0 then\n includefile = _normailize_dep(includefile, projectdir)\n if includefile then\n results:insert(includefile)\n end\n end\n end\n return results:to_array()\nend\n", "language": "lua", "highlightedCode": "
import(\"core.project.config\")\nimport(\"core.project.project\")\nimport(\"core.base.hashset\")\n\nfunction _normailize_dep(dep, projectdir)\n    if not is_host(\"windows\") then\n        dep = dep:gsub(\"\\\\(.)\", \"%1\")\n    end\n    if path.is_absolute(dep) then\n        dep = path.translate(dep)\n    else\n        dep = path.absolute(dep, projectdir)\n    end\n    if dep:startswith(projectdir) then\n        return path.relative(dep, projectdir)\n    else\n        return dep\n    end\nend\n\nfunction main(depsdata, opt)\n    local results = hashset.new()\n    local projectdir = os.projectdir()\n    local line = depsdata:rtrim()\n    local plain = {plain = true}\n    for _, includefile in ipairs(line:split('\\n', plain)) do\n        includefile = includefile:split(\": \", plain)[2]\n        if includefile and #includefile > 0 then\n            includefile = _normailize_dep(includefile, projectdir)\n            if includefile then\n                results:insert(includefile)\n            end\n        end\n    end\n    return results:to_array()\nend\n
" }, { "name": "xmake/modules/detect/tools/find_ar6x.lua", "code": "import(\"lib.detect.find_program\")\nimport(\"lib.detect.find_programver\")\n\nfunction main(opt)\n opt = opt or {}\n opt.check = \"--help\"\n opt.command = \"--help\"\n local program = find_program(opt.program or \"ar6x\", opt)\n local version = nil\n if program and opt.version then\n version = find_programver(program, opt)\n end\n return program, version\nend\n", "language": "lua", "highlightedCode": "
import(\"lib.detect.find_program\")\nimport(\"lib.detect.find_programver\")\n\nfunction main(opt)\n    opt = opt or {}\n    opt.check = \"--help\"\n    opt.command = \"--help\"\n    local program = find_program(opt.program or \"ar6x\", opt)\n    local version = nil\n    if program and opt.version then\n        version = find_programver(program, opt)\n    end\n    return program, version\nend\n
" }, { "name": "xmake/modules/detect/tools/find_cl6x.lua", "code": "import(\"lib.detect.find_program\")\nimport(\"lib.detect.find_programver\")\n\nfunction main(opt)\n opt = opt or {}\n opt.check = \"--help\"\n opt.command = \"--help\"\n local program = find_program(opt.program or \"cl6x\", opt)\n local version = nil\n if program and opt.version then\n version = find_programver(program, opt)\n end\n return program, version\nend\n", "language": "lua", "highlightedCode": "
import(\"lib.detect.find_program\")\nimport(\"lib.detect.find_programver\")\n\nfunction main(opt)\n    opt = opt or {}\n    opt.check = \"--help\"\n    opt.command = \"--help\"\n    local program = find_program(opt.program or \"cl6x\", opt)\n    local version = nil\n    if program and opt.version then\n        version = find_programver(program, opt)\n    end\n    return program, version\nend\n
" }, { "name": "xmake/toolchains/my-c6000/xmake.lua", "code": "toolchain(\"my-c6000\")\n set_kind(\"standalone\")\n set_homepage(\"https://www.ti.com\")\n set_description(\"TI-CGT C6000 compiler\")\n\n set_toolset(\"cc\", \"cl6x\")\n set_toolset(\"cxx\", \"cl6x\")\n set_toolset(\"ld\", \"cl6x\")\n set_toolset(\"sh\", \"cl6x\")\n set_toolset(\"ar\", \"ar6x\")\n set_toolset(\"strip\", \"strip6x\")\n set_toolset(\"as\", \"cl6x\")\n\n on_check(function (toolchain)\n return import(\"lib.detect.find_tool\")(\"cl6x\")\n end)\n\n on_load(function (toolchain)\n toolchain:add(\"cxflags\", \"-Dxxx\")\n end)\n", "language": "lua", "highlightedCode": "
toolchain(\"my-c6000\")\n    set_kind(\"standalone\")\n    set_homepage(\"https://www.ti.com\")\n    set_description(\"TI-CGT C6000 compiler\")\n\n    set_toolset(\"cc\", \"cl6x\")\n    set_toolset(\"cxx\", \"cl6x\")\n    set_toolset(\"ld\", \"cl6x\")\n    set_toolset(\"sh\", \"cl6x\")\n    set_toolset(\"ar\", \"ar6x\")\n    set_toolset(\"strip\", \"strip6x\")\n    set_toolset(\"as\", \"cl6x\")\n\n    on_check(function (toolchain)\n        return import(\"lib.detect.find_tool\")(\"cl6x\")\n    end)\n\n    on_load(function (toolchain)\n        toolchain:add(\"cxflags\", \"-Dxxx\")\n    end)\n
" } ], "examples/configuration/custom_toolchain/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntoolchain(\"myclang\")\n set_kind(\"standalone\")\n set_toolset(\"cc\", \"clang\")\n set_toolset(\"cxx\", \"clang++\")\n set_toolset(\"ld\", \"clang++\")\n on_check(function (toolchain)\n return import(\"lib.detect.find_tool\")(\"clang\")\n end)\n on_load(function (toolchain)\n toolchain:add(\"cxflags\", \"-DTEST_MACRO\")\n end)\ntoolchain_end()\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/main.cpp\")\n set_toolchains(\"myclang\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntoolchain(\"myclang\")\n    set_kind(\"standalone\")\n    set_toolset(\"cc\", \"clang\")\n    set_toolset(\"cxx\", \"clang++\")\n    set_toolset(\"ld\", \"clang++\")\n    on_check(function (toolchain)\n        return import(\"lib.detect.find_tool\")(\"clang\")\n    end)\n    on_load(function (toolchain)\n        toolchain:add(\"cxflags\", \"-DTEST_MACRO\")\n    end)\ntoolchain_end()\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/main.cpp\")\n    set_toolchains(\"myclang\")\n
" }, { "name": "src/main.cpp", "code": "#include \n\nint main(int argc, char** argv) {\n#ifdef TEST_MACRO\n std::cout << \"hello from myclang toolchain!\" << std::endl;\n#else\n std::cout << \"hello world!\" << std::endl;\n#endif\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nint main(int argc, char** argv) {\n#ifdef TEST_MACRO\n    std::cout << \"hello from myclang toolchain!\" << std::endl;\n#else\n    std::cout << \"hello world!\" << std::endl;\n#endif\n    return 0;\n}\n
" } ], "examples/configuration/custom_scope_api/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\n-- register scope apis\ninterp_add_scopeapis(\"myscope.set_name\", \"myscope.add_list\", {kind = \"values\"})\ninterp_add_scopeapis(\"myscope.on_script\", {kind = \"script\"})\n\n-- use myscope\nmyscope(\"hello\")\n set_name(\"foo\")\n add_list(\"value1\", \"value2\")\n on_script(function ()\n print(\"hello\")\n end)\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n on_config(function (target)\n import(\"core.project.project\")\n \n -- get scope data\n local myscope = project.scope(\"myscope\")\n for name, scope in pairs(myscope) do\n print(\"myscope(%s)\", name)\n print(\" name: %s\", scope:get(\"name\"))\n print(\" list: %s\", table.concat(scope:get(\"list\"), \", \"))\n print(\" script:\")\n local script = scope:get(\"script\")\n if script then\n script()\n end\n end\n end)\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\n-- register scope apis\ninterp_add_scopeapis(\"myscope.set_name\", \"myscope.add_list\", {kind = \"values\"})\ninterp_add_scopeapis(\"myscope.on_script\", {kind = \"script\"})\n\n-- use myscope\nmyscope(\"hello\")\n    set_name(\"foo\")\n    add_list(\"value1\", \"value2\")\n    on_script(function ()\n        print(\"hello\")\n    end)\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    on_config(function (target)\n        import(\"core.project.project\")\n        \n        -- get scope data\n        local myscope = project.scope(\"myscope\")\n        for name, scope in pairs(myscope) do\n            print(\"myscope(%s)\", name)\n            print(\"    name: %s\", scope:get(\"name\"))\n            print(\"    list: %s\", table.concat(scope:get(\"list\"), \", \"))\n            print(\"    script:\")\n            local script = scope:get(\"script\")\n            if script then\n                script()\n            end\n        end\n    end)\n
" }, { "name": "src/main.cpp", "code": "#include \n\nusing namespace std;\n\nint main(int argc, char **argv) {\n cout << \"hello world!\" << endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nusing namespace std;\n\nint main(int argc, char **argv) {\n    cout << \"hello world!\" << endl;\n    return 0;\n}\n
" } ], "examples/configuration/custom_rule/basic": [ { "name": "xmake.lua", "code": "rule(\"markdown\")\n set_extensions(\".md\")\n on_build_file(function (target, sourcefile, opt)\n print(\"processing %s\", sourcefile)\n end)\n\ntarget(\"test\")\n set_kind(\"phony\")\n add_files(\"src/*.md\")\n add_rules(\"markdown\")\n", "language": "lua", "highlightedCode": "
rule(\"markdown\")\n    set_extensions(\".md\")\n    on_build_file(function (target, sourcefile, opt)\n        print(\"processing %s\", sourcefile)\n    end)\n\ntarget(\"test\")\n    set_kind(\"phony\")\n    add_files(\"src/*.md\")\n    add_rules(\"markdown\")\n
" }, { "name": "src/test.md", "code": "# Hello\n", "language": "text" } ], "examples/configuration/autogen/simple": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"$(builddir)/autogen.cpp\", {always_added = true})\n before_build(function (target)\n io.writefile(\"$(builddir)/autogen.cpp\", [[\n#include \nusing namespace std;\nint main(int argc, char** argv) {\n cout << \"hello world!\" << endl;\n return 0;\n}\n ]])\n end)\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"$(builddir)/autogen.cpp\", {always_added = true})\n    before_build(function (target)\n        io.writefile(\"$(builddir)/autogen.cpp\", [[\n#include <iostream>\nusing namespace std;\nint main(int argc, char** argv) {\n    cout << \"hello world!\" << endl;\n    return 0;\n}\n        ]])\n    end)\n
" } ], "examples/configuration/autogen/rule": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nrule(\"autogen\")\n set_extensions(\".in\")\n before_buildcmd_file(function (target, batchcmds, sourcefile, opt)\n local sourcefile_cx = path.join(target:autogendir(), \"rules\", \"autogen\", path.basename(sourcefile) .. \".cpp\")\n local objectfile = target:objectfile(sourcefile_cx)\n table.insert(target:objectfiles(), objectfile)\n\n batchcmds:show_progress(opt.progress, \"${color.build.object}compiling.autogen %s\", sourcefile)\n batchcmds:mkdir(path.directory(sourcefile_cx))\n batchcmds:vrunv(target:dep(\"autogen\"):targetfile(), {sourcefile, sourcefile_cx})\n batchcmds:compile(sourcefile_cx, objectfile)\n\n batchcmds:add_depfiles(sourcefile, target:dep(\"autogen\"):targetfile())\n batchcmds:set_depmtime(os.mtime(objectfile))\n batchcmds:set_depcache(target:dependfile(objectfile))\n end)\n\ntarget(\"autogen\")\n set_default(false)\n set_kind(\"binary\")\n set_plat(os.host()) -- generate for host platform\n set_arch(os.arch())\n add_files(\"src/autogen.cpp\")\n set_languages(\"c++11\")\n set_policy(\"build.fence\", true) -- disable parallel build for source files\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_deps(\"autogen\")\n add_rules(\"autogen\")\n add_files(\"src/main.cpp\")\n add_files(\"src/*.in\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nrule(\"autogen\")\n    set_extensions(\".in\")\n    before_buildcmd_file(function (target, batchcmds, sourcefile, opt)\n        local sourcefile_cx = path.join(target:autogendir(), \"rules\", \"autogen\", path.basename(sourcefile) .. \".cpp\")\n        local objectfile = target:objectfile(sourcefile_cx)\n        table.insert(target:objectfiles(), objectfile)\n\n        batchcmds:show_progress(opt.progress, \"${color.build.object}compiling.autogen %s\", sourcefile)\n        batchcmds:mkdir(path.directory(sourcefile_cx))\n        batchcmds:vrunv(target:dep(\"autogen\"):targetfile(), {sourcefile, sourcefile_cx})\n        batchcmds:compile(sourcefile_cx, objectfile)\n\n        batchcmds:add_depfiles(sourcefile, target:dep(\"autogen\"):targetfile())\n        batchcmds:set_depmtime(os.mtime(objectfile))\n        batchcmds:set_depcache(target:dependfile(objectfile))\n    end)\n\ntarget(\"autogen\")\n    set_default(false)\n    set_kind(\"binary\")\n    set_plat(os.host()) -- generate for host platform\n    set_arch(os.arch())\n    add_files(\"src/autogen.cpp\")\n    set_languages(\"c++11\")\n    set_policy(\"build.fence\", true) -- disable parallel build for source files\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_deps(\"autogen\")\n    add_rules(\"autogen\")\n    add_files(\"src/main.cpp\")\n    add_files(\"src/*.in\")\n
" }, { "name": "src/autogen.cpp", "code": "#include \n#include \n#include \n\nint main(int argc, char** argv) {\n if (argc < 3) return 1;\n std::ifstream in(argv[1]);\n std::ofstream out(argv[2]);\n std::string line;\n if (in && out) {\n out << \"#include \\n\";\n out << \"void generated_func() {\\n\";\n while (std::getline(in, line)) {\n out << \" std::cout << \\\"\" << line << \"\\\" << std::endl;\\n\";\n }\n out << \"}\\n\";\n }\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n#include <fstream>\n#include <string>\n\nint main(int argc, char** argv) {\n    if (argc < 3) return 1;\n    std::ifstream in(argv[1]);\n    std::ofstream out(argv[2]);\n    std::string line;\n    if (in && out) {\n        out << \"#include <iostream>\\n\";\n        out << \"void generated_func() {\\n\";\n        while (std::getline(in, line)) {\n            out << \"    std::cout << \\\"\" << line << \"\\\" << std::endl;\\n\";\n        }\n        out << \"}\\n\";\n    }\n    return 0;\n}\n
" }, { "name": "src/main.cpp", "code": "extern void generated_func();\nint main() {\n generated_func();\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
extern void generated_func();\nint main() {\n    generated_func();\n    return 0;\n}\n
" }, { "name": "src/test.in", "code": "Hello\nGenerated\nWorld\n", "language": "text" } ], "examples/configuration/custom_module/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_moduledirs(\"xmake\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/main.cpp\")\n on_load(function (target)\n import(\"modules.hello\").say(\"xmake\")\n end)\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_moduledirs(\"xmake\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/main.cpp\")\n    on_load(function (target)\n        import(\"modules.hello\").say(\"xmake\")\n    end)\n
" }, { "name": "src/main.cpp", "code": "#include \n\nint main(int argc, char** argv) {\n std::cout << \"hello world!\" << std::endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nint main(int argc, char** argv) {\n    std::cout << \"hello world!\" << std::endl;\n    return 0;\n}\n
" }, { "name": "xmake/modules/foo.lua", "code": "function hello()\n print(\"hello from custom module!\")\nend\n", "language": "lua", "highlightedCode": "
function hello()\n    print(\"hello from custom module!\")\nend\n
" }, { "name": "xmake/modules/hello.lua", "code": "function say(name)\n print(\"hello \" .. name)\nend\n", "language": "lua", "highlightedCode": "
function say(name)\n    print(\"hello \" .. name)\nend\n
" } ], "examples/configuration/autogen/modules": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_moduledirs(\"modules\")\n\nrule(\"autogen\")\n set_extensions(\".in\")\n before_build_file(function (target, sourcefile, opt)\n import(\"utils.progress\")\n import(\"core.project.depend\")\n import(\"core.tool.compiler\")\n import(\"autogen.foo\", {always_build = true})\n\n local sourcefile_cx = path.join(target:autogendir(), \"rules\", \"autogen\", path.basename(sourcefile) .. \".cpp\")\n local objectfile = target:objectfile(sourcefile_cx)\n table.insert(target:objectfiles(), objectfile)\n\n depend.on_changed(function ()\n progress.show(opt.progress, \"${color.build.object}compiling.autogen %s\", sourcefile)\n os.mkdir(path.directory(sourcefile_cx))\n foo.generate(sourcefile, sourcefile_cx)\n compiler.compile(sourcefile_cx, objectfile, {target = target})\n end, {dependfile = target:dependfile(objectfile),\n files = sourcefile,\n changed = target:is_rebuilt()})\n end)\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_rules(\"autogen\")\n add_files(\"src/main.cpp\")\n add_files(\"src/*.in\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_moduledirs(\"modules\")\n\nrule(\"autogen\")\n    set_extensions(\".in\")\n    before_build_file(function (target, sourcefile, opt)\n        import(\"utils.progress\")\n        import(\"core.project.depend\")\n        import(\"core.tool.compiler\")\n        import(\"autogen.foo\", {always_build = true})\n\n        local sourcefile_cx = path.join(target:autogendir(), \"rules\", \"autogen\", path.basename(sourcefile) .. \".cpp\")\n        local objectfile = target:objectfile(sourcefile_cx)\n        table.insert(target:objectfiles(), objectfile)\n\n        depend.on_changed(function ()\n            progress.show(opt.progress, \"${color.build.object}compiling.autogen %s\", sourcefile)\n            os.mkdir(path.directory(sourcefile_cx))\n            foo.generate(sourcefile, sourcefile_cx)\n            compiler.compile(sourcefile_cx, objectfile, {target = target})\n        end, {dependfile = target:dependfile(objectfile),\n              files = sourcefile,\n              changed = target:is_rebuilt()})\n    end)\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_rules(\"autogen\")\n    add_files(\"src/main.cpp\")\n    add_files(\"src/*.in\")\n
" }, { "name": "modules/autogen/foo.lua", "code": "function generate(sourcefile, sourcefile_cx)\n local file = io.open(sourcefile_cx, \"w\")\n if file then\n file:write('#include \\n')\n file:write('void generated_func() {\\n')\n file:write(' printf(\"hello xmake!\\\\n\");\\n')\n file:write('}\\n')\n file:close()\n end\nend\n", "language": "lua", "highlightedCode": "
function generate(sourcefile, sourcefile_cx)\n    local file = io.open(sourcefile_cx, \"w\")\n    if file then\n        file:write('#include <stdio.h>\\n')\n        file:write('void generated_func() {\\n')\n        file:write('    printf(\"hello xmake!\\\\n\");\\n')\n        file:write('}\\n')\n        file:close()\n    end\nend\n
" }, { "name": "src/main.cpp", "code": "extern void generated_func();\nint main() {\n generated_func();\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
extern void generated_func();\nint main() {\n    generated_func();\n    return 0;\n}\n
" }, { "name": "src/test.in", "code": "dummy content", "language": "text" } ], "examples/configuration/add_configfiles/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_files(\"src/main.c\")\n\n -- set config variables\n set_configvar(\"FOO_ENABLE\", 1)\n set_configvar(\"FOO_STRING\", \"hello xmake\")\n\n -- set config directory\n set_configdir(\"$(builddir)/config\")\n \n -- generate config header\n add_configfiles(\"config.h.in\")\n \n -- add include directory\n add_includedirs(\"$(builddir)/config\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_files(\"src/main.c\")\n\n    -- set config variables\n    set_configvar(\"FOO_ENABLE\", 1)\n    set_configvar(\"FOO_STRING\", \"hello xmake\")\n\n    -- set config directory\n    set_configdir(\"$(builddir)/config\")\n    \n    -- generate config header\n    add_configfiles(\"config.h.in\")\n    \n    -- add include directory\n    add_includedirs(\"$(builddir)/config\")\n
" }, { "name": "config.h.in", "code": "#ifndef CONFIG_H\n#define CONFIG_H\n\n#define HELLO \"${FOO_STRING}\"\n${define FOO_ENABLE}\n\n#endif\n", "language": "text" }, { "name": "src/main.c", "code": "#include \n#include \"config.h\"\n\nint main(int argc, char** argv)\n{\n printf(\"%s\\n\", HELLO);\n#ifdef FOO_ENABLE\n printf(\"foo enabled\\n\");\n#endif\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n#include \"config.h\"\n\nint main(int argc, char** argv)\n{\n    printf(\"%s\\n\", HELLO);\n#ifdef FOO_ENABLE\n    printf(\"foo enabled\\n\");\n#endif\n    return 0;\n}\n
" } ], "examples/bindings/swig/python_cpp": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\nadd_requires(\"python 3.x\")\n\ntarget(\"example\")\n add_rules(\"swig.cpp\", {moduletype = \"python\"})\n add_files(\"src/example.i\", {scriptdir = \"share\"})\n add_files(\"src/example.cpp\")\n add_packages(\"python\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\nadd_requires(\"python 3.x\")\n\ntarget(\"example\")\n    add_rules(\"swig.cpp\", {moduletype = \"python\"})\n    add_files(\"src/example.i\", {scriptdir = \"share\"})\n    add_files(\"src/example.cpp\")\n    add_packages(\"python\")\n
" }, { "name": "src/example.cpp", "code": "/* File : example.cpp */\n#include \"example.h\"\n\nint fact(int n) {\n if (n <= 1) return 1;\n else return n*fact(n-1);\n}\n", "language": "cpp", "highlightedCode": "
/* File : example.cpp */\n#include \"example.h\"\n\nint fact(int n) {\n    if (n <= 1) return 1;\n    else return n*fact(n-1);\n}\n
" }, { "name": "src/example.h", "code": "/* File : example.h */\nint fact(int n);\n", "language": "cpp", "highlightedCode": "
/* File : example.h */\nint fact(int n);\n
" }, { "name": "src/example.i", "code": "/* File : example.i */\n%module example\n\n%{\n#include \"example.h\"\n%}\n\n/* Let's just grab the original header file here */\n%include \"example.h\"\n", "language": "text" } ], "examples/bindings/swig/lua": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\nadd_requires(\"lua\")\n\ntarget(\"example\")\n add_rules(\"swig.c\", {moduletype = \"lua\"})\n add_files(\"src/example.i\", {swigflags = \"-no-old-metatable-bindings\"})\n add_files(\"src/example.c\")\n add_packages(\"lua\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\nadd_requires(\"lua\")\n\ntarget(\"example\")\n    add_rules(\"swig.c\", {moduletype = \"lua\"})\n    add_files(\"src/example.i\", {swigflags = \"-no-old-metatable-bindings\"})\n    add_files(\"src/example.c\")\n    add_packages(\"lua\")\n
" }, { "name": "src/example.c", "code": "/* File : example.c */\n#include \ndouble My_variable = 3.0;\n\nint fact(int n) {\n if (n <= 1) return 1;\n else return n*fact(n-1);\n}\n\nint my_mod(int x, int y) {\n return (x%y);\n}\n", "language": "cpp", "highlightedCode": "
/* File : example.c */\n#include <time.h>\ndouble My_variable = 3.0;\n\nint fact(int n) {\n    if (n <= 1) return 1;\n    else return n*fact(n-1);\n}\n\nint my_mod(int x, int y) {\n    return (x%y);\n}\n
" }, { "name": "src/example.i", "code": "/* File : example.i */\n%module example\n\n%{\n#include \"example.c\"\n%}\n\n/* Let's just grab the original header file here */\nint fact(int n);\nint my_mod(int x, int y);\nextern double My_variable;\n", "language": "text" } ], "examples/bindings/swig/python_c": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\nadd_requires(\"python 3.x\")\n\ntarget(\"example\")\n add_rules(\"swig.c\", {moduletype = \"python\"})\n add_files(\"src/example.i\", {scriptdir = \"share\"})\n add_files(\"src/example.c\")\n add_packages(\"python\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\nadd_requires(\"python 3.x\")\n\ntarget(\"example\")\n    add_rules(\"swig.c\", {moduletype = \"python\"})\n    add_files(\"src/example.i\", {scriptdir = \"share\"})\n    add_files(\"src/example.c\")\n    add_packages(\"python\")\n
" }, { "name": "src/example.c", "code": "/* File : example.c */\n#include \ndouble My_variable = 3.0;\n\nint fact(int n) {\n if (n <= 1) return 1;\n else return n*fact(n-1);\n}\n\nint my_mod(int x, int y) {\n return (x%y);\n}\n", "language": "cpp", "highlightedCode": "
/* File : example.c */\n#include <time.h>\ndouble My_variable = 3.0;\n\nint fact(int n) {\n    if (n <= 1) return 1;\n    else return n*fact(n-1);\n}\n\nint my_mod(int x, int y) {\n    return (x%y);\n}\n
" }, { "name": "src/example.i", "code": "/* File : example.i */\n%module example\n\n%{\n#include \"example.c\"\n%}\n\n/* Let's just grab the original header file here */\nint fact(int n);\nint my_mod(int x, int y);\nextern double My_variable;\n", "language": "text" } ], "examples/bindings/swig/java": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\n-- make sure you config to an enviroment with jni.h\n-- for example: xmake f -c -p android\n\ntarget(\"example\")\n set_kind('shared')\n -- set moduletype to java\n add_rules(\"swig.c\", {moduletype = \"java\"})\n -- test jar build\n -- add_rules(\"swig.c\", {moduletype = \"java\" , buildjar = true})\n -- use swigflags to provider package name and output path of java files\n add_files(\"src/example.i\", {swigflags = {\n \"-package\",\n \"com.example\",\n \"-outdir\",\n \"build/java/com/example/\"\n }})\n add_files(\"src/example.c\")\n add_includedirs(\"src\")\n before_build(function()\n -- ensure output path exists before running swig\n os.mkdir(\"build/java/com/example/\")\n end)\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\n-- make sure you config to an enviroment with jni.h\n-- for example: xmake f -c -p android\n\ntarget(\"example\")\n    set_kind('shared')\n    -- set moduletype to java\n    add_rules(\"swig.c\", {moduletype = \"java\"})\n    -- test jar build\n    -- add_rules(\"swig.c\", {moduletype = \"java\" , buildjar = true})\n    -- use swigflags to provider package name and output path of java files\n    add_files(\"src/example.i\", {swigflags = {\n        \"-package\",\n        \"com.example\",\n        \"-outdir\",\n        \"build/java/com/example/\"\n    }})\n    add_files(\"src/example.c\")\n    add_includedirs(\"src\")\n    before_build(function()\n        -- ensure output path exists before running swig\n        os.mkdir(\"build/java/com/example/\")\n    end)\n
" }, { "name": "src/example.c", "code": "/* File : example.c */\n#include \ndouble My_variable = 3.0;\n\nint fact(int n) {\n if (n <= 1) return 1;\n else return n*fact(n-1);\n}\n\nint my_mod(int x, int y) {\n return (x%y);\n}\n", "language": "cpp", "highlightedCode": "
/* File : example.c */\n#include <time.h>\ndouble My_variable = 3.0;\n\nint fact(int n) {\n    if (n <= 1) return 1;\n    else return n*fact(n-1);\n}\n\nint my_mod(int x, int y) {\n    return (x%y);\n}\n
" }, { "name": "src/example.i", "code": "/* File : example.i */\n%module example\n\n%{\n#include \"example.c\"\n%}\n\n/* Let's just grab the original header file here */\nint fact(int n);\nint my_mod(int x, int y);\nextern double My_variable;\n", "language": "text" } ], "examples/bindings/python_module/pybind11": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\nadd_requires(\"pybind11\")\n\ntarget(\"example\")\n add_rules(\"python.module\")\n add_files(\"src/*.cpp\")\n add_packages(\"pybind11\")\n set_languages(\"c++11\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\nadd_requires(\"pybind11\")\n\ntarget(\"example\")\n    add_rules(\"python.module\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"pybind11\")\n    set_languages(\"c++11\")\n
" }, { "name": "src/example.cpp", "code": "#include \n\n#define STRINGIFY(x) #x\n#define MACRO_STRINGIFY(x) STRINGIFY(x)\n\nint add(int i, int j) {\n return i + j;\n}\n\nnamespace py = pybind11;\n\nPYBIND11_MODULE(example, m) {\n m.doc() = R\"pbdoc(\n Pybind11 example plugin\n -----------------------\n .. currentmodule:: example\n .. autosummary::\n :toctree: _generate\n add\n subtract\n )pbdoc\";\n\n m.def(\"add\", &add, R\"pbdoc(\n Add two numbers\n Some other explanation about the add function.\n )pbdoc\");\n\n m.def(\"subtract\", [](int i, int j) { return i - j; }, R\"pbdoc(\n Subtract two numbers\n Some other explanation about the subtract function.\n )pbdoc\");\n\n#ifdef VERSION_INFO\n m.attr(\"__version__\") = MACRO_STRINGIFY(VERSION_INFO);\n#else\n m.attr(\"__version__\") = \"dev\";\n#endif\n}\n", "language": "cpp", "highlightedCode": "
#include <pybind11/pybind11.h>\n\n#define STRINGIFY(x) #x\n#define MACRO_STRINGIFY(x) STRINGIFY(x)\n\nint add(int i, int j) {\n    return i + j;\n}\n\nnamespace py = pybind11;\n\nPYBIND11_MODULE(example, m) {\n    m.doc() = R\"pbdoc(\n        Pybind11 example plugin\n        -----------------------\n        .. currentmodule:: example\n        .. autosummary::\n           :toctree: _generate\n           add\n           subtract\n    )pbdoc\";\n\n    m.def(\"add\", &add, R\"pbdoc(\n        Add two numbers\n        Some other explanation about the add function.\n    )pbdoc\");\n\n    m.def(\"subtract\", [](int i, int j) { return i - j; }, R\"pbdoc(\n        Subtract two numbers\n        Some other explanation about the subtract function.\n    )pbdoc\");\n\n#ifdef VERSION_INFO\n    m.attr(\"__version__\") = MACRO_STRINGIFY(VERSION_INFO);\n#else\n    m.attr(\"__version__\") = \"dev\";\n#endif\n}\n
" } ], "examples/bindings/python_module/cython": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"python 3.x\")\n\ntarget(\"example\")\n add_rules(\"python.cython\")\n add_files(\"src/*.pyx\")\n add_packages(\"python\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"python 3.x\")\n\ntarget(\"example\")\n    add_rules(\"python.cython\")\n    add_files(\"src/*.pyx\")\n    add_packages(\"python\")\n
" }, { "name": "src/example.pyx", "code": "def say_hello_to(name):\n print(\"Hello %s!\" % name)\n", "language": "text" } ], "examples/bindings/nodejs_module/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"node-addon-api\")\n\ntarget(\"rime\")\n set_languages(\"cxx17\")\n add_rules(\"nodejs.module\")\n add_packages(\"node-addon-api\")\n add_files(\"src/*.cc\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"node-addon-api\")\n\ntarget(\"rime\")\n    set_languages(\"cxx17\")\n    add_rules(\"nodejs.module\")\n    add_packages(\"node-addon-api\")\n    add_files(\"src/*.cc\")\n
" }, { "name": "src/test.cc", "code": "#include \n\nNapi::String Method(const Napi::CallbackInfo& info) {\n Napi::Env env = info.Env();\n return Napi::String::New(env, \"world\");\n}\n\nNapi::Object Init(Napi::Env env, Napi::Object exports) {\n exports.Set(Napi::String::New(env, \"hello\"),\n Napi::Function::New(env, Method));\n return exports;\n}\n\nNODE_API_MODULE(hello, Init)\n", "language": "cpp", "highlightedCode": "
#include <napi.h>\n\nNapi::String Method(const Napi::CallbackInfo& info) {\n  Napi::Env env = info.Env();\n  return Napi::String::New(env, \"world\");\n}\n\nNapi::Object Init(Napi::Env env, Napi::Object exports) {\n  exports.Set(Napi::String::New(env, \"hello\"),\n              Napi::Function::New(env, Method));\n  return exports;\n}\n\nNODE_API_MODULE(hello, Init)\n
" } ], "examples/bindings/python_module/cpython": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"python 3.x\")\n\ntarget(\"example\")\n add_rules(\"python.module\")\n add_files(\"src/*.c\")\n add_packages(\"python\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\nadd_requires(\"python 3.x\")\n\ntarget(\"example\")\n    add_rules(\"python.module\")\n    add_files(\"src/*.c\")\n    add_packages(\"python\")\n
" }, { "name": "src/main.c", "code": "#include \n\nstatic PyObject* example_hello(PyObject* self, PyObject* args) {\n return Py_BuildValue(\"s\", \"Hello world!\");\n}\n\nstatic PyMethodDef example_methods[] = {\n {\"hello\", (PyCFunction)example_hello, METH_VARARGS, \"Get hello string.\"},\n {NULL, NULL, 0, NULL}\n};\n\nstatic struct PyModuleDef example_module = {\n PyModuleDef_HEAD_INIT,\n \"example\",\n NULL,\n -1,\n example_methods\n};\n\nPyMODINIT_FUNC PyInit_example(void) {\n return PyModule_Create(&example_module);\n}\n", "language": "cpp", "highlightedCode": "
#include <Python.h>\n\nstatic PyObject* example_hello(PyObject* self, PyObject* args) {\n    return Py_BuildValue(\"s\", \"Hello world!\");\n}\n\nstatic PyMethodDef example_methods[] = {\n    {\"hello\", (PyCFunction)example_hello, METH_VARARGS, \"Get hello string.\"},\n    {NULL, NULL, 0, NULL}\n};\n\nstatic struct PyModuleDef example_module = {\n    PyModuleDef_HEAD_INIT,\n    \"example\",\n    NULL,\n    -1,\n    example_methods\n};\n\nPyMODINIT_FUNC PyInit_example(void) {\n    return PyModule_Create(&example_module);\n}\n
" } ], "examples/bindings/lua_module/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"rime\")\n add_rules(\"lua.module\", \"lua.native-objects\")\n add_files(\"src/*.nobj.lua\")\n add_cflags(\"-Wno-int-conversion\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"rime\")\n    add_rules(\"lua.module\", \"lua.native-objects\")\n    add_files(\"src/*.nobj.lua\")\n    add_cflags(\"-Wno-int-conversion\")\n
" }, { "name": "src/example.nobj.lua", "code": "-- A simple example.nobj.lua\n-- see https://github.com/Neopallium/LuaNativeObjects for more details\n\nbasetype \"MyObject\"\n constructor \"MyObject\"\n destructor \"MyObject\"\n", "language": "lua", "highlightedCode": "
-- A simple example.nobj.lua\n-- see https://github.com/Neopallium/LuaNativeObjects for more details\n\nbasetype \"MyObject\"\n  constructor \"MyObject\"\n  destructor \"MyObject\"\n
" } ], "examples/platforms/linux/driver/hello": [ { "name": "xmake.lua", "code": "add_requires(\"linux-headers\", {configs = {driver_modules = true}})\n\ntarget(\"hello\")\n add_rules(\"platform.linux.driver\")\n add_files(\"src/*.c\")\n add_packages(\"linux-headers\")\n set_license(\"GPL-2.0\")\n", "language": "lua", "highlightedCode": "
add_requires(\"linux-headers\", {configs = {driver_modules = true}})\n\ntarget(\"hello\")\n    add_rules(\"platform.linux.driver\")\n    add_files(\"src/*.c\")\n    add_packages(\"linux-headers\")\n    set_license(\"GPL-2.0\")\n
" }, { "name": "src/hello.c", "code": "#include \n#include \n#include \n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Ruki\");\nMODULE_DESCRIPTION(\"A Simple Hello World module\");\n\nstatic int __init hello_init(void)\n{\n printk(KERN_INFO \"Hello world!\\n\");\n return 0;\n}\n\nstatic void __exit hello_exit(void)\n{\n printk(KERN_INFO \"Goodbye world!\\n\");\n}\n\nmodule_init(hello_init);\nmodule_exit(hello_exit);\n", "language": "cpp", "highlightedCode": "
#include <linux/module.h>\n#include <linux/kernel.h>\n#include <linux/init.h>\n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Ruki\");\nMODULE_DESCRIPTION(\"A Simple Hello World module\");\n\nstatic int __init hello_init(void)\n{\n    printk(KERN_INFO \"Hello world!\\n\");\n    return 0;\n}\n\nstatic void __exit hello_exit(void)\n{\n    printk(KERN_INFO \"Goodbye world!\\n\");\n}\n\nmodule_init(hello_init);\nmodule_exit(hello_exit);\n
" } ], "examples/platforms/linux/bpf/minimal": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\nadd_rules(\"platform.linux.bpf\")\n\nadd_requires(\"linux-tools\", {configs = {bpftool = true}})\nadd_requires(\"libbpf\")\nif is_plat(\"android\") then\n add_requires(\"ndk >=22.x\")\n set_toolchains(\"@ndk\", {sdkver = \"23\"})\nelse\n add_requires(\"llvm >=10.x\")\n set_toolchains(\"@llvm\")\n add_requires(\"linux-headers\")\nend\n\ntarget(\"minimal\")\n set_kind(\"binary\")\n add_files(\"src/*.c\")\n add_packages(\"linux-tools\", \"linux-headers\", \"libbpf\")\n set_license(\"GPL-2.0\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\nadd_rules(\"platform.linux.bpf\")\n\nadd_requires(\"linux-tools\", {configs = {bpftool = true}})\nadd_requires(\"libbpf\")\nif is_plat(\"android\") then\n    add_requires(\"ndk >=22.x\")\n    set_toolchains(\"@ndk\", {sdkver = \"23\"})\nelse\n    add_requires(\"llvm >=10.x\")\n    set_toolchains(\"@llvm\")\n    add_requires(\"linux-headers\")\nend\n\ntarget(\"minimal\")\n    set_kind(\"binary\")\n    add_files(\"src/*.c\")\n    add_packages(\"linux-tools\", \"linux-headers\", \"libbpf\")\n    set_license(\"GPL-2.0\")\n
" }, { "name": "src/minimal.bpf.c", "code": "#include \n#include \n\nSEC(\"tracepoint/syscalls/sys_enter_write\")\nint handle_tp(void *ctx)\n{\n int pid = bpf_get_current_pid_tgid() >> 32;\n char fmt[] = \"BPF trigger from PID %d.\\n\";\n bpf_trace_printk(fmt, sizeof(fmt), pid);\n return 0;\n}\n\nchar LICENSE[] SEC(\"license\") = \"Dual BSD/GPL\";\n", "language": "cpp", "highlightedCode": "
#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n\nSEC(\"tracepoint/syscalls/sys_enter_write\")\nint handle_tp(void *ctx)\n{\n    int pid = bpf_get_current_pid_tgid() >> 32;\n    char fmt[] = \"BPF trigger from PID %d.\\n\";\n    bpf_trace_printk(fmt, sizeof(fmt), pid);\n    return 0;\n}\n\nchar LICENSE[] SEC(\"license\") = \"Dual BSD/GPL\";\n
" }, { "name": "src/minimal.c", "code": "#include \n#include \n#include \n#include \n#include \"minimal.skel.h\"\n\nstatic int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args)\n{\n return vfprintf(stderr, format, args);\n}\n\nint main(int argc, char **argv)\n{\n struct minimal_bpf *skel;\n int err;\n\n libbpf_set_print(libbpf_print_fn);\n\n skel = minimal_bpf__open();\n if (!skel) {\n fprintf(stderr, \"Failed to open BPF skeleton\\n\");\n return 1;\n }\n\n err = minimal_bpf__load(skel);\n if (err) {\n fprintf(stderr, \"Failed to load and verify BPF skeleton\\n\");\n goto cleanup;\n }\n\n err = minimal_bpf__attach(skel);\n if (err) {\n fprintf(stderr, \"Failed to attach BPF skeleton\\n\");\n goto cleanup;\n }\n\n printf(\"Successfully started! Please run `sudo cat /sys/kernel/debug/tracing/trace_pipe` \"\n \"to see output of the BPF programs.\\n\");\n\n for (;;) {\n fprintf(stderr, \".\");\n sleep(1);\n }\n\ncleanup:\n minimal_bpf__destroy(skel);\n return -err;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n#include <unistd.h>\n#include <sys/resource.h>\n#include <bpf/libbpf.h>\n#include \"minimal.skel.h\"\n\nstatic int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args)\n{\n    return vfprintf(stderr, format, args);\n}\n\nint main(int argc, char **argv)\n{\n    struct minimal_bpf *skel;\n    int err;\n\n    libbpf_set_print(libbpf_print_fn);\n\n    skel = minimal_bpf__open();\n    if (!skel) {\n        fprintf(stderr, \"Failed to open BPF skeleton\\n\");\n        return 1;\n    }\n\n    err = minimal_bpf__load(skel);\n    if (err) {\n        fprintf(stderr, \"Failed to load and verify BPF skeleton\\n\");\n        goto cleanup;\n    }\n\n    err = minimal_bpf__attach(skel);\n    if (err) {\n        fprintf(stderr, \"Failed to attach BPF skeleton\\n\");\n        goto cleanup;\n    }\n\n    printf(\"Successfully started! Please run `sudo cat /sys/kernel/debug/tracing/trace_pipe` \"\n           \"to see output of the BPF programs.\\n\");\n\n    for (;;) {\n        fprintf(stderr, \".\");\n        sleep(1);\n    }\n\ncleanup:\n    minimal_bpf__destroy(skel);\n    return -err;\n}\n
" } ], "examples/cpp/modules/distribution/src": [ { "name": "xmake.lua", "code": "add_rules(\"mode.release\", \"mode.debug\")\nset_languages(\"c++20\")\n\ntarget(\"foo\")\n set_kind(\"static\")\n add_files(\"*.cpp\")\n add_files(\"*.mpp\", {\n defines = \"FOO_EXPORT\", \n public = true\n })\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.release\", \"mode.debug\")\nset_languages(\"c++20\")\n\ntarget(\"foo\")\n    set_kind(\"static\")\n    add_files(\"*.cpp\")\n    add_files(\"*.mpp\", {\n        defines = \"FOO_EXPORT\", \n        public = true\n    })\n
" }, { "name": "foo.cpp", "code": "module foo;\nimport ;\n\nnamespace foo {\n void say(const char *msg) {\n std::cout << \"foo: \" << msg << std::endl;\n }\n}\n", "language": "cpp", "highlightedCode": "
module foo;\nimport <iostream>;\n\nnamespace foo {\n    void say(const char *msg) {\n        std::cout << \"foo: \" << msg << std::endl;\n    }\n}\n
" }, { "name": "foo.mpp", "code": "export module foo;\n\nexport namespace foo {\n#ifdef FOO_EXPORT\n void say(const char *msg);\n#endif\n}\n", "language": "text" }, { "name": "main.cpp", "code": "#include \n\nint main() {\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nint main() {\n    return 0;\n}\n
" } ], "examples/cpp/graphics/tui/ncurses": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"ncurses\")\n\ntarget(\"ncurses_tui\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_packages(\"ncurses\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"ncurses\")\n\ntarget(\"ncurses_tui\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"ncurses\")\n
" }, { "name": "src/main.cpp", "code": "#include \n#include \n\nint main(int argc, char** argv) {\n // Initialize ncurses\n initscr();\n cbreak();\n noecho();\n keypad(stdscr, TRUE);\n\n // Get screen size\n int height, width;\n getmaxyx(stdscr, height, width);\n\n // Create a window for our box\n int win_height = 10;\n int win_width = 40;\n int start_y = (height - win_height) / 2;\n int start_x = (width - win_width) / 2;\n\n WINDOW* win = newwin(win_height, win_width, start_y, start_x);\n refresh();\n\n // Draw a box around the window\n box(win, 0, 0);\n\n // Print some text\n std::string text = \"Hello from Xmake TUI!\";\n mvwprintw(win, win_height / 2, (win_width - text.length()) / 2, \"%s\", text.c_str());\n \n std::string exit_text = \"Press any key to exit...\";\n mvwprintw(win, win_height / 2 + 2, (win_width - exit_text.length()) / 2, \"%s\", exit_text.c_str());\n\n // Refresh the window\n wrefresh(win);\n\n // Wait for input\n getch();\n\n // Clean up\n delwin(win);\n endwin();\n\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <ncurses.h>\n#include <string>\n\nint main(int argc, char** argv) {\n    // Initialize ncurses\n    initscr();\n    cbreak();\n    noecho();\n    keypad(stdscr, TRUE);\n\n    // Get screen size\n    int height, width;\n    getmaxyx(stdscr, height, width);\n\n    // Create a window for our box\n    int win_height = 10;\n    int win_width = 40;\n    int start_y = (height - win_height) / 2;\n    int start_x = (width - win_width) / 2;\n\n    WINDOW* win = newwin(win_height, win_width, start_y, start_x);\n    refresh();\n\n    // Draw a box around the window\n    box(win, 0, 0);\n\n    // Print some text\n    std::string text = \"Hello from Xmake TUI!\";\n    mvwprintw(win, win_height / 2, (win_width - text.length()) / 2, \"%s\", text.c_str());\n    \n    std::string exit_text = \"Press any key to exit...\";\n    mvwprintw(win, win_height / 2 + 2, (win_width - exit_text.length()) / 2, \"%s\", exit_text.c_str());\n\n    // Refresh the window\n    wrefresh(win);\n\n    // Wait for input\n    getch();\n\n    // Clean up\n    delwin(win);\n    endwin();\n\n    return 0;\n}\n
" } ], "examples/cpp/graphics/tui/ftxui": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"ftxui\")\n\ntarget(\"ftxui_tui\")\n set_kind(\"binary\")\n set_languages(\"c++17\")\n add_files(\"src/*.cpp\")\n add_packages(\"ftxui\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"ftxui\")\n\ntarget(\"ftxui_tui\")\n    set_kind(\"binary\")\n    set_languages(\"c++17\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"ftxui\")\n
" }, { "name": "src/main.cpp", "code": "#include \n#include \n#include \n\nint main(int argc, char const *argv[]) {\n using namespace ftxui;\n\n // Define the document\n Element document =\n hbox({\n text(\"left\") | border,\n text(\"middle\") | border | flex,\n text(\"right\") | border,\n });\n\n auto screen = Screen::Create(\n Dimension::Full(),\n Dimension::Fit(document)\n );\n Render(screen, document);\n screen.Print();\n\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <ftxui/dom/elements.hpp>\n#include <ftxui/screen/screen.hpp>\n#include <iostream>\n\nint main(int argc, char const *argv[]) {\n  using namespace ftxui;\n\n  // Define the document\n  Element document =\n    hbox({\n      text(\"left\")   | border,\n      text(\"middle\") | border | flex,\n      text(\"right\")  | border,\n    });\n\n  auto screen = Screen::Create(\n    Dimension::Full(),\n    Dimension::Fit(document)\n  );\n  Render(screen, document);\n  screen.Print();\n\n  return 0;\n}\n
" } ], "examples/cpp/graphics/qt/widgetapp": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"qt_widgetapp\")\n add_rules(\"qt.widgetapp\")\n add_headerfiles(\"src/*.h\")\n add_files(\"src/*.cpp\") \n add_files(\"src/mainwindow.ui\")\n add_files(\"src/mainwindow.h\") -- add meta header files with Q_OBJECT\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"qt_widgetapp\")\n    add_rules(\"qt.widgetapp\")\n    add_headerfiles(\"src/*.h\")\n    add_files(\"src/*.cpp\") \n    add_files(\"src/mainwindow.ui\")\n    add_files(\"src/mainwindow.h\")  -- add meta header files with Q_OBJECT\n
" }, { "name": "src/main.cpp", "code": "#include \"mainwindow.h\"\n#include \n\nint main(int argc, char *argv[]) {\n QApplication a(argc, argv);\n MainWindow w;\n w.show();\n\n return a.exec();\n}\n", "language": "cpp", "highlightedCode": "
#include \"mainwindow.h\"\n#include <QApplication>\n\nint main(int argc, char *argv[]) {\n    QApplication a(argc, argv);\n    MainWindow w;\n    w.show();\n\n    return a.exec();\n}\n
" }, { "name": "src/mainwindow.cpp", "code": "#include \"mainwindow.h\"\n#include \"ui_mainwindow.h\"\n\nMainWindow::MainWindow(QWidget *parent) :\n QMainWindow(parent),\n ui(new Ui::MainWindow) {\n ui->setupUi(this);\n}\n\nMainWindow::~MainWindow() {\n delete ui;\n}\n", "language": "cpp", "highlightedCode": "
#include \"mainwindow.h\"\n#include \"ui_mainwindow.h\"\n\nMainWindow::MainWindow(QWidget *parent) :\n    QMainWindow(parent),\n    ui(new Ui::MainWindow) {\n    ui->setupUi(this);\n}\n\nMainWindow::~MainWindow() {\n    delete ui;\n}\n
" }, { "name": "src/mainwindow.h", "code": "#ifndef MAINWINDOW_H\n#define MAINWINDOW_H\n\n#include \n\nnamespace Ui {\nclass MainWindow;\n}\n\nclass MainWindow : public QMainWindow {\n Q_OBJECT\n\npublic:\n explicit MainWindow(QWidget *parent = 0);\n ~MainWindow();\n\nprivate:\n Ui::MainWindow *ui;\n};\n\n#endif // MAINWINDOW_H\n", "language": "cpp", "highlightedCode": "
#ifndef MAINWINDOW_H\n#define MAINWINDOW_H\n\n#include <QMainWindow>\n\nnamespace Ui {\nclass MainWindow;\n}\n\nclass MainWindow : public QMainWindow {\n    Q_OBJECT\n\npublic:\n    explicit MainWindow(QWidget *parent = 0);\n    ~MainWindow();\n\nprivate:\n    Ui::MainWindow *ui;\n};\n\n#endif // MAINWINDOW_H\n
" }, { "name": "src/mainwindow.ui", "code": "\n\n MainWindow\n \n \n \n 0\n 0\n 400\n 300\n \n \n \n MainWindow\n \n \n \n \n \n 0\n 0\n 400\n 22\n \n \n \n \n \n TopToolBarArea\n \n \n false\n \n \n \n \n \n \n \n\n", "language": "text" } ], "examples/cpp/graphics/qt/static_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"qt_static_library\")\n add_rules(\"qt.static\")\n add_files(\"src/*.cpp\")\n add_frameworks(\"QtNetwork\", \"QtGui\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"qt_static_library\")\n    add_rules(\"qt.static\")\n    add_files(\"src/*.cpp\")\n    add_frameworks(\"QtNetwork\", \"QtGui\")\n
" }, { "name": "src/test.cpp", "code": "#include \"test.h\"\n#include \n\nvoid test() {\n qDebug() << \"Hello from static library\";\n}\n", "language": "cpp", "highlightedCode": "
#include \"test.h\"\n#include <QDebug>\n\nvoid test() {\n    qDebug() << \"Hello from static library\";\n}\n
" }, { "name": "src/test.h", "code": "#ifndef TEST_H\n#define TEST_H\n\nvoid test();\n\n#endif // TEST_H\n", "language": "cpp", "highlightedCode": "
#ifndef TEST_H\n#define TEST_H\n\nvoid test();\n\n#endif // TEST_H\n
" } ], "examples/cpp/graphics/qt/shared_library": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"qt_shared_library\")\n add_rules(\"qt.shared\")\n add_files(\"src/*.cpp\")\n add_frameworks(\"QtNetwork\", \"QtGui\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"qt_shared_library\")\n    add_rules(\"qt.shared\")\n    add_files(\"src/*.cpp\")\n    add_frameworks(\"QtNetwork\", \"QtGui\")\n
" }, { "name": "src/test.cpp", "code": "#include \"test.h\"\n#include \n\nvoid test() {\n qDebug() << \"Hello from shared library\";\n}\n", "language": "cpp", "highlightedCode": "
#include \"test.h\"\n#include <QDebug>\n\nvoid test() {\n    qDebug() << \"Hello from shared library\";\n}\n
" }, { "name": "src/test.h", "code": "#ifndef TEST_H\n#define TEST_H\n\n#include \n\n#if defined(TEST_LIBRARY)\n# define TEST_EXPORT Q_DECL_EXPORT\n#else\n# define TEST_EXPORT Q_DECL_IMPORT\n#endif\n\nTEST_EXPORT void test();\n\n#endif // TEST_H\n", "language": "cpp", "highlightedCode": "
#ifndef TEST_H\n#define TEST_H\n\n#include <QtCore/qglobal.h>\n\n#if defined(TEST_LIBRARY)\n#  define TEST_EXPORT Q_DECL_EXPORT\n#else\n#  define TEST_EXPORT Q_DECL_IMPORT\n#endif\n\nTEST_EXPORT void test();\n\n#endif // TEST_H\n
" } ], "examples/cpp/graphics/qt/console": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"qt_console\")\n add_rules(\"qt.console\")\n add_files(\"src/*.cpp\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"qt_console\")\n    add_rules(\"qt.console\")\n    add_files(\"src/*.cpp\")\n
" }, { "name": "src/main.cpp", "code": "#include \n#include \n\nint main(int argc, char *argv[]) {\n QCoreApplication a(argc, argv);\n qDebug() << \"Hello World\";\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <QCoreApplication>\n#include <QDebug>\n\nint main(int argc, char *argv[]) {\n    QCoreApplication a(argc, argv);\n    qDebug() << \"Hello World\";\n    return 0;\n}\n
" } ], "examples/cpp/graphics/qt/quickplugin": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"demo\")\n add_rules(\"qt.qmlplugin\")\n add_headerfiles(\"src/*.h\")\n add_files(\"src/*.cpp\")\n\n set_values(\"qt.qmlplugin.import_name\", \"My.Plugin\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"demo\")\n    add_rules(\"qt.qmlplugin\")\n    add_headerfiles(\"src/*.h\")\n    add_files(\"src/*.cpp\")\n\n    set_values(\"qt.qmlplugin.import_name\", \"My.Plugin\")\n
" }, { "name": "src/plugin.cpp", "code": "#include \"plugin.h\"\n#include \n\nvoid MyPlugin::registerTypes(const char *uri) {\n // @uri My.Plugin\n}\n", "language": "cpp", "highlightedCode": "
#include \"plugin.h\"\n#include <qqml.h>\n\nvoid MyPlugin::registerTypes(const char *uri) {\n    // @uri My.Plugin\n}\n
" }, { "name": "src/plugin.h", "code": "#ifndef PLUGIN_H\n#define PLUGIN_H\n\n#include \n\nclass MyPlugin : public QQmlExtensionPlugin {\n Q_OBJECT\n Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)\n\npublic:\n void registerTypes(const char *uri) override;\n};\n\n#endif // PLUGIN_H\n", "language": "cpp", "highlightedCode": "
#ifndef PLUGIN_H\n#define PLUGIN_H\n\n#include <QQmlExtensionPlugin>\n\nclass MyPlugin : public QQmlExtensionPlugin {\n    Q_OBJECT\n    Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)\n\npublic:\n    void registerTypes(const char *uri) override;\n};\n\n#endif // PLUGIN_H\n
" } ], "examples/cpp/graphics/qt/quickapp": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"qt_quickapp\")\n add_rules(\"qt.quickapp\")\n add_headerfiles(\"src/*.h\")\n add_files(\"src/*.cpp\") \n add_files(\"src/qml.qrc\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"qt_quickapp\")\n    add_rules(\"qt.quickapp\")\n    add_headerfiles(\"src/*.h\")\n    add_files(\"src/*.cpp\") \n    add_files(\"src/qml.qrc\")\n
" }, { "name": "src/main.cpp", "code": "#include \n#include \n\nint main(int argc, char *argv[]) {\n QGuiApplication app(argc, argv);\n\n QQmlApplicationEngine engine;\n engine.load(QUrl(QStringLiteral(\"qrc:/main.qml\")));\n if (engine.rootObjects().isEmpty())\n return -1;\n\n return app.exec();\n}\n", "language": "cpp", "highlightedCode": "
#include <QGuiApplication>\n#include <QQmlApplicationEngine>\n\nint main(int argc, char *argv[]) {\n    QGuiApplication app(argc, argv);\n\n    QQmlApplicationEngine engine;\n    engine.load(QUrl(QStringLiteral(\"qrc:/main.qml\")));\n    if (engine.rootObjects().isEmpty())\n        return -1;\n\n    return app.exec();\n}\n
" }, { "name": "src/main.qml", "code": "import QtQuick 2.9\nimport QtQuick.Window 2.2\n\nWindow {\n visible: true\n width: 640\n height: 480\n title: qsTr(\"Hello World\")\n\n Text {\n anchors.centerIn: parent\n text: \"Hello World\"\n }\n}\n", "language": "text" }, { "name": "src/qml.qrc", "code": "\n \n main.qml\n \n\n", "language": "text" } ], "examples/cpp/graphics/linux_framebuffer/basic": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"linux_framebuffer\")\n set_kind(\"binary\")\n add_files(\"src/*.c\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"linux_framebuffer\")\n    set_kind(\"binary\")\n    add_files(\"src/*.c\")\n
" }, { "name": "src/main.c", "code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\nint main(int argc, char *argv[])\n{\n int fbfd = 0;\n struct fb_var_screeninfo vinfo;\n struct fb_fix_screeninfo finfo;\n long int screensize = 0;\n char *fbp = 0;\n int x = 0, y = 0;\n long int location = 0;\n\n // Open the file for reading and writing\n fbfd = open(\"/dev/fb0\", O_RDWR);\n if (fbfd == -1) {\n perror(\"Error: cannot open framebuffer device\");\n exit(1);\n }\n printf(\"The framebuffer device was opened successfully.\\n\");\n\n // Get fixed screen information\n if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {\n perror(\"Error reading fixed information\");\n exit(2);\n }\n\n // Get variable screen information\n if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {\n perror(\"Error reading variable information\");\n exit(3);\n }\n\n printf(\"%dx%d, %dbpp\\n\", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);\n\n // Figure out the size of the screen in bytes\n screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;\n\n // Map the device to memory\n fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);\n if (fbp == MAP_FAILED) {\n perror(\"Error: failed to map framebuffer device to memory\");\n exit(4);\n }\n printf(\"The framebuffer device was mapped to memory successfully.\\n\");\n\n // Draw something\n // Assuming 32bpp for simplicity, but good to handle others or just warn\n if (vinfo.bits_per_pixel != 32) {\n printf(\"Warning: example designed for 32bpp, running at %dbpp might look wrong.\\n\", vinfo.bits_per_pixel);\n }\n\n // Draw a gradient\n for (y = 0; y < vinfo.yres; y++) {\n for (x = 0; x < vinfo.xres; x++) {\n location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +\n (y+vinfo.yoffset) * finfo.line_length;\n\n if (vinfo.bits_per_pixel == 32) {\n *(fbp + location) = 100; // Some blue\n *(fbp + location + 1) = 15+(x-100)/2; // A little green\n *(fbp + location + 2) = 200-(y-100)/5; // A lot of red\n *(fbp + location + 3) = 0; // No transparency\n } else if (vinfo.bits_per_pixel == 16) {\n // simple 16bit handling\n int r = x % 32;\n int g = y % 64;\n int b = x % 32;\n unsigned short int t = r<<11 | g << 5 | b;\n *((unsigned short int*)(fbp + location)) = t;\n }\n }\n }\n\n munmap(fbp, screensize);\n close(fbfd);\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <unistd.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <fcntl.h>\n#include <linux/fb.h>\n#include <sys/mman.h>\n#include <sys/ioctl.h>\n\nint main(int argc, char *argv[])\n{\n    int fbfd = 0;\n    struct fb_var_screeninfo vinfo;\n    struct fb_fix_screeninfo finfo;\n    long int screensize = 0;\n    char *fbp = 0;\n    int x = 0, y = 0;\n    long int location = 0;\n\n    // Open the file for reading and writing\n    fbfd = open(\"/dev/fb0\", O_RDWR);\n    if (fbfd == -1) {\n        perror(\"Error: cannot open framebuffer device\");\n        exit(1);\n    }\n    printf(\"The framebuffer device was opened successfully.\\n\");\n\n    // Get fixed screen information\n    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {\n        perror(\"Error reading fixed information\");\n        exit(2);\n    }\n\n    // Get variable screen information\n    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {\n        perror(\"Error reading variable information\");\n        exit(3);\n    }\n\n    printf(\"%dx%d, %dbpp\\n\", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);\n\n    // Figure out the size of the screen in bytes\n    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;\n\n    // Map the device to memory\n    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);\n    if (fbp == MAP_FAILED) {\n        perror(\"Error: failed to map framebuffer device to memory\");\n        exit(4);\n    }\n    printf(\"The framebuffer device was mapped to memory successfully.\\n\");\n\n    // Draw something\n    // Assuming 32bpp for simplicity, but good to handle others or just warn\n    if (vinfo.bits_per_pixel != 32) {\n        printf(\"Warning: example designed for 32bpp, running at %dbpp might look wrong.\\n\", vinfo.bits_per_pixel);\n    }\n\n    // Draw a gradient\n    for (y = 0; y < vinfo.yres; y++) {\n        for (x = 0; x < vinfo.xres; x++) {\n            location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +\n                       (y+vinfo.yoffset) * finfo.line_length;\n\n            if (vinfo.bits_per_pixel == 32) {\n                *(fbp + location) = 100;        // Some blue\n                *(fbp + location + 1) = 15+(x-100)/2;     // A little green\n                *(fbp + location + 2) = 200-(y-100)/5;    // A lot of red\n                *(fbp + location + 3) = 0;      // No transparency\n            } else if (vinfo.bits_per_pixel == 16) {\n                // simple 16bit handling\n                int r = x % 32;\n                int g = y % 64;\n                int b = x % 32;\n                unsigned short int t = r<<11 | g << 5 | b;\n                *((unsigned short int*)(fbp + location)) = t;\n            }\n        }\n    }\n\n    munmap(fbp, screensize);\n    close(fbfd);\n    return 0;\n}\n
" } ], "examples/cpp/graphics/glsl2spv/hlsl": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"directxshadercompiler\", {configs = {binaryonly = true}})\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_rules(\"utils.hlsl2spv\", {bin2c = true})\n add_files(\"src/*.c\")\n add_files(\"src/*.hlsl\")\n add_packages(\"directxshadercompiler\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"directxshadercompiler\", {configs = {binaryonly = true}})\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_rules(\"utils.hlsl2spv\", {bin2c = true})\n    add_files(\"src/*.c\")\n    add_files(\"src/*.hlsl\")\n    add_packages(\"directxshadercompiler\")\n
" }, { "name": "src/main.c", "code": "#include \n\nint main(int argc, char** argv) {\n printf(\"hello shader!\\n\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n\nint main(int argc, char** argv) {\n    printf(\"hello shader!\\n\");\n    return 0;\n}\n
" }, { "name": "src/test.hlsl", "code": "void main() {}\n", "language": "text" } ], "examples/cpp/graphics/glsl2spv/glsl_bin2obj": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"glslang\", {configs = {binaryonly = true}})\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_rules(\"utils.glsl2spv\", {bin2obj = true})\n add_files(\"src/*.c\")\n add_files(\"src/*.glsl\")\n add_packages(\"glslang\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"glslang\", {configs = {binaryonly = true}})\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_rules(\"utils.glsl2spv\", {bin2obj = true})\n    add_files(\"src/*.c\")\n    add_files(\"src/*.glsl\")\n    add_packages(\"glslang\")\n
" }, { "name": "src/main.c", "code": "#include \n\nint main(int argc, char** argv) {\n printf(\"hello shader!\\n\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n\nint main(int argc, char** argv) {\n    printf(\"hello shader!\\n\");\n    return 0;\n}\n
" }, { "name": "src/test.glsl", "code": "#version 450\nvoid main() {}\n", "language": "glsl", "highlightedCode": "
#version 450\nvoid main() {}\n
" } ], "examples/cpp/graphics/glsl2spv/glsl": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"glslang\", {configs = {binaryonly = true}})\n\ntarget(\"test\")\n set_kind(\"binary\")\n add_rules(\"utils.glsl2spv\", {bin2c = true})\n add_files(\"src/*.c\")\n add_files(\"src/*.glsl\")\n add_packages(\"glslang\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"glslang\", {configs = {binaryonly = true}})\n\ntarget(\"test\")\n    set_kind(\"binary\")\n    add_rules(\"utils.glsl2spv\", {bin2c = true})\n    add_files(\"src/*.c\")\n    add_files(\"src/*.glsl\")\n    add_packages(\"glslang\")\n
" }, { "name": "src/main.c", "code": "#include \n\nint main(int argc, char** argv) {\n printf(\"hello shader!\\n\");\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <stdio.h>\n\nint main(int argc, char** argv) {\n    printf(\"hello shader!\\n\");\n    return 0;\n}\n
" }, { "name": "src/test.glsl", "code": "#version 450\nvoid main() {}\n", "language": "glsl", "highlightedCode": "
#version 450\nvoid main() {}\n
" } ], "examples/cpp/graphics/audio/openal": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"openal-soft\")\n\ntarget(\"openal_test\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_packages(\"openal-soft\")\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\nadd_requires(\"openal-soft\")\n\ntarget(\"openal_test\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_packages(\"openal-soft\")\n
" }, { "name": "src/main.cpp", "code": "#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#ifndef M_PI\n#define M_PI 3.14159265358979323846\n#endif\n\nint main() {\n // Open default device\n ALCdevice* device = alcOpenDevice(nullptr);\n if (!device) {\n std::cerr << \"Failed to open default OpenAL device\" << std::endl;\n return 1;\n }\n\n // Create context\n ALCcontext* context = alcCreateContext(device, nullptr);\n if (!context || !alcMakeContextCurrent(context)) {\n std::cerr << \"Failed to create/set OpenAL context\" << std::endl;\n if (context) alcDestroyContext(context);\n alcCloseDevice(device);\n return 1;\n }\n\n std::cout << \"OpenAL initialized successfully!\" << std::endl;\n std::cout << \"Vendor: \" << alGetString(AL_VENDOR) << std::endl;\n std::cout << \"Renderer: \" << alGetString(AL_RENDERER) << std::endl;\n std::cout << \"Version: \" << alGetString(AL_VERSION) << std::endl;\n\n // Generate a sine wave tone\n const int sampleRate = 44100;\n const int durationSeconds = 2;\n const int frequency = 440; // A4 note\n const int bufferSize = sampleRate * durationSeconds;\n std::vector bufferData(bufferSize);\n\n for (int i = 0; i < bufferSize; ++i) {\n double t = (double)i / sampleRate;\n double value = std::sin(2.0 * M_PI * frequency * t);\n bufferData[i] = (short)(value * 32760); // Scale to 16-bit range\n }\n\n // Create buffer\n ALuint buffer;\n alGenBuffers(1, &buffer);\n alBufferData(buffer, AL_FORMAT_MONO16, bufferData.data(), bufferData.size() * sizeof(short), sampleRate);\n\n // Create source\n ALuint source;\n alGenSources(1, &source);\n alSourcei(source, AL_BUFFER, buffer);\n\n // Play sound\n std::cout << \"Playing \" << durationSeconds << \"s sine wave tone...\" << std::endl;\n alSourcePlay(source);\n\n // Wait until playing finishes\n ALint state;\n do {\n std::this_thread::sleep_for(std::chrono::milliseconds(100));\n alGetSourcei(source, AL_SOURCE_STATE, &state);\n } while (state == AL_PLAYING);\n\n // Clean up\n alDeleteSources(1, &source);\n alDeleteBuffers(1, &buffer);\n alcMakeContextCurrent(nullptr);\n alcDestroyContext(context);\n alcCloseDevice(device);\n\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <AL/al.h>\n#include <AL/alc.h>\n#include <iostream>\n#include <vector>\n#include <cmath>\n#include <thread>\n#include <chrono>\n\n#ifndef M_PI\n#define M_PI 3.14159265358979323846\n#endif\n\nint main() {\n    // Open default device\n    ALCdevice* device = alcOpenDevice(nullptr);\n    if (!device) {\n        std::cerr << \"Failed to open default OpenAL device\" << std::endl;\n        return 1;\n    }\n\n    // Create context\n    ALCcontext* context = alcCreateContext(device, nullptr);\n    if (!context || !alcMakeContextCurrent(context)) {\n        std::cerr << \"Failed to create/set OpenAL context\" << std::endl;\n        if (context) alcDestroyContext(context);\n        alcCloseDevice(device);\n        return 1;\n    }\n\n    std::cout << \"OpenAL initialized successfully!\" << std::endl;\n    std::cout << \"Vendor: \" << alGetString(AL_VENDOR) << std::endl;\n    std::cout << \"Renderer: \" << alGetString(AL_RENDERER) << std::endl;\n    std::cout << \"Version: \" << alGetString(AL_VERSION) << std::endl;\n\n    // Generate a sine wave tone\n    const int sampleRate = 44100;\n    const int durationSeconds = 2;\n    const int frequency = 440; // A4 note\n    const int bufferSize = sampleRate * durationSeconds;\n    std::vector<short> bufferData(bufferSize);\n\n    for (int i = 0; i < bufferSize; ++i) {\n        double t = (double)i / sampleRate;\n        double value = std::sin(2.0 * M_PI * frequency * t);\n        bufferData[i] = (short)(value * 32760); // Scale to 16-bit range\n    }\n\n    // Create buffer\n    ALuint buffer;\n    alGenBuffers(1, &buffer);\n    alBufferData(buffer, AL_FORMAT_MONO16, bufferData.data(), bufferData.size() * sizeof(short), sampleRate);\n\n    // Create source\n    ALuint source;\n    alGenSources(1, &source);\n    alSourcei(source, AL_BUFFER, buffer);\n\n    // Play sound\n    std::cout << \"Playing \" << durationSeconds << \"s sine wave tone...\" << std::endl;\n    alSourcePlay(source);\n\n    // Wait until playing finishes\n    ALint state;\n    do {\n        std::this_thread::sleep_for(std::chrono::milliseconds(100));\n        alGetSourcei(source, AL_SOURCE_STATE, &state);\n    } while (state == AL_PLAYING);\n\n    // Clean up\n    alDeleteSources(1, &source);\n    alDeleteBuffers(1, &buffer);\n    alcMakeContextCurrent(nullptr);\n    alcDestroyContext(context);\n    alcCloseDevice(device);\n\n    return 0;\n}\n
" } ], "examples/cpp/graphics/android/custom_glue": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"app\")\n set_kind(\"binary\")\n add_files(\"src/*.c\")\n add_rules(\"android.native_app\", {\n android_manifest = \"src/android/AndroidManifest.xml\",\n package_name = \"com.xmake.custom_glue\",\n android_sdk_version = \"35\"\n })\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"app\")\n    set_kind(\"binary\")\n    add_files(\"src/*.c\")\n    add_rules(\"android.native_app\", {\n        android_manifest = \"src/android/AndroidManifest.xml\",\n        package_name = \"com.xmake.custom_glue\",\n        android_sdk_version = \"35\"\n    })\n
" }, { "name": "src/android/AndroidManifest.xml", "code": "\n\n\n \n\n \n \n \n \n \n \n \n \n \n\n", "language": "xml", "highlightedCode": "
<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"com.xmake.custom_glue\"\n    android:versionCode=\"1\"\n    android:versionName=\"1.0\" >\n\n    <uses-sdk\n        android:minSdkVersion=\"16\"\n        android:targetSdkVersion=\"35\" />\n\n    <application\n        android:hasCode=\"false\"\n        android:label=\"XmakeCustomGlue\" >\n        <activity\n            android:name=\"android.app.NativeActivity\"\n            android:label=\"XmakeCustomGlue\"\n            android:configChanges=\"orientation|keyboardHidden\">\n            <meta-data\n                android:name=\"android.app.lib_name\"\n                android:value=\"app\" />\n            <intent-filter>\n                <action android:name=\"android.intent.action.MAIN\" />\n                <category android:name=\"android.intent.category.LAUNCHER\" />\n            </intent-filter>\n        </activity>\n    </application>\n</manifest>\n
" }, { "name": "src/main.c", "code": "#include \n#include \n\n#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, \"custom_glue\", __VA_ARGS__))\n\nvoid android_main(struct android_app* state) {\n app_dummy();\n LOGI(\"Hello Custom Glue!\");\n while (1) {\n int ident;\n int events;\n struct android_poll_source* source;\n while ((ident = ALooper_pollAll(-1, NULL, &events, (void**)&source)) >= 0) {\n if (source != NULL) {\n source->process(state, source);\n }\n if (state->destroyRequested != 0) {\n return;\n }\n }\n }\n}\n", "language": "cpp", "highlightedCode": "
#include <android_native_app_glue.h>\n#include <android/log.h>\n\n#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, \"custom_glue\", __VA_ARGS__))\n\nvoid android_main(struct android_app* state) {\n    app_dummy();\n    LOGI(\"Hello Custom Glue!\");\n    while (1) {\n        int ident;\n        int events;\n        struct android_poll_source* source;\n        while ((ident = ALooper_pollAll(-1, NULL, &events, (void**)&source)) >= 0) {\n            if (source != NULL) {\n                source->process(state, source);\n            }\n            if (state->destroyRequested != 0) {\n                return;\n            }\n        }\n    }\n}\n
" } ], "examples/cpp/graphics/android/app": [ { "name": "xmake.lua", "code": "add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"android_app\")\n set_kind(\"binary\")\n add_files(\"src/*.cpp\")\n add_rules(\"android.native_app\", {\n android_manifest = \"src/android/AndroidManifest.xml\",\n package_name = \"com.xmake.demo\",\n android_sdk_version = \"35\"\n })\n", "language": "lua", "highlightedCode": "
add_rules(\"mode.debug\", \"mode.release\")\n\ntarget(\"android_app\")\n    set_kind(\"binary\")\n    add_files(\"src/*.cpp\")\n    add_rules(\"android.native_app\", {\n        android_manifest = \"src/android/AndroidManifest.xml\",\n        package_name = \"com.xmake.demo\",\n        android_sdk_version = \"35\"\n    })\n
" }, { "name": "src/android/AndroidManifest.xml", "code": "\n\n \n \n \n \n \n \n \n \n \n \n\n", "language": "xml", "highlightedCode": "
<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"com.xmake.demo\"\n    android:versionCode=\"1\"\n    android:versionName=\"1.0\" >\n    <uses-sdk android:minSdkVersion=\"16\" android:targetSdkVersion=\"35\" />\n    <application android:label=\"XmakeDemo\" android:hasCode=\"false\">\n        <activity android:name=\"android.app.NativeActivity\"\n                  android:label=\"XmakeDemo\"\n                  android:configChanges=\"orientation|keyboardHidden\">\n            <meta-data android:name=\"android.app.lib_name\" android:value=\"android_app\" />\n            <intent-filter>\n                <action android:name=\"android.intent.action.MAIN\" />\n                <category android:name=\"android.intent.category.LAUNCHER\" />\n            </intent-filter>\n        </activity>\n    </application>\n</manifest>\n
" }, { "name": "src/main.cpp", "code": "#include \n#include \n\n#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, \"xmake-demo\", __VA_ARGS__))\n\nvoid android_main(struct android_app* state) {\n app_dummy();\n LOGI(\"Hello Xmake on Android!\");\n while (1) {\n int ident;\n int events;\n struct android_poll_source* source;\n while ((ident = ALooper_pollAll(-1, NULL, &events, (void**)&source)) >= 0) {\n if (source != NULL) {\n source->process(state, source);\n }\n if (state->destroyRequested != 0) {\n return;\n }\n }\n }\n}\n", "language": "cpp", "highlightedCode": "
#include <android_native_app_glue.h>\n#include <android/log.h>\n\n#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, \"xmake-demo\", __VA_ARGS__))\n\nvoid android_main(struct android_app* state) {\n    app_dummy();\n    LOGI(\"Hello Xmake on Android!\");\n    while (1) {\n        int ident;\n        int events;\n        struct android_poll_source* source;\n        while ((ident = ALooper_pollAll(-1, NULL, &events, (void**)&source)) >= 0) {\n            if (source != NULL) {\n                source->process(state, source);\n            }\n            if (state->destroyRequested != 0) {\n                return;\n            }\n        }\n    }\n}\n
" } ], "examples/configuration/namespace_isolation/basic/src1": [ { "name": "xmake.lua", "code": "target(\"lib\")\n set_kind(\"static\")\n add_files(\"main.cpp\")\n add_defines(\"NS1_LIB\")\n", "language": "lua", "highlightedCode": "
target(\"lib\")\n    set_kind(\"static\")\n    add_files(\"main.cpp\")\n    add_defines(\"NS1_LIB\")\n
" }, { "name": "main.cpp", "code": "#include \n\nvoid lib1_hello() {\n std::cout << \"hello from ns1::lib\" << std::endl;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nvoid lib1_hello() {\n    std::cout << \"hello from ns1::lib\" << std::endl;\n}\n
" } ], "examples/configuration/namespace_isolation/basic/src2": [ { "name": "xmake.lua", "code": "target(\"lib\")\n set_kind(\"static\")\n add_files(\"main.cpp\")\n add_defines(\"NS2_LIB\")\n", "language": "lua", "highlightedCode": "
target(\"lib\")\n    set_kind(\"static\")\n    add_files(\"main.cpp\")\n    add_defines(\"NS2_LIB\")\n
" }, { "name": "main.cpp", "code": "#include \n\nvoid lib2_hello() {\n std::cout << \"hello from ns2::lib\" << std::endl;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nvoid lib2_hello() {\n    std::cout << \"hello from ns2::lib\" << std::endl;\n}\n
" } ], "examples/configuration/namespace_isolation/basic/src": [ { "name": "xmake.lua", "code": "target(\"test\")\n set_kind(\"static\")\n add_files(\"test.cpp\")\n", "language": "lua", "highlightedCode": "
target(\"test\")\n    set_kind(\"static\")\n    add_files(\"test.cpp\")\n
" }, { "name": "main.cpp", "code": "extern void lib1_hello();\nextern void lib2_hello();\n\nint main(int argc, char** argv) {\n lib1_hello();\n lib2_hello();\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
extern void lib1_hello();\nextern void lib2_hello();\n\nint main(int argc, char** argv) {\n    lib1_hello();\n    lib2_hello();\n    return 0;\n}\n
" }, { "name": "test.cpp", "code": "#include \n\nvoid test() {\n std::cout << \"hello from ns1::test!\" << std::endl;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nvoid test() {\n    std::cout << \"hello from ns1::test!\" << std::endl;\n}\n
" } ], "examples/configuration/multi_level_directories/basic/src": [ { "name": "xmake.lua", "code": "target(\"test\")\n set_kind(\"binary\")\n add_files(\"main.cpp\")\n", "language": "lua", "highlightedCode": "
target(\"test\")\n    set_kind(\"binary\")\n    add_files(\"main.cpp\")\n
" }, { "name": "main.cpp", "code": "#include \n\nint main(int argc, char** argv) {\n std::cout << \"hello world!\" << std::endl;\n return 0;\n}\n", "language": "cpp", "highlightedCode": "
#include <iostream>\n\nint main(int argc, char** argv) {\n    std::cout << \"hello world!\" << std::endl;\n    return 0;\n}\n
" } ], "examples/configuration/custom_toolchain/unknown_toolchain/xmake/toolchains/my-c6000": [ { "name": "xmake.lua", "code": "toolchain(\"my-c6000\")\n set_kind(\"standalone\")\n set_homepage(\"https://www.ti.com\")\n set_description(\"TI-CGT C6000 compiler\")\n\n set_toolset(\"cc\", \"cl6x\")\n set_toolset(\"cxx\", \"cl6x\")\n set_toolset(\"ld\", \"cl6x\")\n set_toolset(\"sh\", \"cl6x\")\n set_toolset(\"ar\", \"ar6x\")\n set_toolset(\"strip\", \"strip6x\")\n set_toolset(\"as\", \"cl6x\")\n\n on_check(function (toolchain)\n return import(\"lib.detect.find_tool\")(\"cl6x\")\n end)\n\n on_load(function (toolchain)\n toolchain:add(\"cxflags\", \"-Dxxx\")\n end)\n", "language": "lua", "highlightedCode": "
toolchain(\"my-c6000\")\n    set_kind(\"standalone\")\n    set_homepage(\"https://www.ti.com\")\n    set_description(\"TI-CGT C6000 compiler\")\n\n    set_toolset(\"cc\", \"cl6x\")\n    set_toolset(\"cxx\", \"cl6x\")\n    set_toolset(\"ld\", \"cl6x\")\n    set_toolset(\"sh\", \"cl6x\")\n    set_toolset(\"ar\", \"ar6x\")\n    set_toolset(\"strip\", \"strip6x\")\n    set_toolset(\"as\", \"cl6x\")\n\n    on_check(function (toolchain)\n        return import(\"lib.detect.find_tool\")(\"cl6x\")\n    end)\n\n    on_load(function (toolchain)\n        toolchain:add(\"cxflags\", \"-Dxxx\")\n    end)\n
" } ] }