Skip to content

Commit

Permalink
Merge pull request #260 from malbarbo/static-musl
Browse files Browse the repository at this point in the history
static builder on travis
  • Loading branch information
pkgw authored Nov 21, 2018
2 parents ab23456 + 4fcb5a3 commit 9495808
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 18 deletions.
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ matrix:
- os: osx
osx_image: xcode8.3
rust: stable
# static build
- os: linux
sudo: required
dist: xenial
rust: nightly
env: IMAGE=x86_64-alpine-linux-musl
allow_failures:
- rust: nightly

Expand Down Expand Up @@ -80,8 +86,13 @@ before_script:
script:
- |
cargo build --verbose &&
cargo test
if [[ -z "$IMAGE" ]]; then
cargo build --verbose &&
cargo test
else
docker build -t ttci-$IMAGE dist/docker/$IMAGE/ &&
docker run -v $(pwd):/tectonic ttci-$IMAGE
fi
after_success: |
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ crate-type = ["rlib"]

[build-dependencies]
cc = "^1.0"
pkg-config = "^0.3"
pkg-config = "^0.3" # note: sync dist/docker/*/pkg-config-rs.sh with the version in Cargo.lock
regex = "^1.0"
sha2 = "^0.8"

Expand Down
42 changes: 42 additions & 0 deletions dist/docker/x86_64-alpine-linux-musl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2018 The Tectonic Project
# Licensed under the MIT License.

FROM alpine:edge

RUN apk update && \
apk add \
g++ \
git \
rust \
cargo \
fontconfig-dev \
freetype-static \
glib-static \
graphite2-dev \
graphite2-static \
harfbuzz-dev \
harfbuzz-static \
icu-dev \
icu-static \
openssl-dev \
zlib-dev

ADD pkg-config-rs.sh /
RUN /pkg-config-rs.sh

ENV PKG_CONFIG_ALL_STATIC=1
ENV OPENSSL_STATIC=1
ENV OPENSSL_DIR=/usr

# cc-rs does not support static linking stdc++,
# so we omit linking information on build.rs by setting CXXSTDLIB=''
# and specify static linking in RUSTFLAGS
ENV CXXSTDLIB=""
ENV RUSTFLAGS="-L /usr/lib -l static=stdc++ -C target-feature=+crt-static"

# Use a patched pkg-config-rs to allow static linking with system libraries.
# The --no-default-features flag removes serde-derive as a dep, which doesn't
# work when linking statically (rust-lang#40147).
CMD cd /tectonic && \
echo -e "[patch.crates-io]\npkg-config = { path = \"/pkg-config-rs\" }" >> Cargo.toml && \
cargo test --release --no-default-features
25 changes: 25 additions & 0 deletions dist/docker/x86_64-alpine-linux-musl/pkg-config-rs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
# Copyright 2018 The Tectonic Project
# Licensed under the MIT License.

set -ex

git clone --branch 0.3.14 https://github.com/alexcrichton/pkg-config-rs /pkg-config-rs

