SlideShare a Scribd company logo
1 of 26
Download to read offline
@antweiss@antweiss
A Deeper Look at
Cargo
Ant Weiss, Otomato
http://otomato.link
@antweiss@antweiss
Cargo is the Package Manager for Rust
● Basic Scaffolding
● Dependency Mgmt
● Compilation
● Packaging
● Publishing
● Toolchain Expansion
@antweiss@antweiss
The First Step
cargo new --bin my-rust-app
cargo new --lib my-rust-lib
cargo new my-rust-app --vcs git
@antweiss@antweiss
The toml and the lock
Cargo.toml: (AKA The Manifest)
[package]
name = "some-app"
version = "0.1.0"
authors = ["Anton Weiss <anton@otomato.link>"]
[dependencies]
tiny_http = "0.6.0"
redis = "0.9.0"
@antweiss@antweiss
Cargo.lock
Simple rule:
Binary: check Cargo.lock into source control
Library: put Cargo.lock in .gitignore
Don’t use “*” dependencies.
Crates.io will reject your crate!
@antweiss@antweiss
Depends On...
● Crates from crates.io
[dependencies]
chashmap = "2.2.0"
● Git repos
[dependencies]
evmap = ( git = https://github.com/jonhoo/rust-evmap.git }
● Files in subdirectories of your project
[dependencies]
hello_utils = { path = "hello_utils" }
@antweiss@antweiss
Versions of Truth
Cargo.toml:
[dependencies]
clap = "2.20.0"
>cargo build
Updating crates.io index
...
Compiling clap v2.32.0
To ensure specific version -
use:
mylib = "=0.2.3"
Maximal Version
Resolution = At the time
the lockfile is generated
- the latest available
version is used.
@antweiss@antweiss
Versions of Truth : Caret
An update is allowed if the new version number does not
modify the left-most non-zero digit in the major, minor,
patch grouping:
[dependencies]
time = "^0.20.0"
Examples:
^1.2.3 := >=1.2.3 <2.0.0
^1.2 := >=1.2.0 <2.0.0
^1 := >=1.0.0 <2.0.0
^0.2.3 := >=0.2.3 <0.3.0
^0.2 := >= 0.2.0 < 0.3.0
^0.0.3 := >=0.0.3 <0.0.4
^0.0 := >=0.0.0 <0.1.0
^0 := >=0.0.0 <1.0.0
@antweiss@antweiss
Versions of Truth : Tilde
Specify a minimal version with some ability to update:
[dependencies]
clap = "~2.3.0"
Examples:
~1.2.3 := >=1.2.3 <1.3.0
~1.2 := >=1.2.0 <1.3.0
~1 := >=1.0.0 <2.0.0
@antweiss@antweiss
Versions of Truth : Wildcard and Inequality
Wildcard - allow for any version where the wildcard is.
Examples:
* := >=0.0.0
1.* := >=1.0.0 <2.0.0
1.2.* := >=1.2.0 <1.3.0
In/equality - allow manually specifying a version range or
an exact version.
Examples:
>= 1.2.0
> 1
< 2
= 1.2.3
@antweiss@antweiss
Updating dependencies:
> cargo update
Or
> cargo update -p mycrate
To update a specific crate.
@antweiss@antweiss
Versions of Truth : Git
[dependencies]
rand = { git = "https://github.com/rust-lang-nursery/rand" }
= Use the latest commit on ’master’ in the linked repo
Or - specify branch, tag or commit to use:
mylib = { git = "https://mylibrepo" branch = "testing" }
mylib = { git = "https://mylibrepo" tag = "v0.12" }
mylib = { git = "https://mylibrepo" rev = "ede4591" }
@antweiss@antweiss
Versions of Truth : Path dependencies
> cargo new mybin
> cd mybin
# inside of mybin:
> cargo new --lib mylib
In Cargo.toml:
[dependencies]
mylib = { path = "mylib" }
Crates with path dependencies are not permitted on
crates.io. We’d need to publish a version of mylib to
crates.io and specify its version like this:
mylib = { path = "mylib" , version = "0.1.0" }
@antweiss@antweiss
Versions of Truth : Overriding dependencies
[dependencies]
serde_json = '1.0'
[patch.crates-io]
serde_json = { path = 'serde_json' }
[dependencies.mylibrs]
git = 'https://github.com/otomato_gh/mylibrs'
[patch.'https://github.com/otomato_gh/mylibrs']
mylibrs = { git = 'https://github.com/antweiss/mylibrs', branch =
'patched' }
@antweiss@antweiss
Multi-crate projects
a [workspace] is a set of crates that all share the same Cargo.lock
and output directory
[package]
name = "wsbin"
version = "0.1.0"
authors = ["Anton Weiss <anton@otomato.link>"]
[workspace]
members = ["wslib", "wsbin2"]
cargo build --all
@antweiss@antweiss
Configiring Your Cargo:
● ./.cargo/config
● ../parent/.cargo/config
● $HOME/.cargo/config
Some values:
[cargo-new]
name = "Ant Weiss"
email = "anton@otomato.link"
# By default `cargo new` will initialize a new Git repository.
vcs = "none"
[build]
jobs = 1 # number of parallel jobs, defaults to # of CPUs
rustc = "rustc" # the rust compiler tool
@antweiss@antweiss
Environment Variables
● CARGO - Path to the cargo binary performing the build.
● CARGO_MANIFEST_DIR - The directory containing the manifest of your
package.
● CARGO_PKG_VERSION - The full version of your package.
● CARGO_PKG_VERSION_MAJOR - The major version of your package.
● CARGO_PKG_VERSION_MINOR - The minor version of your package.
● CARGO_PKG_VERSION_PATCH - The patch version of your package.
● CARGO_PKG_VERSION_PRE - The pre-release version of your package.
● CARGO_PKG_AUTHORS - Colon separated list of authors from the manifest.
● CARGO_PKG_NAME - The name of your package.
● CARGO_PKG_DESCRIPTION - The description of your package.
● CARGO_PKG_HOMEPAGE - The home page of your package.
● OUT_DIR - If the package has a build script - the folder where it should
place its output.
let app = env!("CARGO_PKG_NAME");
@antweiss@antweiss
Build scripts
● Use Cases:
○ Building a bundled C library.
○ Finding a C library on the host system.
○ Generating a Rust module from a specification.
○ Performing any platform-specific configuration needed for the crate.
[package]
# ...
build = "build.rs" #the default
[build-dependencies]
protobuf-codegen-pure = "2.2.0"
@antweiss@antweiss
Example: code generation with protobufs
extern crate protobuf_codegen_pure;
fn main(){
protobuf_codegen_pure::run(protobuf_codegen_pure::Args {
out_dir: "src/protos",
input: &["protos/myprotos.proto"],
includes: &["protos"],
customize: protobuf_codegen_pure::Customize {
..Default::default()
},
}).expect("protoc");
}
@antweiss@antweiss
Publishing to Crates.io
Register to Crates.io : log in with your Github account. Go
to ‘Account Settings’ to get your API token.
Log in :
$ cargo login <your_API_token>
Package the crate:
$ cargo package
Publish the crate!:
$ cargo publish
[package]
# ...
exclude = [
"public/assets/*",
"videos/*",
]
@antweiss@antweiss
Integrating with the World
CI/CD Tools, IDEs, etc…
$ cargo metadata
Outputs project structure and dependencies information in JSON
$ cargo build --message-format json
Outputs:
● compiler errors and warnings,
● produced artifacts,
● results of the build scripts (for example, native dependencies)
@antweiss@antweiss
Custom subcommands
$ cargo my_command == ${PATH}/cargo-my_command
may use the $CARGO environment variable to call back to
Cargo
The list of known cargo subcommands.
@antweiss@antweiss
cargo-generate - cargo, make me a project
@antweiss@antweiss
cargo-make - Rust task runner and build tool.
[tasks.build]
command = "cargo"
args = ["build"]
dependencies = ["clean"]
[tasks.test]
command = "cargo"
args = ["test"]
dependencies = ["clean"]
[tasks.my-flow]
dependencies = [
"format",
"build",
"test"
]
cargo make --makefile build.toml my-flow
build.toml:
https://github.com/sagiegurari/cargo-make
@antweiss@antweiss
Unstable Features
cargo -Z help
Available unstable (nightly-only) flags:
-Z avoid-dev-deps -- Avoid installing dev-dependencies if possible
-Z minimal-versions -- Install minimal dependency versions instead of
maximum
-Z no-index-update -- Do not update the registry, avoids a network
request for benchmarking
-Z offline -- Offline mode that does not perform network requests
-Z unstable-options -- Allow the usage of unstable options such as
--registry
-Z config-profile -- Read profiles from .cargo/config files
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'
@antweiss@antweiss
Thank you!!!
@antweiss
http://otomato.link
http://devopstrain.pro

More Related Content

What's hot

Devoxx UK 2013: Sandboxing with the Vagrant-Binding API
Devoxx UK 2013: Sandboxing with the Vagrant-Binding APIDevoxx UK 2013: Sandboxing with the Vagrant-Binding API
Devoxx UK 2013: Sandboxing with the Vagrant-Binding APIHendrik Ebbers
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Soshi Nemoto
 
Oracle Developers APAC Meetup #1 - Working with Wercker Worksheets
Oracle Developers APAC Meetup #1 -  Working with Wercker WorksheetsOracle Developers APAC Meetup #1 -  Working with Wercker Worksheets
Oracle Developers APAC Meetup #1 - Working with Wercker WorksheetsDarrel Chia
 
Infrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & AnsibleInfrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & AnsibleRobert Reiz
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點William Yeh
 
Building (localized) Vagrant boxes with Packer
Building (localized) Vagrant boxes with PackerBuilding (localized) Vagrant boxes with Packer
Building (localized) Vagrant boxes with PackerCristovao G. Verstraeten
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansiblejtyr
 
Developing and Deploying PHP with Docker
Developing and Deploying PHP with DockerDeveloping and Deploying PHP with Docker
Developing and Deploying PHP with DockerPatrick Mizer
 
Docker + Microservices in Production
Docker + Microservices in ProductionDocker + Microservices in Production
Docker + Microservices in ProductionPatrick Mizer
 
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecMartin Etmajer
 
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2Yros
 
Vagrant for Virtualized Development
Vagrant for Virtualized DevelopmentVagrant for Virtualized Development
Vagrant for Virtualized DevelopmentAdam Culp
 
PHP development with Docker
PHP development with DockerPHP development with Docker
PHP development with DockerYosh de Vos
 
How Reconnix Is Using Docker
How Reconnix Is Using DockerHow Reconnix Is Using Docker
How Reconnix Is Using DockerRuss Mckendrick
 
How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environmentSumedt Jitpukdebodin
 
Lightweight and reproducible environments with vagrant and Puppet
Lightweight and reproducible environments with vagrant and PuppetLightweight and reproducible environments with vagrant and Puppet
Lightweight and reproducible environments with vagrant and PuppetHendrik Ebbers
 

What's hot (20)

Devoxx UK 2013: Sandboxing with the Vagrant-Binding API
Devoxx UK 2013: Sandboxing with the Vagrant-Binding APIDevoxx UK 2013: Sandboxing with the Vagrant-Binding API
Devoxx UK 2013: Sandboxing with the Vagrant-Binding API
 
Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)Fabric workshop(1) - (MOSG)
Fabric workshop(1) - (MOSG)
 
