rules_foreign_cc icon indicating copy to clipboard operation
rules_foreign_cc copied to clipboard

How to call `autoheader`?

Open bruno-digitbio opened this issue 1 year ago • 0 comments

I'm using configure_make to build SAMtools, a popular bioinformatics library.

The installation instructions request that the user run autoheader before autoconf.

I can obviously just check in the config.h.in file that autoheader generates, but this will introduce the requirement that I carefully ensure the (6+) environments I build in have identical libraries (and I am not a large enough operation to realistically vendor all of these upstream dependencies).

I tried playing some tricks like:

autogen = 1,
autogen_command = "autoheader",

but that produces a build_script.sh like:

NOCONFIGURE="1" "$BUILD_TMPDIR/autoheader"

which is not quite right.

I've patched this repo to get the behavior I want for now, but was wondering if there is a "better" way to do this?

❯ git diff HEAD~1 HEAD
diff --git a/foreign_cc/configure.bzl b/foreign_cc/configure.bzl
index 781f3ab..bc5c15b 100644
--- a/foreign_cc/configure.bzl
+++ b/foreign_cc/configure.bzl
@@ -111,6 +111,7 @@ def _create_configure_script(configureParameters):
         autogen = ctx.attr.autogen,
         autogen_command = ctx.attr.autogen_command,
         autogen_options = ctx.attr.autogen_options,
+        autoheader = ctx.attr.autoheader,
         make_commands = make_commands,
         make_path = attrs.make_path,
     )
@@ -159,6 +160,14 @@ def _attrs():
         "autogen_options": attr.string_list(
             doc = "Any options to be put in the 'autogen.sh' command line.",
         ),
+        "autoheader": attr.bool(
+            doc = (
+                "Set to True if we should run 'autoheader' before 'autoconf', " +
+                "currently requires `configure_in_place` to be True."
+            ),
+            mandatory = False,
+            default = False,
+        ),
         "autoreconf": attr.bool(
             doc = (
                 "Set to True if 'autoreconf' should be invoked before 'configure.', " +
diff --git a/foreign_cc/private/configure_script.bzl b/foreign_cc/private/configure_script.bzl
index dce885a..aa8836f 100644
--- a/foreign_cc/private/configure_script.bzl
+++ b/foreign_cc/private/configure_script.bzl
@@ -24,6 +24,7 @@ def create_configure_script(
         autogen,
         autogen_command,
         autogen_options,
+        autoheader,
         make_path,
         make_commands):
     ext_build_dirs = inputs.ext_build_dirs
@@ -40,6 +41,9 @@ def create_configure_script(
     script.append("##export_var## MAKE {}".format(make_path))
     script.append("##enable_tracing##")

+    if autoheader:
+        script.append("autoheader")
+
     if autogen:
         # NOCONFIGURE is pseudo standard and tells the script to not invoke configure.
         # We explicitly invoke configure later.

bruno-digitbio avatar Aug 12 '23 01:08 bruno-digitbio