Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add -output-obj rules for ocamlbuild #6059

Closed
vicuna opened this issue Jun 29, 2013 · 7 comments
Closed

add -output-obj rules for ocamlbuild #6059

vicuna opened this issue Jun 29, 2013 · 7 comments

Comments

@vicuna
Copy link

vicuna commented Jun 29, 2013

Original bug ID: 6059
Reporter: @avsm
Assigned to: @gasche
Status: resolved (set by @gasche on 2013-08-06T19:01:04Z)
Resolution: suspended
Priority: normal
Severity: feature
Category: -for ocamlbuild use https://github.com/ocaml/ocamlbuild/issues
Tags: junior_job

Bug description

Add -output-obj rules to ocamlbuild for byte and native code.

Three rules are added:
%.byte.o : bytecode object file
%.byte.c : bytecode source C file
%.native.o : native code object file

avsm@fde233b
or
https://github.com/avsm/ocaml/commit/fde233bdad4f9512d040764e86c9e7d2cfd0cda7.patch

From fde233b Mon Sep 17 00:00:00 2001
From: Anil Madhavapeddy anil@recoil.org
Date: Sat, 29 Jun 2013 18:54:26 +0100
Subject: [PATCH] Add -output-obj rules to ocamlbuild for byte and native code

Three rules are added:
%.byte.o : bytecode object file
%.byte.c : bytecode source C file
%.native.o : native code object file

ocamlbuild/ocaml_compiler.ml | 6 ++++++
ocamlbuild/ocaml_compiler.mli | 2 ++
ocamlbuild/ocaml_specific.ml | 18 ++++++++++++++++++
3 files changed, 26 insertions(+)

diff --git a/ocamlbuild/ocaml_compiler.ml b/ocamlbuild/ocaml_compiler.ml
index 218842f..39a68f8 100644
--- a/ocamlbuild/ocaml_compiler.ml
+++ b/ocamlbuild/ocaml_compiler.ml
@@ -231,6 +231,9 @@ let byte_link_gen = link_gen "cmo" "cma" "cma" ["cmo"; "cmi"]
let byte_link = byte_link_gen ocamlc_link_prog
(fun tags -> tags++"ocaml"++"link"++"byte"++"program")

+let byte_output_obj = byte_link_gen ocamlc_link_prog

  • (fun tags -> tags++"ocaml"++"link"++"byte"++"output_obj")

let byte_library_link = byte_link_gen byte_lib_linker byte_lib_linker_tags

let byte_debug_link_gen =
@@ -248,6 +251,9 @@ let native_link_gen linker =
let native_link x = native_link_gen ocamlopt_link_prog
(fun tags -> tags++"ocaml"++"link"++"native"++"program") x

+let native_output_obj x = native_link_gen ocamlopt_link_prog

  • (fun tags -> tags++"ocaml"++"link"++"native"++"output_obj") x

let native_library_link x =
native_link_gen native_lib_linker native_lib_linker_tags x

diff --git a/ocamlbuild/ocaml_compiler.mli b/ocamlbuild/ocaml_compiler.mli
index 667191a..24c3695 100644
--- a/ocamlbuild/ocaml_compiler.mli
+++ b/ocamlbuild/ocaml_compiler.mli
@@ -41,10 +41,12 @@ val link_gen :
(Tags.t -> Tags.t) ->
string -> string -> Rule.action
val byte_link : string -> string -> Rule.action
+val byte_output_obj : string -> string -> Rule.action
val byte_library_link : string -> string -> Rule.action
val byte_debug_link : string -> string -> Rule.action
val byte_debug_library_link : string -> string -> Rule.action
val native_link : string -> string -> Rule.action
+val native_output_obj : string -> string -> Rule.action
val native_library_link : string -> string -> Rule.action
val native_shared_library_link : ?tags:(string list) -> string -> string -> Rule.action
val native_profile_link : string -> string -> Rule.action
diff --git a/ocamlbuild/ocaml_specific.ml b/ocamlbuild/ocaml_specific.ml
index c433025..a5873ae 100644
--- a/ocamlbuild/ocaml_specific.ml
+++ b/ocamlbuild/ocaml_specific.ml
@@ -160,6 +160,18 @@ rule "ocaml: cmo* -> byte"
~dep:"%.cmo"
(Ocaml_compiler.byte_link "%.cmo" "%.byte");;