Oracle Developers APAC Meetup #1 - Working with Wercker Worksheets
Oracle Developers APAC Meetup #1 -  Working with Wercker WorksheetsOracle Developers APAC Meetup #1 -  Working with Wercker Worksheets
Oracle Developers APAC Meetup #1 - Working with Wercker Worksheets
 
Vagrant
VagrantVagrant
Vagrant
 
Vagrant For DevOps
Vagrant For DevOpsVagrant For DevOps
Vagrant For DevOps
 
Infrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & AnsibleInfrastructure Deployment with Docker & Ansible
Infrastructure Deployment with Docker & Ansible
 
Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點Ansible 實戰:top down 觀點
Ansible 實戰:top down 觀點
 
Vagrant to-aws-flow
Vagrant to-aws-flowVagrant to-aws-flow
Vagrant to-aws-flow
 
Building (localized) Vagrant boxes with Packer
Building (localized) Vagrant boxes with PackerBuilding (localized) Vagrant boxes with Packer
Building (localized) Vagrant boxes with Packer
 
Automation and Ansible
Automation and AnsibleAutomation and Ansible
Automation and Ansible
 
Developing and Deploying PHP with Docker
Developing and Deploying PHP with DockerDeveloping and Deploying PHP with Docker
Developing and Deploying PHP with Docker
 
