Skip to content

Commit

Permalink
Update hyper to v0.12. (#350)
Browse files Browse the repository at this point in the history
The main differences are:

- hyper requires service futures to be `Send`, which rippled through most types
  in the codebase. This is because it uses the new tokio thread-pool runtime
  under the hood instead of the old tokio-core single-threaded executor.

- Replace our use of tokio-core with tokio, and update other tokio-related
  crates, for the same reason. Tests continue to use the single-threaded
  runtime. Some deps like tokio_tcp are re-exported from the tokio crate,
  so they've been removed.

- The implicit tokio runtime means that the code no longer needs to pass
  `tokio_core::Handle` around, so `Handle` parameters have been removed from
  various structs and constructors.

- hyper's `Connect` and `Service` traits now have a different meaning.

  - `Connect` is only meant to be used with things that provide a transport,
    and not for clients in general.

  - `Service` is only meant for server-type services, must be Send, and takes
    `&mut self` since new Service values are generated by the NewService impl
    for each client connection.

  The code relied on a default `Connect` impl for all `Service` impls that
  took a `Uri` as input, and used these `Service` impls for HTTP clients.
  The equivalent of this for most cases is now provided through our own new
  `ClientImpl` trait.

- hyper no longer provides HTTP header types. Use the typed-headers crate
  for these. However `typed-headers::Authorization` is not as flexible
  as hyper 0.11's type was (does not allow arbitrary values like our
  SAS tokens), so this has been reverted to use raw headers.

- HSM operations used to be done without any synchronization, relying on the
  underlying runtime being a single specific thread (the tokio_core runtime).
  They now use a `Mutex`, allowing HSM impls to assume that only one thread
  accesses them at a time, but it is not necessarily the *same* thread.
  In other words, HSM impls do not need to be `Sync`, but they *must*
  be `Send`.


Other changes:

- Temporarily disable parallel codegen for VSTS builds. ld crashes in the
  Linux amd64 Test job with a non-descript error. Disabling parallel codegen
  appears to help, probably because it reduces the number of objects the linker
  needs to link.

- Fix `DockerModuleRuntime::list()` to log errors if the API call fails.

- Replace the clippy docker image with a pinned nightly. The docker image
  was broken when running as non-root anyway.

- Deny unused extern crates warning, and remove unused deps. Some other
  dev-deps were target-specific and have been marked as such in Cargo.toml
  • Loading branch information
arsing authored Oct 4, 2018
1 parent b9dac4a commit 10d1d79
Show file tree
Hide file tree
Showing 143 changed files with 4,401 additions and 4,401 deletions.
880 changes: 391 additions & 489 deletions THIRDPARTYNOTICES

Large diffs are not rendered by default.

832 changes: 408 additions & 424 deletions edgelet/Cargo.lock

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions edgelet/build/linux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ process_args()

process_args "$@"

# ld crashes in the VSTS CI's Linux amd64 job while trying to link iotedged
# with a generic exit code 1 and no indicative error message. It seems to
# work fine if we reduce the number of objects given to the linker,
# by disabling parallel codegen and incremental compile.
#
# We don't want to disable these for everyone else, so only do it in this script
# that the CI uses.
>> "$PROJECT_ROOT/Cargo.toml" cat <<-EOF
[profile.dev]
codegen-units = 1
incremental = false
[profile.test]
codegen-units = 1
incremental = false
EOF

if [[ -z ${RELEASE} ]]; then
cd "$PROJECT_ROOT" && $CARGO "+$TOOLCHAIN" build --all
else
Expand Down
22 changes: 5 additions & 17 deletions edgelet/build/linux/clippy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ DIR=$(cd "$(dirname "$0")" && pwd)
BUILD_REPOSITORY_LOCALPATH=${BUILD_REPOSITORY_LOCALPATH:-$DIR/../../..}
PROJECT_ROOT=${BUILD_REPOSITORY_LOCALPATH}/edgelet
SCRIPT_NAME=$(basename "$0")
IMAGE="azureiotedge/cargo-clippy:nightly"
USE_DOCKER=1
TOOLCHAIN='nightly-2018-09-12'
RUSTUP="$HOME/.cargo/bin/rustup"
CARGO="$HOME/.cargo/bin/cargo"

Expand All @@ -30,8 +29,6 @@ function usage()
echo ""
echo "options"
echo " -h, --help Print this help and exit."
echo " -i, --image Docker image to run (default: $IMAGE)"
echo " -d, --use-docker Run clippy using a docker image (default: Do not run in a docker image)"
exit 1;
}

Expand All @@ -44,14 +41,9 @@ function print_help_and_exit()
function run_clippy()
{
echo "Running clippy..."
(cd $PROJECT_ROOT && $CARGO +nightly clippy --all)
(cd $PROJECT_ROOT && $CARGO "+$TOOLCHAIN" clippy --all)
}

