-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
System_cxx_toolchain improvements for MSVC support
- Loading branch information
Showing
6 changed files
with
339 additions
and
18 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
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,18 @@ | ||
load(":tools.bzl", "find_msvc_tools") | ||
|
||
python_bootstrap_binary( | ||
name = "vswhere", | ||
main = "vswhere.py", | ||
visibility = [], | ||
) | ||
|
||
python_bootstrap_binary( | ||
name = "run_msvc_tool", | ||
main = "run_msvc_tool.py", | ||
visibility = [], | ||
) | ||
|
||
find_msvc_tools( | ||
name = "msvc_tools", | ||
visibility = ["toolchains//..."], | ||
) |
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,40 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import json | ||
import os | ||
import subprocess | ||
import sys | ||
from typing import List, NamedTuple | ||
|
||
|
||
class Tool(NamedTuple): | ||
exe: str | ||
libs: List[str] | ||
paths: List[str] | ||
includes: List[str] | ||
|
||
|
||
def add_env(env, key, entries): | ||
entries = ";".join(entries) | ||
if key in env: | ||
env[key] = entries + ";" + env[key] | ||
else: | ||
env[key] = entries | ||
|
||
|
||
def main(): | ||
tool_json, arguments = sys.argv[1], sys.argv[2:] | ||
with open(tool_json, encoding="utf-8") as f: | ||
tool = Tool(**json.load(f)) | ||
|
||
env = os.environ.copy() | ||
add_env(env, "LIB", tool.libs) | ||
add_env(env, "PATH", tool.paths) | ||
add_env(env, "INCLUDE", tool.includes) | ||
|
||
completed_process = subprocess.run([tool.exe, *arguments], env=env) | ||
sys.exit(completed_process.returncode) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,65 @@ | ||
load("@prelude//utils:cmd_script.bzl", "ScriptOs", "cmd_script") | ||
|
||
VisualStudio = provider(fields = [ | ||
# Path to cl.exe | ||
"cl_exe", | ||
# Path to lib.exe | ||
"lib_exe", | ||
# Path to ml64.exe | ||
"ml64_exe", | ||
]) | ||
|
||
def _find_msvc_tools_impl(ctx: AnalysisContext) -> ["provider"]: | ||
cl_exe_json = ctx.actions.declare_output("cl.exe.json") | ||
lib_exe_json = ctx.actions.declare_output("lib.exe.json") | ||
ml64_exe_json = ctx.actions.declare_output("ml64.exe.json") | ||
|
||
cmd = [ | ||
ctx.attrs.vswhere[RunInfo], | ||
cmd_args("--cl=", cl_exe_json.as_output(), delimiter = ""), | ||
cmd_args("--lib=", lib_exe_json.as_output(), delimiter = ""), | ||
cmd_args("--ml64=", ml64_exe_json.as_output(), delimiter = ""), | ||
] | ||
|
||
ctx.actions.run( | ||
cmd, | ||
category = "vswhere", | ||
local_only = True, | ||
) | ||
|
||
run_msvc_tool = ctx.attrs.run_msvc_tool[RunInfo] | ||
cl_exe_script = cmd_script( | ||
ctx = ctx, | ||
name = "cl", | ||
cmd = cmd_args(run_msvc_tool, cl_exe_json), | ||
os = ScriptOs("windows"), | ||
) | ||
lib_exe_script = cmd_script( | ||
ctx = ctx, | ||
name = "lib", | ||
cmd = cmd_args(run_msvc_tool, lib_exe_json), | ||
os = ScriptOs("windows"), | ||
) | ||
ml64_exe_script = cmd_script( | ||
ctx = ctx, | ||
name = "ml64", | ||
cmd = cmd_args(run_msvc_tool, ml64_exe_json), | ||
os = ScriptOs("windows"), | ||
) | ||
|
||
return [ | ||
DefaultInfo(), | ||
VisualStudio( | ||
cl_exe = cl_exe_script, | ||
lib_exe = lib_exe_script, | ||
ml64_exe = ml64_exe_script, | ||
), | ||
] | ||
|
||
find_msvc_tools = rule( | ||
impl = _find_msvc_tools_impl, | ||
attrs = { | ||
"run_msvc_tool": attrs.default_only(attrs.dep(providers = [RunInfo], default = "toolchains//msvc:run_msvc_tool")), | ||
"vswhere": attrs.default_only(attrs.dep(providers = [RunInfo], default = "toolchains//msvc:vswhere")), | ||
}, | ||
) |
Oops, something went wrong.