Docker + Microservices in Production
Docker + Microservices in ProductionDocker + Microservices in Production
Docker + Microservices in Production
 
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
 
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
 
Vagrant for Virtualized Development
Vagrant for Virtualized DevelopmentVagrant for Virtualized Development
Vagrant for Virtualized Development
 
PHP development with Docker
PHP development with DockerPHP development with Docker
PHP development with Docker
 
How Reconnix Is Using Docker
How Reconnix Is Using DockerHow Reconnix Is Using Docker
How Reconnix Is Using Docker
 
How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environment
 
Lightweight and reproducible environments with vagrant and Puppet
Lightweight and reproducible environments with vagrant and PuppetLightweight and reproducible environments with vagrant and Puppet
Lightweight and reproducible environments with vagrant and Puppet
 
Intro to vagrant
Intro to vagrantIntro to vagrant
Intro to vagrant
 

Similar to A Deeper Look at Cargo

Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3kognate
 
Deploying a simple Rails application with AWS Elastic Beanstalk
Deploying a simple Rails application with AWS Elastic BeanstalkDeploying a simple Rails application with AWS Elastic Beanstalk
Deploying a simple Rails application with AWS Elastic BeanstalkJulien SIMON
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierCarlos Sanchez
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Carlos Sanchez
 
DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...
DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...
DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...DevSecCon
 