+rule "ocaml: cmo* -> byte.o"

  • ~tags:["ocaml"; "byte"; "link"; "output_obj" ]
  • ~prod:"%.byte.o"
  • ~dep:"%.cmo"
  • (Ocaml_compiler.byte_output_obj "%.cmo" "%.byte.o");;

+rule "ocaml: cmo* -> byte.c"

  • ~tags:["ocaml"; "byte"; "link"; "output_obj" ]
  • ~prod:"%.byte.c"
  • ~dep:"%.cmo"
  • (Ocaml_compiler.byte_output_obj "%.cmo" "%.byte.c");;

rule "ocaml: p.cmx* & p.o* -> p.native"
~tags:["ocaml"; "native"; "profile"; "program"]
~prod:"%.p.native"
@@ -172,6 +184,12 @@ rule "ocaml: cmx* & o* -> native"
~deps:["%.cmx"; x_o]
(Ocaml_compiler.native_link "%.cmx" "%.native");;

+rule "ocaml: cmx* & o* -> native.o"

  • ~tags:["ocaml"; "native"; "output_obj" ]
  • ~prod:"%.native.o"
  • ~deps:["%.cmx"; x_o]
  • (Ocaml_compiler.native_output_obj "%.cmx" "%.native.o");;

rule "ocaml: mllib & d.cmo* -> d.cma"
~tags:["ocaml"; "byte"; "debug"; "library"]
~prod:"%.d.cma"

1.8.1.6

Steps to reproduce

$ ocamlbuild.byte -classic-display t.native.o
/usr/local/bin/ocamldep.opt -modules t.ml > t.ml.depends
/usr/local/bin/ocamlc.opt -c -o t.cmo t.ml
/usr/local/bin/ocamlopt.opt -c -o t.cmx t.ml
/usr/local/bin/ocamlopt.opt -output-obj t.cmx -o t.native.o
$ ocamlbuild.byte -classic-display t.byte.o
/usr/local/bin/ocamldep.opt -modules t.ml > t.ml.depends
/usr/local/bin/ocamlc.opt -c -o t.cmo t.ml
/usr/local/bin/ocamlc.opt -output-obj t.cmo -o t.byte.o

  • /usr/local/bin/ocamlc.opt -output-obj t.cmo -o t.byte.o
    clang: warning: argument unused during compilation: '-fno-defer-pop'
    $ ocamlbuild.byte -classic-display t.byte.c
    /usr/local/bin/ocamldep.opt -modules t.ml > t.ml.depends
    /usr/local/bin/ocamlc.opt -c -o t.cmo t.ml
    /usr/local/bin/ocamlc.opt -output-obj t.cmo -o t.byte.c
    $ ocamlbuild.byte -classic-display t.byte
    /usr/local/bin/ocamldep.opt -modules t.ml > t.ml.depends
    /usr/local/bin/ocamlc.opt -c -o t.cmo t.ml
    /usr/local/bin/ocamlc.opt t.cmo -o t.byte
    $ ocamlbuild/ocamlbuild.byte -classic-display t.native
    /usr/local/bin/ocamldep.opt -modules t.ml > t.ml.depends
    /usr/local/bin/ocamlc.opt -c -o t.cmo t.ml
    /usr/local/bin/ocamlopt.opt -c -o t.cmx t.ml
    /usr/local/bin/ocamlopt.opt t.cmx -o t.native

Additional information

I think this is the last rule needed for Mirage to compile up Xen kernels using vanilla ocamlbuild.

File attachments

@vicuna
Copy link
Author

vicuna commented Jun 29, 2013

Comment author: @gasche

The patch looks fine and Wojciech agrees this should be merged, so I'll commit it upstream soon.

Would you consider adding testcases to the testsuite corresponding to those new features? It is in the testsuite/ directory, and you can just edit the level0.ml file to add new test cases. It is rather self-descriptive and easy to write new tests.

@vicuna
Copy link
Author

vicuna commented Jun 29, 2013

Comment author: @avsm

Test case added and verified to work with the patch.
avsm@bb3a2c8
https://github.com/avsm/ocaml/commit/bb3a2c81970ebb4733dd700287193194929753cc.patch

