Skip to content

Commit

Permalink
fix(turborepo): Check for TLS feature at build-time (#3585)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Feb 9, 2023
1 parent 66eb2e5 commit dfca4e0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: check
args: --workspace --all-targets --locked
args: --workspace --all-targets --locked --features rustls-tls

rust_lint:
needs: [determine_jobs, rust_prepare]
Expand Down Expand Up @@ -472,16 +472,16 @@ jobs:
- name: Run cargo check release
run: |
cargo check --workspace --all-targets --release
cargo check --workspace --all-targets --release --features rustls-tls
- name: Run cargo clippy
run: |
cargo clippy --workspace --all-targets
cargo clippy --workspace --all-targets --features rustls-tls
- name: Count clippy warnings
run: |
count="0"
clippy_output="$(cargo clippy --workspace --all-targets 2>&1)"
clippy_output="$(cargo clippy --workspace --all-targets --features rustls-tls 2>&1)"
# Clippy will be invoked and report on each crate individually. We need to sum manually.
for warnings in $(echo "$clippy_output" | sed -n 's/.*generated \([0-9]*\) warnings\?$/\1/p'); do
Expand Down Expand Up @@ -567,7 +567,7 @@ jobs:
timeout-minutes: 120
# We exclude turbo as it requires linking Go and all logic resides in turborepo-lib
run: |
cargo test -p turborepo-lib
cargo test -p turborepo-lib --features rustls-tls
turbopack_rust_test1:
needs: [determine_jobs, rust_prepare]
Expand Down Expand Up @@ -599,15 +599,13 @@ jobs:

- name: Build nextest
timeout-minutes: 120
# We exclude turbo as it requires linking Go and all logic resides in turborepo-lib
run: |
cargo nextest run --no-run --workspace --release --exclude turbo --exclude turborepo-ffi
cargo nextest run --no-run --workspace --release --exclude turbo --exclude turborepo-ffi --exclude turborepo-lib
- name: Run nextest
timeout-minutes: 120
# We exclude turbo as it requires linking Go and all logic resides in turborepo-lib
run: |
cargo nextest run --workspace --release --no-fail-fast --exclude turbo --exclude turborepo-ffi
cargo nextest run --workspace --release --no-fail-fast --exclude turbo --exclude turborepo-ffi --exclude turborepo-lib
turbopack_rust_test2:
needs: [determine_jobs, rust_prepare]
Expand Down Expand Up @@ -666,13 +664,13 @@ jobs:
timeout-minutes: 120
# We exclude turbo as it requires linking Go and all logic resides in turborepo-lib
run: |
cargo nextest run --no-run --workspace --release --exclude turbo --exclude turborepo-ffi
cargo nextest run --no-run --workspace --release --exclude turbo --exclude turborepo-ffi --exclude turborepo-lib
- name: Run nextest
timeout-minutes: 120
# We exclude turbo as it requires linking Go and all logic resides in turborepo-lib
run: |
cargo nextest run --workspace --release --no-fail-fast --exclude turbo --exclude turborepo-ffi
cargo nextest run --workspace --release --no-fail-fast --exclude turbo --exclude turborepo-ffi --exclude turborepo-lib
turbopack_rust_test_bench1:
needs: [determine_jobs, rust_prepare]
Expand Down
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ Building
- Building `turbo` CLI: In `cli` run `make turbo`
- Using `turbo` to build `turbo` CLI: `./turbow.js`

### TLS Implementation

Turborepo uses `reqwest`, a Rust HTTP client, to make requests to the Turbo API. `reqwest` supports two TLS implementations: `rustls` and `native-tls`. `rustls` is a pure Rust implementation of TLS, while `native-tls` is a wrapper around OpenSSL. Turborepo requires users to select
one of them by building with the `rustls-tls` or `native-tls` feature, respectively. To do so, pass either `--features rustls-tls` or `--features native-tls` to `cargo build` or `cargo test`. The Makefile already passes `rustls-tls` by default.

### Running Turborepo Tests

#### Go Tests
Expand All @@ -54,7 +59,7 @@ To run a single Go test, you can run `go test ./[path/to/package/]`. See more [i

#### Rust Tests

The recommended way to run tests is: `cargo nextest run -p turborepo-lib`.
The recommended way to run tests is: `cargo nextest run -p turborepo-lib --features rustls-tls`.
You'll have to [install it first](https://nexte.st/book/pre-built-binaries.html).

You can also use the built in [`cargo test`](https://doc.rust-lang.org/cargo/commands/cargo-test.html) directly `cargo test -p turborepo-lib`.
Expand Down
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ default-members = [
"crates/turbopack-swc-utils",
"crates/turbopack",
"crates/turbopack-tests",
"crates/turborepo-lib",
"crates/turbo-updater",
"xtask",
]

Expand Down
2 changes: 1 addition & 1 deletion cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SRC_FILES = $(shell find . -name "*.go" | grep -v "_test.go")
GENERATED_FILES = internal/turbodprotocol/turbod.pb.go internal/turbodprotocol/turbod_grpc.pb.go

turbo: go-turbo$(EXT)
cargo build --manifest-path ../crates/turborepo/Cargo.toml
cargo build --manifest-path ../crates/turborepo/Cargo.toml --features rustls-tls

go-turbo$(EXT): $(GENERATED_FILES) $(SRC_FILES) go.mod turborepo-ffi-install
CGO_ENABLED=1 go build $(GO_FLAGS) -tags $(GO_TAG) -o go-turbo$(EXT) ./cmd/turbo
Expand Down
10 changes: 10 additions & 0 deletions crates/turborepo-lib/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
fn check_tls_config() {}
#[cfg(not(any(feature = "native-tls", feature = "rustls-tls")))]
fn check_tls_config() {
panic!("You must enable one of the TLS features: native-tls or rustls-tls");
}

fn main() {
check_tls_config();
}

0 comments on commit dfca4e0

Please sign in to comment.