PVS-Studio in the Clouds: Azure DevOps
PVS-Studio in the Clouds: Azure DevOpsPVS-Studio in the Clouds: Azure DevOps
PVS-Studio in the Clouds: Azure DevOpsAndrey Karpov
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular applicationmirrec
 
Amazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionAmazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionPaolo latella
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with ComposerAdam Englander
 
Microservices Server - MSS Workshop
Microservices Server - MSS WorkshopMicroservices Server - MSS Workshop
Microservices Server - MSS WorkshopWSO2
 
Create Development and Production Environments with Vagrant
Create Development and Production Environments with VagrantCreate Development and Production Environments with Vagrant
Create Development and Production Environments with VagrantBrian Hogan
 
Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)Ben Hall
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012alexismidon
 
Docker for Ruby Developers
Docker for Ruby DevelopersDocker for Ruby Developers
Docker for Ruby DevelopersAptible
 
Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ...
Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ...Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ...
Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ...Andrey Karpov
 
Start tracking your ruby infrastructure
Start tracking your ruby infrastructureStart tracking your ruby infrastructure
Start tracking your ruby infrastructureSergiy Kukunin
 

Similar to A Deeper Look at Cargo (20)

Docker Starter Pack
Docker Starter PackDocker Starter Pack
Docker Starter Pack
 
Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3Server(less) Swift at SwiftCloudWorkshop 3
Server(less) Swift at SwiftCloudWorkshop 3
 
Deploying a simple Rails application with AWS Elastic Beanstalk
Deploying a simple Rails application with AWS Elastic BeanstalkDeploying a simple Rails application with AWS Elastic Beanstalk
Deploying a simple Rails application with AWS Elastic Beanstalk
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
 
DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...
DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...
DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...
 
PVS-Studio in the Clouds: Azure DevOps
PVS-Studio in the Clouds: Azure DevOpsPVS-Studio in the Clouds: Azure DevOps
PVS-Studio in the Clouds: Azure DevOps
 
Dev ops meetup
Dev ops meetupDev ops meetup
Dev ops meetup
 
Composer
ComposerComposer
Composer
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
Amazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionAmazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to production
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
 
Microservices Server - MSS Workshop
Microservices Server - MSS WorkshopMicroservices Server - MSS Workshop
Microservices Server - MSS Workshop
 