function run_clippy_via_docker()
{
echo "Running clippy docker image..."
docker run --user "$(id -u)":"$(id -g)" --rm -v "$PROJECT_ROOT:/volume" "$IMAGE"
}
###############################################################################
# Obtain and validate the options supported by this script
###############################################################################
Expand All @@ -61,14 +53,10 @@ function process_args()
for arg in "$@"
do
if [ $save_next_arg -eq 1 ]; then
IMAGE="$arg"
USE_DOCKER=1
save_next_arg=0
else
case "$arg" in
"-h" | "--help" ) usage;;
"-i" | "--image" ) save_next_arg=1;;
"-d" | "--use-docker" ) USE_DOCKER=1;;
* ) usage;;
esac
fi
Expand All @@ -80,9 +68,9 @@ process_args "$@"
if [[ $USE_DOCKER -eq 1 ]]; then
run_clippy_via_docker
else
echo "Installing nightly toolchain"
$RUSTUP install nightly
echo "Installing $TOOLCHAIN toolchain"
$RUSTUP install "$TOOLCHAIN"
echo "Installing clippy..."
$RUSTUP component add clippy-preview --toolchain=nightly
$RUSTUP component add clippy-preview "--toolchain=$TOOLCHAIN"
run_clippy
fi
22 changes: 22 additions & 0 deletions edgelet/doc/devguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ sudo apt-get update
sudo apt-get install -y git cmake build-essential curl libcurl4-openssl-dev libssl-dev uuid-dev pkg-config
```

#### Windows

1. Install `vcpkg`

```powershell
git clone https://github.com/Microsoft/vcpkg
cd vcpkg
.\bootstrap-vcpkg.bat
```

1. Install openssl binaries

```powershell
vcpkg install openssl:x64-windows
```

1. Set `OPENSSL_ROOT_DIR`

```powershell
$env:OPENSSL_ROOT_DIR = "$PWD\installed\x64-windows"
```

### Cargo
Cargo is the build tool for rust. You will use cargo frequently. It manages the build of the project, downloading dependencies,
testing, etc. You can read more about cargo and it's capabilities in the [cargo book](https://doc.rust-lang.org/cargo/).
Expand Down
6 changes: 2 additions & 4 deletions edgelet/docker-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ publish = false
base64 = "0.9"
failure = "0.1"
futures = "0.1"
hyper = "0.11"
hyper = "0.12"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
serde_yaml = "0.7"
typed-headers = "0.1"
url = "1.5"

[dev-dependencies]
tokio-core = "*"
22 changes: 11 additions & 11 deletions edgelet/docker-rs/src/apis/client.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// Copyright (c) Microsoft. All rights reserved.

use std::rc::Rc;
use std::sync::Arc;

use super::configuration::Configuration;
use hyper;

pub struct APIClient<C: hyper::client::Connect> {
configuration: Rc<Configuration<C>>,
pub struct APIClient<C: hyper::client::connect::Connect> {
configuration: Arc<Configuration<C>>,
container_api: Box<::apis::ContainerApi>,
image_api: Box<::apis::ImageApi>,
network_api: Box<::apis::NetworkApi>,
system_api: Box<::apis::SystemApi>,
volume_api: Box<::apis::VolumeApi>,
}

impl<C: hyper::client::Connect> APIClient<C> {
impl<C: hyper::client::connect::Connect + 'static> APIClient<C> {
pub fn new(configuration: Configuration<C>) -> APIClient<C> {
let rc = Rc::new(configuration);
let configuration = Arc::new(configuration);

APIClient {
configuration: rc.clone(),
container_api: Box::new(::apis::ContainerApiClient::new(rc.clone())),
image_api: Box::new(::apis::ImageApiClient::new(rc.clone())),
network_api: Box::new(::apis::NetworkApiClient::new(rc.clone())),
system_api: Box::new(::apis::SystemApiClient::new(rc.clone())),
volume_api: Box::new(::apis::VolumeApiClient::new(rc.clone())),
configuration: configuration.clone(),
container_api: Box::new(::apis::ContainerApiClient::new(configuration.clone())),
image_api: Box::new(::apis::ImageApiClient::new(configuration.clone())),
network_api: Box::new(::apis::NetworkApiClient::new(configuration.clone())),
system_api: Box::new(::apis::SystemApiClient::new(configuration.clone())),
volume_api: Box::new(::apis::VolumeApiClient::new(configuration.clone())),
}
}

Expand Down
4 changes: 2 additions & 2 deletions edgelet/docker-rs/src/apis/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

use failure::err_msg;
use failure::Error;
use hyper::client::Connect;
use hyper::client::connect::Connect;
use hyper::{Client, Uri};

pub struct Configuration<C: Connect> {
pub base_path: String,
pub user_agent: Option<String>,
pub client: Client<C>,
pub uri_composer: Box<Fn(&str, &str) -> Result<Uri, Error>>,
pub uri_composer: Box<Fn(&str, &str) -> Result<Uri, Error> + Send + Sync>,
}

impl<C: Connect> Configuration<C> {
Expand Down
Loading

0 comments on commit 10d1d79

Please sign in to comment.