From bb3a2c8 Mon Sep 17 00:00:00 2001
From: Anil Madhavapeddy anil@recoil.org
Date: Sat, 29 Jun 2013 21:35:27 +0100
Subject: [PATCH] add test case for fde233b


ocamlbuild/testsuite/level0.ml | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/ocamlbuild/testsuite/level0.ml b/ocamlbuild/testsuite/level0.ml
index c538910..52739e4 100644
--- a/ocamlbuild/testsuite/level0.ml
+++ b/ocamlbuild/testsuite/level0.ml
@@ -162,4 +162,9 @@ test "NoIncludeNoHygiene3"
(* will make hygiene fail if must_ignore/ is checked *)
~targets:("hello.byte",[]) ();;

+test "OutputObj"

run ~root:"_test";;

1.8.1.6

@vicuna
Copy link
Author

vicuna commented Jun 29, 2013

Comment author: @avsm

I've also made a cleanup patch intended for trunk (not 4.01) that removes the very confusing ~tags argument to Rule.rule, which is completely unused and serves only as a trap for an unwary ocamlbuild plugin developer.

https://github.com/avsm/ocaml/commit/168dabc8da8add283a7fa390ff700d97c3907974.patch
(this conflicts with the above patch very slightly, but should be easy to fix up)
I've only lightly tested it, so wouldn't recommend merging into the 4.1 branch.

From 168dabc Mon Sep 17 00:00:00 2001
From: Anil Madhavapeddy anil@recoil.org
Date: Sat, 29 Jun 2013 21:57:24 +0100
Subject: [PATCH] Remove the deprecated ocamlbuild Rule.rule ~tags argument.

It's very confusing leaving this here, because it's set in the
various rules but has absolutely no effect. The actual tags are
set by the rule bodies, which (almost) duplicate the tags that
are removed by this commit.

ocamlbuild/ocaml_specific.ml | 35 -----------------------------------
ocamlbuild/rule.ml | 20 ++++++++------------
ocamlbuild/rule.mli | 1 -
ocamlbuild/signatures.mli | 3 +--
4 files changed, 9 insertions(+), 50 deletions(-)

diff --git a/ocamlbuild/ocaml_specific.ml b/ocamlbuild/ocaml_specific.ml
index a4c6e46..2a9ea16 100644
--- a/ocamlbuild/ocaml_specific.ml
+++ b/ocamlbuild/ocaml_specific.ml
@@ -75,123 +75,103 @@ rule "target files"
end;;

rule "ocaml: mli -> cmi"

  • ~tags:["ocaml"]
    ~prod:"%.cmi"
    ~deps:["%.mli"; "%.mli.depends"]
    (Ocaml_compiler.compile_ocaml_interf "%.mli" "%.cmi");;

rule "ocaml: mlpack & d.cmo* -> d.cmo & cmi"

  • ~tags:["ocaml"; "debug"; "byte"]
    ~prods:["%.d.cmo"]
    ~deps:["%.mlpack"; "%.cmi"]
    (Ocaml_compiler.byte_debug_pack_mlpack "%.mlpack" "%.d.cmo");;

rule "ocaml: mlpack & cmo* & cmi -> cmo"

  • ~tags:["ocaml"; "byte"]
    ~prod:"%.cmo"
    ~deps:["%.mli"; "%.cmi"; "%.mlpack"]
    (Ocaml_compiler.byte_pack_mlpack "%.mlpack" "%.cmo");;

rule "ocaml: mlpack & cmo* -> cmo & cmi"

  • ~tags:["ocaml"; "byte"]
    ~prods:["%.cmo"; "%.cmi"]
    ~dep:"%.mlpack"
    (Ocaml_compiler.byte_pack_mlpack "%.mlpack" "%.cmo");;

rule "ocaml: ml & cmi -> d.cmo"

  • ~tags:["ocaml"; "byte"]
    ~prod:"%.d.cmo"
    ~deps:["%.mli"(* This one is inserted to force this rule to be skiped when
    a .ml is provided without a .mli *); "%.ml"; "%.ml.depends"; "%.cmi"]
    (Ocaml_compiler.byte_compile_ocaml_implem ~tag:"debug" "%.ml" "%.d.cmo");;

