Skip to content

Commit

Permalink
Document the need to export main. Closes #23.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundominguez committed Jul 18, 2018
1 parent f960b82 commit 28b87bf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
$NIXRUN "bazel run clotestbin"
$NIXRUN "bazel run clotestbin-cc"
$NIXRUN "bazel run clotestbin-cc-norunfiles"
$NIXRUN "bazel run clotestbin-cc-pie"
workflows:
version: 2
Expand Down
14 changes: 14 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ binary_closure(
src = "libhello-cc-norunfiles.so",
)

cc_binary(
name = "hello-cc-pie",
srcs = ["src/test/cc/hello/main.c"],
linkopts = ["-pie", "-Wl,--dynamic-list", "main-symbol-list.ld"],
deps = ["main-symbol-list.ld"],
testonly = True,
)

binary_closure(
name = "clotestbin-cc-pie",
testonly = True,
src = "hello-cc-pie",
)

sh_binary(
name = "deps",
srcs = ["src/main/bash/deps.sh"],
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ of the result as a poor man's container image. Compared to containers:

Clodl can be used to build binary closures or library closures.

A binary closure is made from an executable and can be executed.
In practice, the binary closure is a zip file appended to a script
that uncompresses the file to a temporary folder and has the
executable invoked.
A binary closure is made from an executable or a shared library
defining symbol `main` and can be executed. In practice, the binary
closure is a zip file appended to a script that uncompresses the file
to a temporary folder and has `main` invoked.

A library closure is a zip file containing the shared libraries in
the closure, and provides a top-level library which depends on all of
Expand Down Expand Up @@ -58,9 +58,9 @@ haskell_binary(
name = "hello-hs",
srcs = ["src/test/haskell/hello/Main.hs"],
compiler_flags = [
"-threaded",
"-dynamic",
"-pie",
"-rdynamic", # or "-Wl,--dynamic-list", "main-symbol-list.ld"
],
...
)
Expand All @@ -71,7 +71,7 @@ binary_closure(
)
```

The [BUILD file](BUILD) has a complete example.
The [BUILD file](BUILD) has complete examples.

[bazel]: https://bazel.build
[bazel-rules]: https://docs.bazel.build/versions/master/skylark/rules.html
Expand Down
18 changes: 13 additions & 5 deletions clodl/clodl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -430,25 +430,33 @@ def library_closure(name, srcs, outzip = "", excludes = [], executable = False,
def binary_closure(name, src, excludes = [], **kwargs):
"""
Produces a zip file containing a closure of all the shared libraries needed
to load the given executable. The zipfile is prepended with a script that
uncompresses the zip file and executes the binary.
to load the given position independent executable or shared library defining
symbol main. The zipfile is prepended with a script that uncompresses the
zip file and executes main.
Args:
name: A unique name for this rule
src: The executable binary
src: The position independent executable or a shared library.
excludes: Same purpose as in library_closure
Example:
```bzl
cc_binary(
name = "hello-cc",
srcs = ["src/test/cc/hello/main.c"],
linkopts = ["-pie", "-Wl,--dynamic-list", "main-symbol-list.ld"],
deps = ["main-symbol-list.ld"],
)
binary_closure(
name = "closure"
src = ":exe"
src = "hello-cc"
excludes = ["libexclude_this\.so", "libthis_too\.so"]
...
)
```
The zip file closure is created, with all the
shared libraries required by ":exe" except those in excludes.
shared libraries required by "hello-cc" except those in excludes.
"""
zip_name = "%s-closure" % name
library_closure(
Expand Down
3 changes: 3 additions & 0 deletions main-symbol-list.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
main;
};

0 comments on commit 28b87bf

Please sign in to comment.