fix(build): handle assembly and reject sources meowc cannot compile
This commit is contained in:
4 files changed
+30
-11
No files matched your search
+13
-4
@@ -43,6 +43,12 @@ let includes_of p (t : target) =
|
|||||||
let inherited = List.concat_map (fun (d : target) -> d.includes) (deps_of p t) in
|
let inherited = List.concat_map (fun (d : target) -> d.includes) (deps_of p t) in
|
||||||
List.sort_uniq compare (t.includes @ inherited @ config_dir p)
|
List.sort_uniq compare (t.includes @ inherited @ config_dir p)
|
||||||
|
|
||||||
|
(* A compiler only writes a depfile when it preprocesses, which for assembly
|
||||||
|
means .S and not .s. Asking for one that never appears would leave the action
|
||||||
|
permanently out of date. *)
|
||||||
|
let tracks_deps src =
|
||||||
|
match lang_of src with Asm -> Filename.extension src = ".S" | C | Cxx -> true
|
||||||
|
|
||||||
let compile_cmd p ~pic (t : target) src obj =
|
let compile_cmd p ~pic (t : target) src obj =
|
||||||
let lang = lang_of src in
|
let lang = lang_of src in
|
||||||
let driver = match lang with Cxx -> p.tc.cxx | _ -> p.tc.cc in
|
let driver = match lang with Cxx -> p.tc.cxx | _ -> p.tc.cc in
|
||||||
@@ -59,7 +65,8 @@ let compile_cmd p ~pic (t : target) src obj =
|
|||||||
@ List.concat_map (fun d -> [ "-D"; d ]) t.defines
|
@ List.concat_map (fun d -> [ "-D"; d ]) t.defines
|
||||||
@ List.concat_map (fun d -> [ "-I"; d ]) (includes_of p t)
|
@ List.concat_map (fun d -> [ "-I"; d ]) (includes_of p t)
|
||||||
in
|
in
|
||||||
Array.of_list (((driver :: flags) @ [ "-MMD"; "-MF"; obj ^ ".d" ]) @ [ "-c"; src; "-o"; obj ])
|
let dep = if tracks_deps src then [ "-MMD"; "-MF"; obj ^ ".d" ] else [] in
|
||||||
|
Array.of_list (((driver :: flags) @ dep) @ [ "-c"; src; "-o"; obj ])
|
||||||
|
|
||||||
let link_libs p (t : target) =
|
let link_libs p (t : target) =
|
||||||
let deps = List.rev (deps_of p t) in
|
let deps = List.rev (deps_of p t) in
|
||||||
@@ -116,10 +123,11 @@ let of_project p =
|
|||||||
(fun src ->
|
(fun src ->
|
||||||
let obj = obj_of p t src in
|
let obj = obj_of p t src in
|
||||||
let cmd = compile_cmd p ~pic t src obj in
|
let cmd = compile_cmd p ~pic t src obj in
|
||||||
let tag = if lang_of src = Cxx then "c++" else "cc" in
|
let tag = match lang_of src with Cxx -> "c++" | Asm -> "as" | C -> "cc" in
|
||||||
|
let depfile = if tracks_deps src then Some (obj ^ ".d") else None in
|
||||||
add
|
add
|
||||||
(Graph.make ~id:!n ~tag ~label:src ~cmd ~outs:[ obj ] ~ins:[ src ]
|
(Graph.make ~id:!n ~tag ~label:src ~cmd ~outs:[ obj ] ~ins:[ src ] ?depfile
|
||||||
~depfile:(obj ^ ".d") ~ords:gen_headers ~rsp:(obj ^ ".rsp") ());
|
~ords:gen_headers ~rsp:(obj ^ ".rsp") ());
|
||||||
obj)
|
obj)
|
||||||
(all_srcs t)
|
(all_srcs t)
|
||||||
in
|
in
|
||||||
@@ -142,6 +150,7 @@ let paint tag text =
|
|||||||
match tag with
|
match tag with
|
||||||
| "cc" -> Style.blue text
|
| "cc" -> Style.blue text
|
||||||
| "c++" -> Style.blue text
|
| "c++" -> Style.blue text
|
||||||
|
| "as" -> Style.magenta text
|
||||||
| "ar" -> Style.magenta text
|
| "ar" -> Style.magenta text
|
||||||
| "so" -> Style.cyan text
|
| "so" -> Style.cyan text
|
||||||
| "ld" -> Style.green text
|
| "ld" -> Style.green text
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@ let render (b : Build.t) =
|
|||||||
let dir = Sys.getcwd () in
|
let dir = Sys.getcwd () in
|
||||||
let entries =
|
let entries =
|
||||||
Array.to_list b.g.Graph.nodes
|
Array.to_list b.g.Graph.nodes
|
||||||
|> List.filter (fun (n : Graph.node) -> n.tag = "cc" || n.tag = "c++")
|
|> List.filter (fun (n : Graph.node) -> List.mem n.tag [ "cc"; "c++"; "as" ])
|
||||||
|> List.map (fun (n : Graph.node) ->
|
|> List.map (fun (n : Graph.node) ->
|
||||||
Printf.sprintf
|
Printf.sprintf
|
||||||
" {\n \"directory\": %s,\n \"file\": %s,\n \"output\": %s,\n \"arguments\": %s\n }"
|
" {\n \"directory\": %s,\n \"file\": %s,\n \"output\": %s,\n \"arguments\": %s\n }"
|
||||||
@@ -15,5 +15,5 @@ let render (b : Build.t) =
|
|||||||
let write b path =
|
let write b path =
|
||||||
Fs.write path (render b);
|
Fs.write path (render b);
|
||||||
List.length
|
List.length
|
||||||
(List.filter (fun (n : Graph.node) -> n.Graph.tag = "cc" || n.Graph.tag = "c++")
|
(List.filter (fun (n : Graph.node) -> List.mem n.Graph.tag [ "cc"; "c++"; "as" ])
|
||||||
(Array.to_list b.Build.g.Graph.nodes))
|
(Array.to_list b.Build.g.Graph.nodes))
|
||||||
@@ -134,6 +134,13 @@ let sources_of ~extra ((b : block), base) (t : target) =
|
|||||||
Diag.error ~span:b.nspan
|
Diag.error ~span:b.nspan
|
||||||
~hint:(Printf.sprintf "no file matches %s" (String.concat " " pats))
|
~hint:(Printf.sprintf "no file matches %s" (String.concat " " pats))
|
||||||
"%s %s matched no sources" b.kind b.bname;
|
"%s %s matched no sources" b.kind b.bname;
|
||||||
|
List.iter
|
||||||
|
(fun f ->
|
||||||
|
if lang_opt f = None then
|
||||||
|
Diag.error ~span:b.nspan
|
||||||
|
~hint:("meowc compiles " ^ String.concat " " source_exts)
|
||||||
|
"%s %s lists %s, which is not a source meowc can compile" b.kind b.bname f)
|
||||||
|
files;
|
||||||
let gen, real = List.partition (fun f -> List.mem f extra) files in
|
let gen, real = List.partition (fun f -> List.mem f extra) files in
|
||||||
{ t with srcs = real; gen_srcs = gen }
|
{ t with srcs = real; gen_srcs = gen }
|
||||||
|
|
||||||
|
|||||||
+8
-5
@@ -77,10 +77,13 @@ let uniq_targets ts =
|
|||||||
|
|
||||||
let order p ts = uniq_targets (List.concat_map (fun t -> deps_of p t @ [ t ]) ts)
|
let order p ts = uniq_targets (List.concat_map (fun t -> deps_of p t @ [ t ]) ts)
|
||||||
|
|
||||||
let lang_of path =
|
let langs =
|
||||||
match String.lowercase_ascii (Filename.extension path) with
|
[ (".c", C); (".m", C);
|
||||||
| ".cc" | ".cpp" | ".cxx" | ".c++" | ".mm" -> Cxx
|
(".cc", Cxx); (".cpp", Cxx); (".cxx", Cxx); (".c++", Cxx); (".mm", Cxx);
|
||||||
| ".s" | ".asm" -> Asm
|
(".s", Asm); (".asm", Asm) ]
|
||||||
| _ -> C
|
|
||||||
|
let source_exts = List.map fst langs
|
||||||
|
let lang_opt path = List.assoc_opt (String.lowercase_ascii (Filename.extension path)) langs
|
||||||
|
let lang_of path = Option.value (lang_opt path) ~default:C
|
||||||
|
|
||||||
let all_srcs t = t.srcs @ t.gen_srcs
|
let all_srcs t = t.srcs @ t.gen_srcs
|
||||||
Reference in new issue
Block a user