rule "ocaml: ml & cmi -> cmo"

  • ~tags:["ocaml"; "byte"]
    ~prod:"%.cmo"
    ~deps:["%.mli"(* This one is inserted to force this rule to be skiped when
    a .ml is provided without a .mli *); "%.ml"; "%.ml.depends"; "%.cmi"]
    (Ocaml_compiler.byte_compile_ocaml_implem "%.ml" "%.cmo");;

rule "ocaml: mlpack & cmi & p.cmx* & p.o* -> p.cmx & p.o"

  • ~tags:["ocaml"; "profile"; "native"]
    ~prods:["%.p.cmx"; x_p_o(* no cmi here you must make the byte version to have it *)]
    ~deps:["%.mlpack"; "%.cmi"]
    (Ocaml_compiler.native_profile_pack_mlpack "%.mlpack" "%.p.cmx");;

rule "ocaml: mlpack & cmi & cmx* & o* -> cmx & o"

  • ~tags:["ocaml"; "native"]
    ~prods:["%.cmx"; x_o(* no cmi here you must make the byte version to have it *)]
    ~deps:["%.mlpack"; "%.cmi"]
    (Ocaml_compiler.native_pack_mlpack "%.mlpack" "%.cmx");;

rule "ocaml: ml & cmi -> p.cmx & p.o"

  • ~tags:["ocaml"; "native"; "profile"]
    ~prods:["%.p.cmx"; x_p_o]
    ~deps:["%.ml"; "%.ml.depends"; "%.cmi"]
    (Ocaml_compiler.native_compile_ocaml_implem ~tag:"profile" ~cmx_ext:"p.cmx" "%.ml");;

rule "ocaml: ml & cmi -> cmx & o"

  • ~tags:["ocaml"; "native"]
    ~prods:["%.cmx"; x_o]
    ~deps:["%.ml"; "%.ml.depends"; "%.cmi"]
    (Ocaml_compiler.native_compile_ocaml_implem "%.ml");;

rule "ocaml: ml -> d.cmo & cmi"

  • ~tags:["ocaml"; "debug"]
    ~prods:["%.d.cmo"]
    ~deps:["%.ml"; "%.ml.depends"; "%.cmi"]
    (Ocaml_compiler.byte_compile_ocaml_implem ~tag:"debug" "%.ml" "%.d.cmo");;

rule "ocaml: ml -> cmo & cmi"

  • ~tags:["ocaml"]
    ~prods:["%.cmo"; "%.cmi"]
    ~deps:["%.ml"; "%.ml.depends"]
    (Ocaml_compiler.byte_compile_ocaml_implem "%.ml" "%.cmo");;

rule "ocaml: d.cmo* -> d.byte"

  • ~tags:["ocaml"; "byte"; "debug"; "program"]
    ~prod:"%.d.byte"
    ~dep:"%.d.cmo"
    (Ocaml_compiler.byte_debug_link "%.d.cmo" "%.d.byte");;

rule "ocaml: cmo* -> byte"

  • ~tags:["ocaml"; "byte"; "program"]
    ~prod:"%.byte"
    ~dep:"%.cmo"
    (Ocaml_compiler.byte_link "%.cmo" "%.byte");;

rule "ocaml: p.cmx* & p.o* -> p.native"

  • ~tags:["ocaml"; "native"; "profile"; "program"]
    ~prod:"%.p.native"
    ~deps:["%.p.cmx"; x_p_o]
    (Ocaml_compiler.native_profile_link "%.p.cmx" "%.p.native");;

rule "ocaml: cmx* & o* -> native"

  • ~tags:["ocaml"; "native"; "program"]
    ~prod:"%.native"
    ~deps:["%.cmx"; x_o]
    (Ocaml_compiler.native_link "%.cmx" "%.native");;

rule "ocaml: mllib & d.cmo* -> d.cma"

  • ~tags:["ocaml"; "byte"; "debug"; "library"]
    ~prod:"%.d.cma"
    ~dep:"%.mllib"
    (Ocaml_compiler.byte_debug_library_link_mllib "%.mllib" "%.d.cma");;

rule "ocaml: mllib & cmo* -> cma"

  • ~tags:["ocaml"; "byte"; "library"]
    ~prod:"%.cma"
    ~dep:"%.mllib"
    (Ocaml_compiler.byte_library_link_mllib "%.mllib" "%.cma");;

