Building Habitat on FreeBSD


#1

Hello,

I’m looking to build Habitat on FreeBSD, largely because I want to see if I can, but if I can I think there’s definitely a use case here… I realize that it’s not a “supported” OS, but it’s just rust… I don’t see a reason why it shouldn’t build… (running may be an entirely different story, but we’ll cross that bridge…)

Anyway, I built a fresh FreeBSD 11.2 for this process.

Here’s my process so far:

# install curl so we can download the installer
pkg install curl

# install rust/cargo/et al
curl https://sh.rustup.rs -sSf | sh

# You have to manually update your .cshrc to include $HOME/.cargo/bin, your path should look like (uncommented):
# set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin $HOME/.cargo/bin)

# clone 0.68.0 since I know that works in linux
git clone -b '0.68.0' --single-branch --depth 1 https://github.com/habitat-sh/habitat.git
cd habitat

# install prereqs
pkg install pkgconf libarchive libsodium protobuf gmake

# Run gmake because that's gnu make which we use in linux
gmake

This all goes swimmingly until:

# gmake
sh -c 'cd components/hab && cargo build '
   Compiling habitat_http_client v0.0.0 (https://github.com/habitat-sh/core.git#63f04305)
   Compiling habitat-sup-protocol v0.0.0 (/root/habitat/components/sup-protocol)
error: /root/habitat/target/debug/build/habitat_http_client-0b153eeb838571ed/out/cacert.pem wasn't a utf-8 file
  --> /root/.cargo/git/checkouts/core-4cdefcf00786d1eb/63f0430/components/http-client/src/lib.rs:54:38
   |
54 |     const CACERT_PEM: &'static str = include_str!(concat!(env!("OUT_DIR"), "/cacert.pem"));
   |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: Could not compile `habitat_http_client`.
warning: build failed, waiting for other jobs to finish...
error: build failed
gmake: *** [Makefile:178: build-hab] Error 101

And in fact, it is NOT a UTF-8 file:

# file /root/habitat/target/debug/build/habitat_http_client-0b153eeb838571ed/out/cacert.pem
/root/habitat/target/debug/build/habitat_http_client-0b153eeb838571ed/out/cacert.pem: ISO-8859 text

And this appears to be because of an invalid character sequence:

# iconv -t UTF-8 /root/habitat/target/debug/build/habitat_http_client-0b153eeb838571ed/out/cacert.pem
... snip ...
                Policy: X509v3 Any Policy
                  CPS: http://www.certicamara.com/dpc/
                  User Notice:
iconv: iconv(): Illegal byte sequence
                    Explicit Text: Limitaciones de garantroot@freebsd-11-2:~/habitat #

(copied as-is, I’m guessing the error is at Limitaciones and some accent that the word uses?)

So, I’m stumped… any thoughts, comments, guesses, or ideas?

Thanks!


#2

It looks like you’re running into the fallout from https://github.com/habitat-sh/core/blob/master/components/http-client/build.rs#L12

It looks like the path CA bundle used is just pulled from your SSL_CERT_FILE env var during the build process. My guess is that the CA bundle on your system is wonky. You could probably copy it, edit out the problematic part(s), and set the env var before attempting to build.


#3

Hmm… Interesting, as part of installing curl, it seems to have installed openssl, and in fact:

# file /usr/local/openssl/cert.pem /usr/local/share/certs/ca-root-nss.crt /usr/local/etc/ssl/cert.pem
/usr/local/openssl/cert.pem:            ISO-8859 text
/usr/local/share/certs/ca-root-nss.crt: ISO-8859 text
/usr/local/etc/ssl/cert.pem:            ISO-8859 text

So I copied a tls-ca-bundle.pem file from a CentOS machine. And it is a UTF-8 file:

root@freebsd-11-2:~ # file tls-ca-bundle.pem
tls-ca-bundle.pem: UTF-8 Unicode text

However, a:

set SSL_CERT_FILE="/root/tls-ca-bundle.pem"

Didn’t seem to help… so I just replaced the file in place… But now I’m getting a new error.

So the current process is this:

# install curl so we can download the installer
pkg install curl

# install rust/cargo/et al
curl https://sh.rustup.rs -sSf | sh

# You have to manually update your .cshrc to include $HOME/.cargo/bin, your path should look like (uncommented):
# set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin $HOME/.cargo/bin)

# clone 0.68.0 since I know that works in linux
git clone -b '0.68.0' --single-branch --depth 1 https://github.com/habitat-sh/habitat.git
cd habitat

# install prereqs
pkg install pkgconf libarchive libsodium protobuf gmake

# Run gmake because that's gnu make which we use in linux
gmake # Gmake will fail here

# copy our known good ssl cert file in place
cp ~/tls-ca-bundle.pem /root/habitat/target/debug/build/habitat_http_client-0b153eeb838571ed/out/cacert.pem

# run gmake again
gmake

however, this fails with a “can’t find function”, which… I know 0.68.0 works… so how can this be?

# gmake
sh -c 'cd components/hab && cargo build '
   Compiling habitat_http_client v0.0.0 (https://github.com/habitat-sh/core.git#63f04305)
   Compiling habitat-sup-protocol v0.0.0 (/root/habitat/components/sup-protocol)
   Compiling habitat_api_client v0.0.0 (/root/habitat/components/builder-api-client)
   Compiling habitat_common v0.0.0 (/root/habitat/components/common)
   Compiling habitat-sup-client v0.0.0 (/root/habitat/components/sup-client)
   Compiling hab v0.0.0 (/root/habitat/components/hab)
error[E0425]: cannot find function `sub_svc_load` in this scope
   --> components/hab/src/cli.rs:613:26
    |
613 |             (subcommand: sub_svc_load().aliases(&["l", "lo", "loa"]))
    |                          ^^^^^^^^^^^^ did you mean `sub_svc_start`?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
error: Could not compile `hab`.

To learn more, run the command again with --verbose.
gmake: *** [Makefile:178: build-hab] Error 101

#4

What version of rust are you building with?


#5
root@freebsd-11-2:~ # rustc --version
rustc 1.30.1 (1433507eb 2018-11-07)

I think that’s whatever was “stable” when I ran the curl https://sh.rustup.rs -sSf | sh command.

Is there a specific version of Rust I should be compiling against?

This is the same version I used to compile without issue on CentOS 7:

rustc 1.30.1 (1433507eb 2018-11-07)

#6

@eeyun any thoughts?

Thanks!