Skip to content

Commit

Permalink
Add Habitat plan.sh for x86_64-linux-musl
Browse files Browse the repository at this point in the history
To build the package you have to have habitat install and then run:
```
$ hab pkg build . -k chef
```

You will get a `.hart` package inside `results/` that you can install on
any Linux x86_64.

Spun up a Redhat 6.5 and install it:
```
[root@localhost ~]# hab install /chef-delivery-cli-0.0.1-20170126223932-x86_64-linux.hart
✓ Installed core/cacerts/2016.09.14/20161031044952
✓ Installed core/musl/1.1.14/20161214032430
✓ Installed core/openssl-musl/1.0.2j/20161214065445
✓ Installed core/zlib-musl/1.2.8/20161214065420
✓ Installed chef/delivery-cli/0.0.1/20170126223932
★ Install of chef/delivery-cli/0.0.1/20170126223932 complete with 5 new packages installed.
[root@localhost ~]# /hab/pkgs/chef/delivery-cli/0.0.1/20170126223932/bin/delivery --version
delivery 0.0.0 (0000)
```

Next steps could be to make the installer install the package in the
right location. Maybe even make one for OSX. 😄

Signed-off-by: Salim Afiune <afiune@chef.io>
  • Loading branch information
Salim Afiune committed Jan 27, 2017
1 parent 0b746ca commit 4f6c0ee
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ tmp/
/omnibus/Berksfile.lock
/omnibus/Gemfile.lock
cookbooks/delivery_rust/Berksfile.lock

# Habitat
results/
80 changes: 80 additions & 0 deletions plan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
pkg_name=delivery-cli
pkg_origin=chef
pkg_version=0.0.1
pkg_maintainer="Salim Afiune <afiune@chef.io>"
pkg_license=('Apache-2.0')
pkg_source=nosuchfile.tar.gz
# (Salim) TODO: We want the result to be a portable, static binary
# in a zero-dependency package. At the moment I cound't make it to
# compile because we need to figure out how to tell zlib that we are
# building in static mode, so for now we are packaging the dependencies.
pkg_deps=(
core/gcc
core/zlib-musl
core/openssl-musl
)
pkg_build_deps=(
core/musl
core/zlib-musl
core/openssl-musl
core/coreutils
core/rust core/gcc
)
pkg_bin_dirs=(bin)

# Name of the resulting binary
_bin="delivery"

do_prepare() {
# Can be either `--release` or `--debug` to determine cargo build strategy
build_type="--release"
build_line "Building artifacts with \`${build_type#--}' mode"

# Used by Cargo to use a pristine, isolated directory for all compilation
export CARGO_TARGET_DIR="$HAB_CACHE_SRC_PATH/$pkg_dirname"
build_line "Setting CARGO_TARGET_DIR=$CARGO_TARGET_DIR"

export rustc_target="x86_64-unknown-linux-musl"
build_line "Setting rustc_target=$rustc_target"

export OPENSSL_LIB_DIR=$(pkg_path_for openssl-musl)/lib
export OPENSSL_INCLUDE_DIR=$(pkg_path_for openssl-musl)/include
export OPENSSL_STATIC=true

rustflags="-L$(pkg_path_for zlib-musl)/lib -lz"
rustflags="$rustflags -L$(pkg_path_for openssl-musl)/lib -lssl -lcrypto"
export RUSTFLAGS="$rustflags"

export LD_LIBRARY_PATH=$(pkg_path_for gcc)/lib
build_line "Setting LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
}

do_build() {
pushd "$PLAN_CONTEXT" > /dev/null
cargo build ${build_type#--debug} --target=$rustc_target --verbose
popd > /dev/null
}

do_install() {
install -v -D $CARGO_TARGET_DIR/$rustc_target/${build_type#--}/$_bin \
$pkg_prefix/bin/$_bin
}

do_strip() {
if [[ "$build_type" != "--debug" ]]; then
do_default_strip
fi
}

# Turn the remaining default phases into no-ops
do_download() {
return 0
}

do_verify() {
return 0
}

do_unpack() {
return 0
}

0 comments on commit 4f6c0ee

Please sign in to comment.