-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #516 from bitonality/main
Introduction of the cargo.build rule to manage patternsleuth as a target
- Loading branch information
Showing
8 changed files
with
359 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-- If patternsleuth is configured to install as a package. | ||
add_requires("cargo::patternsleuth_bind", { optional = not is_config("patternsleuth", "package"), debug = is_mode_debug(), configs = { cargo_toml = path.join(os.scriptdir(), "Cargo.toml") } }) | ||
|
||
target("patternsleuth_bind") | ||
set_kind("static") | ||
set_values("rust.cratetype", "staticlib") | ||
add_files("src/lib.rs") | ||
-- Exposes the src/lib.rs files to the Visual Studio project filters. | ||
add_extrafiles("src/lib.rs") | ||
|
||
-- If patternsleuth is configured to install as a package. | ||
if is_config("patternsleuth", "package") then | ||
add_packages("cargo::patternsleuth_bind") | ||
add_links("ws2_32", "advapi32", "userenv", "ntdll", "oleaut32", "bcrypt", "ole32", { public = true }) | ||
end | ||
|
||
-- If patternsleuth should be built as part of compilation. | ||
if is_config("patternsleuth", "local") then | ||
add_deps("patternsleuth") | ||
add_rules("rust.link") | ||
end | ||
|
||
-- We need to clean up the non-selected package/local version of patternsleuth when we reconfigure. | ||
-- This just deletes the .lib and keeps cargo deps on disk for faster recompilation. | ||
on_config(function(target) | ||
os.tryrm(target:targetfile()) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
---@alias rust_mode "dev" | "release" | ||
|
||
--- Takes a target and returns context variables to be used in on_xxx overrides. | ||
---@param target any xmake target | ||
---@param is_debug boolean Should we get the debug or release context? | ||
---@return string cargo_dir The root cargo dir for the project. Ex. Intermediates/Cargo/target/ | ||
---@return string cargo_mode_dir The cargo dir for the debug/release config. Ex. Intermediates/Cargo/target/debug/ | ||
---@return rust_mode rust_mode The rust flavor of mode derrived from is_debug param. | ||
function get_cargo_context(target, is_debug) | ||
local rust_mode = is_debug and "dev" or "release" | ||
local rust_mode_dir = is_debug and "debug" or "release" | ||
local cargo_dir = path.join(get_config("buildir"), "cargo", target:name()) | ||
return cargo_dir, path.join(cargo_dir, rust_mode_dir), rust_mode | ||
end | ||
|
||
--- Parses ".d" files created by Cargo. | ||
---@param file string Path to a ".d" file created by Cargo | ||
---@return string[] cargo_deps A list of any src files that should trigger a rebuild. | ||
function get_dependencies(file) | ||
if not os.exists(file) then | ||
return {} | ||
end | ||
|
||
local data = io.readfile(file) | ||
data = data:trim() | ||
local start = data:find(": ", 1, false) | ||
local deps = data:sub(start + 2):split(" ", {strict = false, plain = true}) | ||
|
||
local parsed_deps = {} | ||
local dep = "" | ||
local dep_idx = 1 | ||
while dep do | ||
dep = deps[dep_idx] | ||
if dep then | ||
while dep:endswith("\\") do | ||
dep_idx = dep_idx + 1 | ||
dep = dep:sub(1, -2) .. " " .. deps[dep_idx] | ||
end | ||
table.insert(parsed_deps, dep) | ||
dep_idx = dep_idx + 1 | ||
end | ||
end | ||
|
||
return parsed_deps | ||
end | ||
|
||
--[[ | ||
The previous function is based on the cargo impl of internal .d parsing. | ||
let mut deps = line[pos + 2..].split_whitespace(); | ||
while let Some(s) = deps.next() { | ||
let mut file = s.to_string(); | ||
while file.ends_with('\\') { | ||
file.pop(); | ||
file.push(' '); | ||
file.push_str(deps.next().ok_or_else(|| { | ||
internal("malformed dep-info format, trailing \\".to_string()) | ||
})?); | ||
} | ||
ret.files.push(file.into()); | ||
} | ||
]]-- |
Oops, something went wrong.