rule "ocaml: d.cmo* -> d.cma"

  • ~tags:["ocaml"; "byte"; "debug"; "library"]
    ~prod:"%.d.cma"
    ~dep:"%.d.cmo"
    (Ocaml_compiler.byte_debug_library_link "%.d.cmo" "%.d.cma");;

rule "ocaml: cmo* -> cma"

  • ~tags:["ocaml"; "byte"; "library"]
    ~prod:"%.cma"
    ~dep:"%.cmo"
    (Ocaml_compiler.byte_library_link "%.cmo" "%.cma");;
    @@ -206,67 +186,56 @@ rule "ocaml C stubs: clib & (o|obj)* -> (a|lib) & (so|dll)"
    (C_tools.link_C_library "%(path)lib%(libname).clib" ("%(path)lib%(libname)"-.-ext_lib) "%(path)%(libname)");;

rule "ocaml: mllib & p.cmx* & p.o* -> p.cmxa & p.a"

  • ~tags:["ocaml"; "native"; "profile"; "library"]
    ~prods:["%.p.cmxa"; x_p_a]
    ~dep:"%.mllib"
    (Ocaml_compiler.native_profile_library_link_mllib "%.mllib" "%.p.cmxa");;

rule "ocaml: mllib & cmx* & o* -> cmxa & a"

  • ~tags:["ocaml"; "native"; "library"]
    ~prods:["%.cmxa"; x_a]
    ~dep:"%.mllib"
    (Ocaml_compiler.native_library_link_mllib "%.mllib" "%.cmxa");;

rule "ocaml: p.cmx & p.o -> p.cmxa & p.a"

  • ~tags:["ocaml"; "native"; "profile"; "library"]
    ~prods:["%.p.cmxa"; x_p_a]
    ~deps:["%.p.cmx"; x_p_o]
    (Ocaml_compiler.native_profile_library_link "%.p.cmx" "%.p.cmxa");;

rule "ocaml: cmx & o -> cmxa & a"

  • ~tags:["ocaml"; "native"; "library"]
    ~prods:["%.cmxa"; x_a]
    ~deps:["%.cmx"; x_o]
    (Ocaml_compiler.native_library_link "%.cmx" "%.cmxa");;

rule "ocaml: mldylib & p.cmx* & p.o* -> p.cmxs & p.so"

  • ~tags:["ocaml"; "native"; "profile"; "shared"; "library"]
    ~prods:["%.p.cmxs"; x_p_dll]
    ~dep:"%.mldylib"
    (Ocaml_compiler.native_profile_shared_library_link_mldylib "%.mldylib" "%.p.cmxs");;

rule "ocaml: mldylib & cmx* & o* -> cmxs & so"

  • ~tags:["ocaml"; "native"; "shared"; "library"]
    ~prods:["%.cmxs"; x_dll]
    ~dep:"%.mldylib"
    (Ocaml_compiler.native_shared_library_link_mldylib "%.mldylib" "%.cmxs");;

rule "ocaml: p.cmx & p.o -> p.cmxs & p.so"

  • ~tags:["ocaml"; "native"; "profile"; "shared"; "library"]
    ~prods:["%.p.cmxs"; x_p_dll]
    ~deps:["%.p.cmx"; x_p_o]
    (Ocaml_compiler.native_shared_library_link ~tags:["profile"] "%.p.cmx" "%.p.cmxs");;

rule "ocaml: p.cmxa & p.a -> p.cmxs & p.so"

  • ~tags:["ocaml"; "native"; "profile"; "shared"; "library"]
    ~prods:["%.p.cmxs"; x_p_dll]
    ~deps:["%.p.cmxa"; x_p_a]
    (Ocaml_compiler.native_shared_library_link ~tags:["profile";"linkall"] "%.p.cmxa" "%.p.cmxs");;

rule "ocaml: cmx & o -> cmxs"

  • ~tags:["ocaml"; "native"; "shared"; "library"]
    ~prods:["%.cmxs"]
    ~deps:["%.cmx"; x_o]
    (Ocaml_compiler.native_shared_library_link "%.cmx" "%.cmxs");;

