diff options
| author | ruki <[email protected]> | 2023-03-02 12:35:14 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-03-02 12:35:14 +0800 |
| commit | 5afbc8e9f237b3c782b75183c11ca5b2ed41e661 (patch) | |
| tree | aabe89d41d0dc5a316d000e29063d141a9120706 | |
| parent | 415c4ad77003cd20d9f4edeb813fafb6dd31b3ba (diff) | |
| parent | 6124bdc45b728effde95f96cf57aac7b21f0e20a (diff) | |
Merge pull request #3442 from xmake-io/package
improve plat/arch for package
| -rw-r--r-- | tests/projects/package/multiplat/.gitignore | 8 | ||||
| -rw-r--r-- | tests/projects/package/multiplat/src/main.cpp | 62 | ||||
| -rw-r--r-- | tests/projects/package/multiplat/xmake.lua | 18 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 29 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/package/package.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/package.lua | 9 |
6 files changed, 122 insertions, 8 deletions
diff --git a/tests/projects/package/multiplat/.gitignore b/tests/projects/package/multiplat/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/package/multiplat/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/package/multiplat/src/main.cpp b/tests/projects/package/multiplat/src/main.cpp new file mode 100644 index 000000000..ae4174e80 --- /dev/null +++ b/tests/projects/package/multiplat/src/main.cpp @@ -0,0 +1,62 @@ +/******************************************************************************************* +* +* raylib [core] example - Basic window +* +* Welcome to raylib! +* +* To test examples, just press F6 and execute raylib_compile_execute script +* Note that compiled executable is placed in the same folder as .c file +* +* You can find all basic examples on C:\raylib\raylib\examples folder or +* raylib official webpage: www.raylib.com +* +* Enjoy using raylib. :) +* +* This example has been created using raylib 1.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/tests/projects/package/multiplat/xmake.lua b/tests/projects/package/multiplat/xmake.lua new file mode 100644 index 000000000..a9b51b77d --- /dev/null +++ b/tests/projects/package/multiplat/xmake.lua @@ -0,0 +1,18 @@ +add_rules("mode.debug", "mode.release") + +add_requires("raylib") +add_requires("raylib~mingw", {plat = "mingw", arch = "x86_64"}) + +target("hello") + add_packages("raylib") + set_kind("binary") + add_files("src/*.cpp") + set_languages("c++11") + +target("hello_mingw") + set_plat("mingw") + set_arch("x86_64") + add_packages("raylib~mingw") + set_kind("binary") + add_files("src/*.cpp") + diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 28a130405..c0b60d289 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -2445,9 +2445,10 @@ function package.load_from_project(packagename, project) end -- load the package from the package directory or package description file -function package.load_from_repository(packagename, repo, packagedir, packagefile) +function package.load_from_repository(packagename, repo, packagedir, opt) -- get it directly from cache first + opt = opt or {} local instance = package._memcache():get2("packages", packagename) if instance then return instance @@ -2459,8 +2460,8 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile end -- find the package script path - local scriptpath = packagefile - if not packagefile and packagedir then + local scriptpath = opt.packagefile + if not opt.packagefile and packagedir then scriptpath = path.join(packagedir, "xmake.lua") end if not scriptpath or not os.isfile(scriptpath) then @@ -2470,6 +2471,20 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile -- get interpreter local interp = package._interpreter() + -- we need modify plat/arch in description scope at same time + -- if plat/arch are passed to add_requires. + -- + -- @see https://github.com/orgs/xmake-io/discussions/3439 + -- + -- e.g. add_requires("zlib~mingw", {plat = "mingw", arch = "x86_64"}) + -- + if opt.plat then + package._memcache():set("target_plat", opt.plat) + end + if opt.arch then + package._memcache():set("target_arch", opt.arch) + end + -- load script local ok, errors = interp:load(scriptpath) if not ok then @@ -2491,6 +2506,14 @@ function package.load_from_repository(packagename, repo, packagedir, packagefile -- new an instance instance = _instance.new(packagename, packageinfo, {scriptdir = path.directory(scriptpath), repo = repo}) + -- reset plat/arch + if opt.plat then + package._memcache():set("target_plat", nil) + end + if opt.arch then + package._memcache():set("target_arch", nil) + end + -- save instance to the cache package._memcache():set2("packages", instance) return instance diff --git a/xmake/core/sandbox/modules/import/core/package/package.lua b/xmake/core/sandbox/modules/import/core/package/package.lua index f1ec8799f..906033fde 100644 --- a/xmake/core/sandbox/modules/import/core/package/package.lua +++ b/xmake/core/sandbox/modules/import/core/package/package.lua @@ -52,8 +52,8 @@ function sandbox_core_package_package.load_from_system(packagename) end -- load the package from repositories -function sandbox_core_package_package.load_from_repository(packagename, repo, packagedir, packagefile) - local instance, errors = package.load_from_repository(packagename, repo, packagedir, packagefile) +function sandbox_core_package_package.load_from_repository(packagename, repo, packagedir, opt) + local instance, errors = package.load_from_repository(packagename, repo, packagedir, opt) if not instance then raise(errors) end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index f85a0095c..79801d675 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -167,7 +167,6 @@ function _load_require(require_str, requires_extra, parentinfo) "verify", "external", "private", "build", "configs", "version") for name, value in pairs(require_extra) do if not extra_options:has(name) then - print("not found") wprint("add_requires(\"%s\") has unknown option: {%s=%s}!", require_str, name, tostring(value)) end end @@ -212,9 +211,10 @@ end -- load package package from repositories function _load_package_from_repository(packagename, opt) + opt = opt or {} local packagedir, repo = repository.packagedir(packagename, opt) if packagedir then - return core_package.load_from_repository(packagename, repo, packagedir) + return core_package.load_from_repository(packagename, repo, packagedir, {plat = opt.plat, arch = opt.arch}) end end @@ -750,7 +750,10 @@ function _load_package(packagename, requireinfo, opt) local from_repo = false if not package then package = _load_package_from_repository(packagename, { - name = requireinfo.reponame, locked_repo = locked_requireinfo and locked_requireinfo.repo}) + plat = requireinfo.plat, + arch = requireinfo.arch, + name = requireinfo.reponame, + locked_repo = locked_requireinfo and locked_requireinfo.repo}) if package then from_repo = true end |