Create Development and Production Environments with Vagrant
Create Development and Production Environments with VagrantCreate Development and Production Environments with Vagrant
Create Development and Production Environments with Vagrant
 
Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)Running Docker in Development & Production (#ndcoslo 2015)
Running Docker in Development & Production (#ndcoslo 2015)
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
 
Docker for Ruby Developers
Docker for Ruby DevelopersDocker for Ruby Developers
Docker for Ruby Developers
 
Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ...
Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ...Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ...
Analysis of commits and pull requests in Travis CI, Buddy and AppVeyor using ...
 
Start tracking your ruby infrastructure
Start tracking your ruby infrastructureStart tracking your ruby infrastructure
Start tracking your ruby infrastructure
 
Capistrano
CapistranoCapistrano
Capistrano
 

More from Anton Weiss

The New Science of Software Delivery
The New Science of Software DeliveryThe New Science of Software Delivery
The New Science of Software DeliveryAnton Weiss
 
Escaping the Jungle - Migrating to Cloud Native CI/CD
Escaping the Jungle - Migrating to Cloud Native CI/CDEscaping the Jungle - Migrating to Cloud Native CI/CD
Escaping the Jungle - Migrating to Cloud Native CI/CDAnton Weiss
 
Envoy, Wasm and Rust - the Mighty Trio
Envoy, Wasm and Rust -  the Mighty TrioEnvoy, Wasm and Rust -  the Mighty Trio
Envoy, Wasm and Rust - the Mighty TrioAnton Weiss
 
Dumb Services in Smart Nets - istio
Dumb Services in Smart Nets -  istioDumb Services in Smart Nets -  istio
Dumb Services in Smart Nets - istioAnton Weiss
 
WTF Do We Need a Service Mesh?
WTF Do We Need a Service Mesh? WTF Do We Need a Service Mesh?
WTF Do We Need a Service Mesh? Anton Weiss
 
Many Changes Little Fun
Many Changes Little Fun Many Changes Little Fun
Many Changes Little Fun Anton Weiss
 
Optimizing the Delivery Pipeline for Flow
Optimizing the Delivery Pipeline for FlowOptimizing the Delivery Pipeline for Flow
Optimizing the Delivery Pipeline for FlowAnton Weiss
 
Heralding change - How to Get Engineers On Board the DevOps Ship
Heralding change - How to Get Engineers On Board the DevOps ShipHeralding change - How to Get Engineers On Board the DevOps Ship
Heralding change - How to Get Engineers On Board the DevOps ShipAnton Weiss
 
When Your Pipelines Are a Mess
When Your Pipelines Are a MessWhen Your Pipelines Are a Mess
When Your Pipelines Are a MessAnton Weiss
 
Wiring up microservices with Istio
Wiring up microservices with IstioWiring up microservices with Istio
Wiring up microservices with IstioAnton Weiss
 
ChatOps - the Road to a Collaborative CLI
ChatOps  - the Road to a Collaborative CLI ChatOps  - the Road to a Collaborative CLI
ChatOps - the Road to a Collaborative CLI Anton Weiss
 
The Road to a Hybrid, Transparent Pipeline
The Road to a Hybrid, Transparent PipelineThe Road to a Hybrid, Transparent Pipeline
The Road to a Hybrid, Transparent PipelineAnton Weiss
 
Jenkins and the Future of Software Delivery
Jenkins and the Future of Software DeliveryJenkins and the Future of Software Delivery
Jenkins and the Future of Software DeliveryAnton Weiss
 
How Openstack is Built
How Openstack is BuiltHow Openstack is Built
How Openstack is BuiltAnton Weiss
 
Continuous Delivery is Not a Commodity
Continuous Delivery is Not a CommodityContinuous Delivery is Not a Commodity
Continuous Delivery is Not a CommodityAnton Weiss
 
Grooving with Jenkins
Grooving with JenkinsGrooving with Jenkins
Grooving with JenkinsAnton Weiss
 
Ninja, Choose Your Weapon!
Ninja, Choose Your Weapon!Ninja, Choose Your Weapon!
Ninja, Choose Your Weapon!Anton Weiss
 
DevOps - Transparency & Self Service
DevOps - Transparency & Self ServiceDevOps - Transparency & Self Service
DevOps - Transparency & Self ServiceAnton Weiss
 
Vagrant in 15 minutes
Vagrant in 15 minutesVagrant in 15 minutes
Vagrant in 15 minutesAnton Weiss
 
Continuous Delivery for Mobile R&D
Continuous Delivery for Mobile R&DContinuous Delivery for Mobile R&D
Continuous Delivery for Mobile R&DAnton Weiss
 

More from Anton Weiss (20)

The New Science of Software Delivery
The New Science of Software DeliveryThe New Science of Software Delivery
The New Science of Software Delivery
 
Escaping the Jungle - Migrating to Cloud Native CI/CD
Escaping the Jungle - Migrating to Cloud Native CI/CDEscaping the Jungle - Migrating to Cloud Native CI/CD
Escaping the Jungle - Migrating to Cloud Native CI/CD
 
Envoy, Wasm and Rust - the Mighty Trio
Envoy, Wasm and Rust -  the Mighty TrioEnvoy, Wasm and Rust -  the Mighty Trio
Envoy, Wasm and Rust - the Mighty Trio
 
Dumb Services in Smart Nets - istio
Dumb Services in Smart Nets -  istioDumb Services in Smart Nets -  istio
Dumb Services in Smart Nets - istio
 
WTF Do We Need a Service Mesh?
WTF Do We Need a Service Mesh? WTF Do We Need a Service Mesh?
WTF Do We Need a Service Mesh?
 
Many Changes Little Fun
Many Changes Little Fun Many Changes Little Fun
Many Changes Little Fun
 
Optimizing the Delivery Pipeline for Flow
Optimizing the Delivery Pipeline for FlowOptimizing the Delivery Pipeline for Flow
Optimizing the Delivery Pipeline for Flow
 
Heralding change - How to Get Engineers On Board the DevOps Ship
Heralding change - How to Get Engineers On Board the DevOps ShipHeralding change - How to Get Engineers On Board the DevOps Ship
Heralding change - How to Get Engineers On Board the DevOps Ship
 
When Your Pipelines Are a Mess
When Your Pipelines Are a MessWhen Your Pipelines Are a Mess
When Your Pipelines Are a Mess
 
Wiring up microservices with Istio
Wiring up microservices with IstioWiring up microservices with Istio
Wiring up microservices with Istio
 
ChatOps - the Road to a Collaborative CLI
ChatOps  - the Road to a Collaborative CLI ChatOps  - the Road to a Collaborative CLI
ChatOps - the Road to a Collaborative CLI
 
The Road to a Hybrid, Transparent Pipeline
The Road to a Hybrid, Transparent PipelineThe Road to a Hybrid, Transparent Pipeline
The Road to a Hybrid, Transparent Pipeline
 
Jenkins and the Future of Software Delivery
Jenkins and the Future of Software DeliveryJenkins and the Future of Software Delivery
Jenkins and the Future of Software Delivery
 
How Openstack is Built
How Openstack is BuiltHow Openstack is Built
How Openstack is Built
 
Continuous Delivery is Not a Commodity
Continuous Delivery is Not a CommodityContinuous Delivery is Not a Commodity
Continuous Delivery is Not a Commodity
 
Grooving with Jenkins
Grooving with JenkinsGrooving with Jenkins
Grooving with Jenkins
 
Ninja, Choose Your Weapon!
Ninja, Choose Your Weapon!Ninja, Choose Your Weapon!
Ninja, Choose Your Weapon!
 
DevOps - Transparency & Self Service
DevOps - Transparency & Self ServiceDevOps - Transparency & Self Service
DevOps - Transparency & Self Service
 
Vagrant in 15 minutes
Vagrant in 15 minutesVagrant in 15 minutes
Vagrant in 15 minutes
 
Continuous Delivery for Mobile R&D
Continuous Delivery for Mobile R&DContinuous Delivery for Mobile R&D
Continuous Delivery for Mobile R&D
 

Recently uploaded

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 

Recently uploaded (20)

Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 

A Deeper Look at Cargo

  • 1. @antweiss@antweiss A Deeper Look at Cargo Ant Weiss, Otomato http://otomato.link
  • 2. @antweiss@antweiss Cargo is the Package Manager for Rust ● Basic Scaffolding ● Dependency Mgmt ● Compilation ● Packaging ● Publishing ● Toolchain Expansion
  • 3. @antweiss@antweiss The First Step cargo new --bin my-rust-app cargo new --lib my-rust-lib cargo new my-rust-app --vcs git
  • 4. @antweiss@antweiss The toml and the lock Cargo.toml: (AKA The Manifest) [package] name = "some-app" version = "0.1.0" authors = ["Anton Weiss <anton@otomato.link>"] [dependencies] tiny_http = "0.6.0" redis = "0.9.0"
  • 5. @antweiss@antweiss Cargo.lock Simple rule: Binary: check Cargo.lock into source control Library: put Cargo.lock in .gitignore Don’t use “*” dependencies. Crates.io will reject your crate!
  • 6. @antweiss@antweiss Depends On... ● Crates from crates.io [dependencies] chashmap = "2.2.0" ● Git repos [dependencies] evmap = ( git = https://github.com/jonhoo/rust-evmap.git } ● Files in subdirectories of your project [dependencies] hello_utils = { path = "hello_utils" }
  • 7. @antweiss@antweiss Versions of Truth Cargo.toml: [dependencies] clap = "2.20.0" >cargo build Updating crates.io index ... Compiling clap v2.32.0 To ensure specific version - use: mylib = "=0.2.3" Maximal Version Resolution = At the time the lockfile is generated - the latest available version is used.
  • 8. @antweiss@antweiss Versions of Truth : Caret An update is allowed if the new version number does not modify the left-most non-zero digit in the major, minor, patch grouping: [dependencies] time = "^0.20.0" Examples: ^1.2.3 := >=1.2.3 <2.0.0 ^1.2 := >=1.2.0 <2.0.0 ^1 := >=1.0.0 <2.0.0 ^0.2.3 := >=0.2.3 <0.3.0 ^0.2 := >= 0.2.0 < 0.3.0 ^0.0.3 := >=0.0.3 <0.0.4 ^0.0 := >=0.0.0 <0.1.0 ^0 := >=0.0.0 <1.0.0
  • 9. @antweiss@antweiss Versions of Truth : Tilde Specify a minimal version with some ability to update: [dependencies] clap = "~2.3.0" Examples: ~1.2.3 := >=1.2.3 <1.3.0 ~1.2 := >=1.2.0 <1.3.0 ~1 := >=1.0.0 <2.0.0
  • 10. @antweiss@antweiss Versions of Truth : Wildcard and Inequality Wildcard - allow for any version where the wildcard is. Examples: * := >=0.0.0 1.* := >=1.0.0 <2.0.0 1.2.* := >=1.2.0 <1.3.0 In/equality - allow manually specifying a version range or an exact version. Examples: >= 1.2.0 > 1 < 2 = 1.2.3
  • 11. @antweiss@antweiss Updating dependencies: > cargo update Or > cargo update -p mycrate To update a specific crate.
  • 12. @antweiss@antweiss Versions of Truth : Git [dependencies] rand = { git = "https://github.com/rust-lang-nursery/rand" } = Use the latest commit on ’master’ in the linked repo Or - specify branch, tag or commit to use: mylib = { git = "https://mylibrepo" branch = "testing" } mylib = { git = "https://mylibrepo" tag = "v0.12" } mylib = { git = "https://mylibrepo" rev = "ede4591" }
  • 13. @antweiss@antweiss Versions of Truth : Path dependencies > cargo new mybin > cd mybin # inside of mybin: > cargo new --lib mylib In Cargo.toml: [dependencies] mylib = { path = "mylib" } Crates with path dependencies are not permitted on crates.io. We’d need to publish a version of mylib to crates.io and specify its version like this: mylib = { path = "mylib" , version = "0.1.0" }
  • 14. @antweiss@antweiss Versions of Truth : Overriding dependencies [dependencies] serde_json = '1.0' [patch.crates-io] serde_json = { path = 'serde_json' } [dependencies.mylibrs] git = 'https://github.com/otomato_gh/mylibrs' [patch.'https://github.com/otomato_gh/mylibrs'] mylibrs = { git = 'https://github.com/antweiss/mylibrs', branch = 'patched' }
  • 15. @antweiss@antweiss Multi-crate projects a [workspace] is a set of crates that all share the same Cargo.lock and output directory [package] name = "wsbin" version = "0.1.0" authors = ["Anton Weiss <anton@otomato.link>"] [workspace] members = ["wslib", "wsbin2"] cargo build --all
  • 16. @antweiss@antweiss Configiring Your Cargo: ● ./.cargo/config ● ../parent/.cargo/config ● $HOME/.cargo/config Some values: [cargo-new] name = "Ant Weiss" email = "anton@otomato.link" # By default `cargo new` will initialize a new Git repository. vcs = "none" [build] jobs = 1 # number of parallel jobs, defaults to # of CPUs rustc = "rustc" # the rust compiler tool
  • 17. @antweiss@antweiss Environment Variables ● CARGO - Path to the cargo binary performing the build. ● CARGO_MANIFEST_DIR - The directory containing the manifest of your package. ● CARGO_PKG_VERSION - The full version of your package. ● CARGO_PKG_VERSION_MAJOR - The major version of your package. ● CARGO_PKG_VERSION_MINOR - The minor version of your package. ● CARGO_PKG_VERSION_PATCH - The patch version of your package. ● CARGO_PKG_VERSION_PRE - The pre-release version of your package. ● CARGO_PKG_AUTHORS - Colon separated list of authors from the manifest. ● CARGO_PKG_NAME - The name of your package. ● CARGO_PKG_DESCRIPTION - The description of your package. ● CARGO_PKG_HOMEPAGE - The home page of your package. ● OUT_DIR - If the package has a build script - the folder where it should place its output. let app = env!("CARGO_PKG_NAME");
  • 18. @antweiss@antweiss Build scripts ● Use Cases: ○ Building a bundled C library. ○ Finding a C library on the host system. ○ Generating a Rust module from a specification. ○ Performing any platform-specific configuration needed for the crate. [package] # ... build = "build.rs" #the default [build-dependencies] protobuf-codegen-pure = "2.2.0"
  • 19. @antweiss@antweiss Example: code generation with protobufs extern crate protobuf_codegen_pure; fn main(){ protobuf_codegen_pure::run(protobuf_codegen_pure::Args { out_dir: "src/protos", input: &["protos/myprotos.proto"], includes: &["protos"], customize: protobuf_codegen_pure::Customize { ..Default::default() }, }).expect("protoc"); }
  • 20. @antweiss@antweiss Publishing to Crates.io Register to Crates.io : log in with your Github account. Go to ‘Account Settings’ to get your API token. Log in : $ cargo login <your_API_token> Package the crate: $ cargo package Publish the crate!: $ cargo publish [package] # ... exclude = [ "public/assets/*", "videos/*", ]
  • 21. @antweiss@antweiss Integrating with the World CI/CD Tools, IDEs, etc… $ cargo metadata Outputs project structure and dependencies information in JSON $ cargo build --message-format json Outputs: ● compiler errors and warnings, ● produced artifacts, ● results of the build scripts (for example, native dependencies)
  • 22. @antweiss@antweiss Custom subcommands $ cargo my_command == ${PATH}/cargo-my_command may use the $CARGO environment variable to call back to Cargo The list of known cargo subcommands.
  • 24. @antweiss@antweiss cargo-make - Rust task runner and build tool. [tasks.build] command = "cargo" args = ["build"] dependencies = ["clean"] [tasks.test] command = "cargo" args = ["test"] dependencies = ["clean"] [tasks.my-flow] dependencies = [ "format", "build", "test" ] cargo make --makefile build.toml my-flow build.toml: https://github.com/sagiegurari/cargo-make
  • 25. @antweiss@antweiss Unstable Features cargo -Z help Available unstable (nightly-only) flags: -Z avoid-dev-deps -- Avoid installing dev-dependencies if possible -Z minimal-versions -- Install minimal dependency versions instead of maximum -Z no-index-update -- Do not update the registry, avoids a network request for benchmarking -Z offline -- Offline mode that does not perform network requests -Z unstable-options -- Allow the usage of unstable options such as --registry -Z config-profile -- Read profiles from .cargo/config files Run with 'cargo -Z [FLAG] [SUBCOMMAND]'