rule "ocaml: cmx & o -> cmxs & so"

  • ~tags:["ocaml"; "native"; "shared"; "library"]
    ~prods:["%.cmxs"; x_dll]
    ~deps:["%.cmx"; x_o]
    (Ocaml_compiler.native_shared_library_link "%.cmx" "%.cmxs");;

rule "ocaml: cmxa & a -> cmxs & so"

  • ~tags:["ocaml"; "native"; "shared"; "library"]
    ~prods:["%.cmxs"; x_dll]
    ~deps:["%.cmxa"; x_a]
    (Ocaml_compiler.native_shared_library_link ~tags:["linkall"] "%.cmxa" "%.cmxs");;
    @@ -282,19 +251,16 @@ rule "ocaml dependencies mli"
    (Ocaml_tools.ocamldep_command "%.mli" "%.mli.depends");;

rule "ocamllex"

  • ~tags:["ocaml"] (* FIXME "lexer" *)
    ~prod:"%.ml"
    ~dep:"%.mll"
    (Ocaml_tools.ocamllex "%.mll");;

rule "ocaml: mli -> odoc"

  • ~tags:["ocaml"; "doc"]
    ~prod:"%.odoc"
    ~deps:["%.mli"; "%.mli.depends"]
    (Ocaml_tools.document_ocaml_interf "%.mli" "%.odoc");;

rule "ocaml: ml -> odoc"

  • ~tags:["ocaml"; "doc"]
    ~prod:"%.odoc"
    ~deps:["%.ml"; "%.ml.depends"]
    (Ocaml_tools.document_ocaml_implem "%.ml" "%.odoc");;
    @@ -346,7 +312,6 @@ if !Options.use_menhir || Configuration.has_tag "use_menhir" then begin

end else
rule "ocamlyacc"

  • ~tags:["ocaml"] (* FIXME "parser" *)
    ~prods:["%.ml"; "%.mli"]
    ~dep:"%.mly"
    (Ocaml_tools.ocamlyacc "%.mly");;
    diff --git a/ocamlbuild/rule.ml b/ocamlbuild/rule.ml
    index d28833d..2c9c0e2 100644
    --- a/ocamlbuild/rule.ml
    +++ b/ocamlbuild/rule.ml
    @@ -29,7 +29,6 @@ type digest_command = { digest : string; command : Command.t }

type 'a gen_rule =
{ name : string;

  • tags : Tags.t;
    deps : Pathname.t list; (* These pathnames must be normalized )
    prods : 'a list; (
    Note that prods also contains stamp *)
    stamp : 'a option;
    @@ -52,8 +51,8 @@ let print_rule_name f r = pp_print_string f r.name
    let print_resource_list = List.print Resource.print

let print_rule_contents ppelt f r =

  • fprintf f "@[{@ @[<2>name =@ %S@];@ @[<2>tags =@ %a@];@ @[<2>deps =@ %a@];@ @[<2>prods = %a@];@ @[<2>code = @]@]@ }"
  • r.name Tags.print r.tags print_resource_list r.deps (List.print ppelt) r.prods
  • fprintf f "@[{@ @[<2>name =@ %S@];@ @[<2>deps =@ %a@];@ @[<2>prods = %a@];@ @[<2>code = @]@]@ }"
  • r.name print_resource_list r.deps (List.print ppelt) r.prods

let pretty_print ppelt f r =
fprintf f "@[rule@ %S@ ~deps:%a@ ~prods:%a@ @]"
@@ -67,11 +66,11 @@ let subst env rule =
let finder next_finder p = next_finder (Resource.subst_any env p) in
let stamp = match rule.stamp with None -> None | Some x -> Some (Resource.subst_pattern env x) in
let prods = subst_resource_patterns rule.prods in

  • { (rule) with name = sbprintf "%s (%a)" rule.name Resource.print_env env;
  •            prods = prods;
    
  •            deps = subst_resources rule.deps; (* The substition should preserve normalization of pathnames *)
    
  •            stamp = stamp;
    
  •            code = (fun env -> rule.code (finder env)) }
    
  • { name = sbprintf "%s (%a)" rule.name Resource.print_env env;
  • prods = prods;
  • deps = subst_resources rule.deps; (* The substition should preserve normalization of pathnames *)
  • stamp = stamp;
  • code = (fun env -> rule.code (finder env)) }

