 +    config = ctx.attr.sigstruct[SGXSigstructInfo].config
 +    unsigned = ctx.attr.sigstruct[SGXSigstructInfo].unsigned
 +    unsigned_file = unsigned.files.to_list()[0]
-+    ctx.actions.run(
++    ctx.actions.run_shell(
 +        inputs = [
 +            config,
 +            ctx.file.public_key,

+    sigstruct = ctx.outputs.sigstruct
+    if not sigstruct:
+        sigstruct = ctx.actions.declare_file(ctx.label.name + ".dat")
+    ctx.actions.run(
+        inputs = [
+            ctx.file.unsigned,
+            ctx.file.config,
+        ],
+        executable = ctx.executable._sign_tool,
+        outputs = [sigstruct],
+        progress_message = "Generating SIGSTRUCT material for: //{pkg}:{name}".format(
+            pkg = ctx.attr.unsigned.label.package,
+            name = ctx.attr.unsigned.label.name,
+        ),
+        arguments = [
+            "gendata",
+            "-enclave",

+
+def _sgx_debug_enclave_impl(ctx):
+    """Implementation of an automated signing process of an unsigned enclave."""
+    ctx.actions.run_shell(
+        inputs = [
+            ctx.file.unsigned,
+            ctx.file._key,
+            ctx.file.config,
+        ],
+        tools = [ctx.executable._sign_tool],
+        outputs = [ctx.outputs.executable],
+        progress_message = "Signing for debug: //{pkg}:{name}".format(
+            pkg = ctx.attr.unsigned.label.package,
+            name = ctx.attr.unsigned.label.name,
+        ),
+        # Suppresses tool output on success.
+        command = "output=`%s $@ 2>&1` || echo $output" %
+                  ctx.executable._sign_tool.path,
+        arguments = [
+            "sign",
+            "-enclave",