# make pkg-config-rs allows static linking with system libraries
cd /pkg-config-rs
patch -p1 <<'EOF'
diff --git a/src/lib.rs b/src/lib.rs
index 88dd310..ffcd7ae 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -547,7 +547,7 @@ fn is_static_available(name: &str, dirs: &[PathBuf]) -> bool {
};
dirs.iter().any(|dir| {
- !system_roots.iter().any(|sys| dir.starts_with(sys)) &&
+ // !system_roots.iter().any(|sys| dir.starts_with(sys)) &&
dir.join(&libname).exists()
})
}
EOF
8 changes: 4 additions & 4 deletions tectonic/dpx-dpxcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1228,10 +1228,10 @@ AES_ecb_encrypt (const unsigned char *key, size_t key_len,

/* NULL iv means here "use random IV". */
void
AES_cbc_encrypt (const unsigned char *key, size_t key_len,
const unsigned char *iv, int padding,
const unsigned char *plain, size_t plain_len,
unsigned char **cipher, size_t *cipher_len)
AES_cbc_encrypt_tectonic (const unsigned char *key, size_t key_len,
const unsigned char *iv, int padding,
const unsigned char *plain, size_t plain_len,
unsigned char **cipher, size_t *cipher_len)
{
AES_CONTEXT *ctx, aes;
const unsigned char *inptr;
Expand Down
8 changes: 4 additions & 4 deletions tectonic/dpx-dpxcrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ void AES_ecb_encrypt (const unsigned char *key, size_t key_len,
const unsigned char *plain, size_t plain_len,
unsigned char **cipher, size_t *cipher_len);

void AES_cbc_encrypt (const unsigned char *key, size_t key_len,
const unsigned char *iv, int padding,
const unsigned char *plain, size_t plain_len,
unsigned char **cipher, size_t *cipher_len);
void AES_cbc_encrypt_tectonic (const unsigned char *key, size_t key_len,
const unsigned char *iv, int padding,
const unsigned char *plain, size_t plain_len,
unsigned char **cipher, size_t *cipher_len);

#endif /* _DPXCRYPT_H_ */
14 changes: 7 additions & 7 deletions tectonic/dpx-pdfencrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ compute_hash_V5 (unsigned char *hash,
Kr = NEW(K1_len * 64, unsigned char);
for (i = 0; i < 64; i++)
memcpy(Kr + i * K1_len, K1, K1_len);
AES_cbc_encrypt(K, 16, K + 16, 0, Kr, K1_len * 64, &E, &E_len);
AES_cbc_encrypt_tectonic(K, 16, K + 16, 0, Kr, K1_len * 64, &E, &E_len);
free(Kr);

for (i = 0; i < 16; i++)
Expand Down Expand Up @@ -392,7 +392,7 @@ compute_owner_password_V5 (struct pdf_sec *p, const char *oplain)

compute_hash_V5(hash, oplain, ksalt, p->U, p->R);
memset(iv, 0, AES_BLOCKSIZE);
AES_cbc_encrypt(hash, 32, iv, 0, p->key, p->key_size, &OE, &OE_len);
AES_cbc_encrypt_tectonic(hash, 32, iv, 0, p->key, p->key_size, &OE, &OE_len);
memcpy(p->OE, OE, 32);
free(OE);
}
Expand All @@ -417,7 +417,7 @@ compute_user_password_V5 (struct pdf_sec *p, const char *uplain)

compute_hash_V5(hash, uplain, ksalt, NULL, p->R);
memset(iv, 0, AES_BLOCKSIZE);
AES_cbc_encrypt(hash, 32, iv, 0, p->key, p->key_size, &UE, &UE_len);
AES_cbc_encrypt_tectonic(hash, 32, iv, 0, p->key, p->key_size, &UE, &UE_len);
memcpy(p->UE, UE, 32);
free(UE);
}
Expand Down Expand Up @@ -634,12 +634,12 @@ pdf_encrypt_data (const unsigned char *plain, size_t plain_len,
break;
case 4:
calculate_key(p, key);
AES_cbc_encrypt(key, MIN(16, p->key_size + 5), NULL, 1,
plain, plain_len, cipher, cipher_len);
AES_cbc_encrypt_tectonic(key, MIN(16, p->key_size + 5), NULL, 1,
plain, plain_len, cipher, cipher_len);
break;
case 5:
AES_cbc_encrypt(p->key, p->key_size, NULL, 1,
plain, plain_len, cipher, cipher_len);
AES_cbc_encrypt_tectonic(p->key, p->key_size, NULL, 1,
plain, plain_len, cipher, cipher_len);
break;
default:
_tt_abort("pdfencrypt: Unexpected V value: %d", p->V);
Expand Down

0 comments on commit 9495808

Please sign in to comment.