exception Can_produce of rule

@@ -84,8 +83,6 @@ let can_produce target rule =
end rule.prods; None
with Can_produce r -> Some r

-(* let tags_matches tags r = if Tags.does_match tags r.tags then Some r else None *)

let digest_prods r =
List.fold_right begin fun p acc ->
let f = Pathname.to_string (Resource.in_build_dir p) in
@@ -252,7 +249,7 @@ let (get_rules, add_rule, clear_rules) =
end,
(fun () -> rules := [])

-let rule name ?(tags=[]) ?(prods=[]) ?(deps=[]) ?prod ?dep ?stamp ?(insert = bottom) code = +let rule name ?(prods=[]) ?(deps=[]) ?prod ?dep ?stamp ?(insert = bottom) code =
let res_add import xs xopt =
let init =
match xopt with
@@ -281,7 +278,6 @@ let rule name ?(tags=[]) ?(prods=[]) ?(deps=[]) ?prod ?dep ?stamp ?(insert = `bo
in
add_rule insert
{ name = name;

  • tags = List.fold_right Tags.add tags Tags.empty;
    deps = res_add Resource.import (* should normalize *) deps dep;
    stamp = stamp;
    prods = prods;
    diff --git a/ocamlbuild/rule.mli b/ocamlbuild/rule.mli
    index 0acb125..02ce129 100644
    --- a/ocamlbuild/rule.mli
    +++ b/ocamlbuild/rule.mli
    @@ -35,7 +35,6 @@ val deps_of_rule : 'a gen_rule -> Pathname.t list
    val prods_of_rule : 'a gen_rule -> 'a list

val rule : string ->

  • ?tags:string list ->
    ?prods:string list ->
    ?deps:string list ->
    ?prod:string ->
    diff --git a/ocamlbuild/signatures.mli b/ocamlbuild/signatures.mli
    index bc21778..d7f80fe 100644
    --- a/ocamlbuild/signatures.mli
    +++ b/ocamlbuild/signatures.mli
    @@ -601,9 +601,8 @@ module type PLUGIN = sig
    automatically produced by ocamlbuild. This file can serve as a virtual
    target (or phony target), since it will be filled up by a digest of
    it dependencies.
  •  - The ~tags argument in deprecated, don't use it. *)
    
  • *)
    val rule : string ->
  • ?tags:string list ->
    ?prods:string list ->
    ?deps:string list ->
    ?prod:string ->
    --
    1.8.1.6

@vicuna
Copy link
Author

vicuna commented Jun 30, 2013

Comment author: @gasche

The feature and its test are now included in trunk and version/4.01.

I have two remaining worries (that may not require immediate action but maybe help people coming back at this PR in the future):

  • only statically-linked object files (.o) are supported, while -output-obj also supports producing object files for dynamic linking (.so); we may want to complete that feature
  • .o and .so are the unix prefixes for object files, as opposed to Windows prefixes (.obj and .dll) that are also supported by the compiler. I wonder if not also supporting .obj and .dll target may make life harder for windows user.

@vicuna
Copy link
Author

vicuna commented Jun 30, 2013

Comment author: @gasche

I just uploaded here the minor patch "output_obj_ext.diff" that parametrizes the target name over the right extension. In theory this should allow building "foo.byte.obj" over Windows, but I don't have access to a Windows machine to test it.

@vicuna
Copy link
Author

vicuna commented Jun 30, 2013

Comment author: @avsm

The output_obj_ext.diff looks correct to me, although I also don't have a WIndows machine to test it on.

@vicuna
Copy link
Author

vicuna commented Aug 6, 2013

Comment author: @gasche

I integrated the windows-extensions patch. I'm marking this bug as resolved>suspended, because we still lack support for .so/.dll files. Not having experience using those, I don't feel like implementing support that I don't know how to test. Please, dear future user, if you come over this bugtracker item with a need for .so/.dll -output-obj support, complain and bring us a reproducible use-case to test.

I also integrated a variant of Anil's ~tags-removing patch. Instead of removing completely the ~tags argument for the interface (which would provoke build failure on all myocamlbuild.ml using old code), I chose to emit a warning at runtime: "Warning: your ocamlbuild rule %S uses the ~tags parameter, which is deprecated and ignored."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants