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
Comments
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. |
Comment author: @avsm Test case added and verified to work with the patch. From bb3a2c8 Mon Sep 17 00:00:00 2001 ocamlbuild/testsuite/level0.ml | 5 +++++ diff --git a/ocamlbuild/testsuite/level0.ml b/ocamlbuild/testsuite/level0.ml +test "OutputObj"
run ~root:"_test";;1.8.1.6 |
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 From 168dabc Mon Sep 17 00:00:00 2001 It's very confusing leaving this here, because it's set in the
|
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):
|
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. |
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. |
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." |
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
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
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"
+rule "ocaml: 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"
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
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
The text was updated successfully, but these errors were encountered: