Skip to content

Commit

Permalink
Make pypi releases from ci
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Sep 16, 2018
1 parent c923e38 commit 6f57592
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 139 deletions.
56 changes: 24 additions & 32 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,18 @@ env:
global:
# Change this to the name of your binary
- BINARY_NAME="pyo3-pack"
- PKG_CONFIG_ALLOW_CROSS=1 # For openssl-sys
- secure: xxDBiPcL7jDjbnKJ3R0UzTTjaWdITGBHUB7SmjKAy5WPk8Eyx/BgYwGBv2F4/EfSOoOOF+HSUfegXV70r+UHA8OyZtb+h9RLrcBsnEvnrBo2FylQCzz8JeoTdHJikvhH8H9oEbb4jQpwy85r5xDK3+8dMkD2nDjf5vfctblMyShayNTzyMX9DkG5OqZnJ0CXaPzPrtrMXEw3hPpMpyTYBqnZhNVK5IHzXA8kR+6WKgkrf+X/48Or3TDys9ufdO3mEazgxfLJ6WHESQFONYtjT67++rkBNB0jYXf+bFjW2OaEl9Qa8ZHevbWZcJkb3dlW9ktbPnhBmjw14a6Oqhu1w5x2DGVp9196vRwPzXi5YCFXbw93OurF2cDS4NVCk5vZKKuKZvHa6LdS6zVh31uwdOYa5AUK9mYLpwsW0B8k/YyBjea9pkskyBeLXzKpYXgplbMzyqnJZMoiHimeLlHMNNSUlJqKVinDEEEukazABJvN6xcbUunvKj8nQpNVdVg0NPcmMQ2R7CLOJTkhLYqnq+CsX8nTmH5PSh/XxA7NkTfbbibxpWqHp0QDLCFltK23rGAAhs0WkvXF8lSaUSpl7DksA3CfNUn2eI2k+iWao8OD7gu0pFeVOHxND4fuT8Jy8nILySwsECyB0LECPNr++Ymz6+xMHrlaIpGBkCGQXcY=

addons:
apt:
packages:
# If your project needs any system packages add them here
- libdbus-1-dev

matrix:
fast_finish: true
include:
# Those are tested
- os: linux
rust: nightly
env: TARGET=x86_64-unknown-linux-gnu
- os: osx
rust: nightly
env: TARGET=x86_64-apple-darwin

# These create deployments
# These create deployments; Apparently there is not 32 bit mac os
- os: linux
rust: stable
env: TARGET=x86_64-unknown-linux-gnu
Expand All @@ -33,17 +25,23 @@ matrix:
- os: linux
rust: stable
env: TARGET=i686-unknown-linux-gnu
- os: osx
rust: stable
env: TARGET=i686-apple-darwin
addons:
apt:
packages:
- libdbus-1-dev:i386
- libc6-dev-i386
- linux-libc-dev:i386
- libssl-dev:i386
- libgmp-dev:i386
- gcc-multilib

# Other rust versions to check
- os: linux
rust: 1.28.0
env: TARGET=x86_64-unknown-linux-gnu
# Those are tested
- os: linux
rust: beta
rust: nightly
env: TARGET=x86_64-unknown-linux-gnu
- os: osx
rust: nightly
env: TARGET=x86_64-apple-darwin

install:
# Both pyenv and travis are weird; Mac os can't do virtualenv out of venv, linux needs a venv, so this
Expand All @@ -66,16 +64,17 @@ install:
fi
script:
- curl https://sh.rustup.rs -sSf | sh -s -- -y --default-host $TARGET --default-toolchain $TRAVIS_RUST_VERSION
- cargo build
- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo test -- --nocapture; fi
- if [ "$TARGET" == "i686-unknown-linux-gnu" ]; then rustup target add $TARGET; fi
- cargo build --target $TARGET
- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo test --target $TARGET -- --nocapture; fi

before_deploy:
- cargo build --release
- cd target/release/
- cargo build --release --target $TARGET
- cargo run --target $TARGET -- publish -b bin --cargo-extra-args="--target=$TARGET" --skip-auditwheel -u konstin
- cd target/$TARGET/release/
# You can add more file to the archive by adding them to this line
- tar czf ../../${BINARY_NAME}-$TRAVIS_TAG-$TARGET.tar.gz ${BINARY_NAME}
- cd ../..
- tar czf ../../../${BINARY_NAME}-$TRAVIS_TAG-$TARGET.tar.gz ${BINARY_NAME}
- cd ../../..

deploy:
- # Add zipped binary to the github release
Expand All @@ -91,13 +90,6 @@ deploy:
# - Paste the output down here
api_key:
secure: "bKY3J8FBwgit9inzp2CMxQC3icBVco+COcRnqM6NhaOWX3KefXYG/yWQ7htBkeTRAfQERlOkZZOPsOto2dAD49/Mo4Uin9wbRPjPDGPJpFcQofX5aKHqK1Xd1k96rtZKZRIEG5k5J2IKAzPso3GnA0FESAZlZbxEShSCBD6aOlVmjFXwB2kKzJDo9zECxCg84GSvR/7wQg4hwMaMBa79y3VJRCohGTMaISL22QJ0haG+gqZgTv/r9K8P9lwSMBIiTXX3wFJU871sqUNTSSwkmHlVLhVUOwluv+KQ2DI/V/gWfx2CuiZ/7OQlz4zkOB/Y56msH0G7vOwqbSHLwkMYC+zgDWvF0oI/Eb/mdY5VliQdsLDOkKwWm3EuoEUvCgyV9UB1POxxogIx1sAU+Vt9QUj5/cRIJc1zrtA3LdNlbg9M9rYG8jJ6JMbeYTFDTL6YNoHc2lPAdmAqQAZQy6vyR515vm76JfS7yDcLRXKKhLE4dEPUEpv0qU8vCA/FdaZaiW+GJZSS5rJoE0vHaMRsWkgFLqCNSDpUZBd2x60E+n6dQ7XX4DrJ1JmzcG+IZ6AfuIWyRD9s3jQBxRjtyM61ZGo3Nb4zwX2ML1PftNURNAo8rPlgIrqPaveic45hP6PAeX+iMIWzTckq8shlYngjBTw/3UmA8Z18udrRyKCbygs="
- provider: script
skip_cleanup: true
on: # Create downloads only with stable rust and only for stable releases
condition: $TRAVIS_RUST_VERSION = stable
tags: true
# The password is in the travis ui config
script: cargo run -- publish -b bin --cargo-extra-args="--target=$TARGET" --skip-auditwheel -u konstin

branches:
only:
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["konstin <[email protected]>"]
name = "pyo3-pack"
version = "0.3.2-beta.6"
version = "0.3.3"
description = "Build and publish crates with pyo3 bindings as python packages"
exclude = ["get-fourtytwo/**/*", "integration-test/**/*", "sysconfig/*"]
readme = "Readme.md"
Expand Down Expand Up @@ -44,6 +44,7 @@ indicatif = "0.9.0"
atty = "0.2.11"
tempfile = "3.0.3"
goblin = { version = "0.0.17", optional = true }
openssl = { version = "0.10", features = ["vendored"], optional = true }

[dev-dependencies]
indoc = "0.2.8"
Expand All @@ -55,6 +56,7 @@ auditwheel = ["goblin"]
sdist = ["tar", "libflate"]
upload = ["reqwest"]
password-storage = ["upload", "keyring"]
musl_wip = ["openssl"]

[workspace]
members = [
Expand Down
17 changes: 8 additions & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ environment:
CHANNEL: stable
- TARGET: x86_64-pc-windows-msvc
CHANNEL: stable
# Only check compilation
- TARGET: i686-pc-windows-gnu
CHANNEL: stable
- TARGET: x86_64-pc-windows-gnu
CHANNEL: stable

# Commented out to avoid duplicate uploads to pypi
#- TARGET: i686-pc-windows-gnu
# CHANNEL: stable
#- TARGET: x86_64-pc-windows-gnu
# CHANNEL: stable

# For the integration test
# The test passes, but the build still fails for an unknown reason.
# If this is the last entry, we still get the binaries on releases until the this cause is fixed
Expand Down Expand Up @@ -60,10 +62,7 @@ before_deploy:
- cargo build --release
# I don't know how I can create a script deployment like in travis in appveyor, so let's hijack before_deploy
# Also we only need one version for win32 and one for win_amd64, so we only deploy to pypi for msvc
- ps: |
if ($env:target -like "*-msvc") {
cargo run -- publish -b bin -u konstin
}
- cargo run -- publish -b bin -u konstin
# Grab the binary and pack it into a zip archive
- cd target\release\
# You can add more file to the archive by adding them to this line
Expand Down
66 changes: 32 additions & 34 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use auditwheel_rs;
use build_source_distribution;
use compile;
use failure::{Context, Error, ResultExt};
use module_writer::WheelWriter;
use Metadata21;
use module_writer::{write_bin, write_bindings_module, write_cffi_module};
use module_writer::WheelWriter;
use PythonInterpreter;
use std::collections::HashMap;
use std::fs;
use std::path::PathBuf;
use Metadata21;
use PythonInterpreter;
use Target;

/// The way the rust code is bridged with python, i.e. either using extern c and cffi or
Expand All @@ -22,18 +22,15 @@ pub enum BridgeModel {
/// A rust binary to be shipped a python package
Bin,
/// A native module with pyo3 or rust-cpython bindings
Bindings {
interpreter: Vec<PythonInterpreter>,
bindings_crate: String,
},
Bindings(String),
}

impl BridgeModel {
// TODO
pub fn to_option(&self) -> Option<String> {
/// Returns the name of the bindings crate
pub fn unwrap_bindings(&self) -> &str {
match self {
BridgeModel::Cffi | BridgeModel::Bin => None,
BridgeModel::Bindings { bindings_crate, .. } => Some(bindings_crate.clone()),
BridgeModel::Bindings(value) => &value,
_ => panic!("Expected Bindings"),
}
}
}
Expand Down Expand Up @@ -65,6 +62,8 @@ pub struct BuildContext {
pub cargo_extra_args: Vec<String>,
/// Extra arguments that will be passed to rustc as `cargo rustc [...] -- [arg1] [arg2]`
pub rustc_extra_args: Vec<String>,
/// The available python interpreter
pub interpreter: Vec<PythonInterpreter>,
}

impl BuildContext {
Expand All @@ -77,7 +76,7 @@ impl BuildContext {
let wheels = match &self.bridge {
BridgeModel::Cffi => vec![(self.build_cffi_wheel()?, "py2.py3".to_string(), None)],
BridgeModel::Bin => vec![(self.build_bin_wheel()?, "py2.py3".to_string(), None)],
BridgeModel::Bindings { interpreter, .. } => self.build_binding_wheels(&interpreter)?,
BridgeModel::Bindings(_) => self.build_binding_wheels()?,
};

Ok(wheels)
Expand All @@ -92,10 +91,9 @@ impl BuildContext {
/// [auditwheel_rs()] if the auditwheel feature isn't deactivated
pub fn build_binding_wheels(
&self,
interpreter: &[PythonInterpreter],
) -> Result<Vec<(PathBuf, String, Option<PythonInterpreter>)>, Error> {
let mut wheels = Vec::new();
for python_version in interpreter {
for python_version in &self.interpreter {
let artifact = self.compile_cdylib(Some(&python_version))?;

let tag = python_version.get_tag();
Expand Down Expand Up @@ -128,22 +126,22 @@ impl BuildContext {
}

#[cfg(feature = "sdist")]
{
let sdist_path = wheel_dir.join(format!(
"{}-{}.tar.gz",
&self.metadata21.get_distribution_encoded(),
&self.metadata21.get_version_encoded()
));

println!(
"Building the source distribution to {}",
sdist_path.display()
);
build_source_distribution(&self, &self.metadata21, &self.scripts, &sdist_path)
.context("Failed to build the source distribution")?;

wheels.push((sdist_path, None));
}
{
let sdist_path = wheel_dir.join(format!(
"{}-{}.tar.gz",
&self.metadata21.get_distribution_encoded(),
&self.metadata21.get_version_encoded()
));

println!(
"Building the source distribution to {}",
sdist_path.display()
);
build_source_distribution(&self, &self.metadata21, &self.scripts, &sdist_path)
.context("Failed to build the source distribution")?;

wheels.push((sdist_path, None));
}

Ok(wheels)
}
Expand All @@ -154,7 +152,7 @@ impl BuildContext {
&self,
python_interpreter: Option<&PythonInterpreter>,
) -> Result<PathBuf, Error> {
let artifacts = compile(&self, python_interpreter, self.bridge.to_option())
let artifacts = compile(&self, python_interpreter, &self.bridge)
.context("Failed to build a native library through cargo")?;

let artifact = artifacts.get("cdylib").cloned().ok_or_else(|| {
Expand All @@ -170,7 +168,7 @@ impl BuildContext {

if !self.skip_auditwheel && target.is_linux() {
#[cfg(feature = "auditwheel")]
auditwheel_rs(&artifact).context("Failed to ensure manylinux compliance")?;
auditwheel_rs(&artifact).context("Failed to ensure manylinux compliance")?;
}

Ok(artifact)
Expand Down Expand Up @@ -205,7 +203,7 @@ impl BuildContext {

/// Builds a wheel that contains a rust binary and an entrypoint for that binary
pub fn build_bin_wheel(&self) -> Result<PathBuf, Error> {
let artifacts = compile(&self, None, self.bridge.to_option())
let artifacts = compile(&self, None, &self.bridge)
.context("Failed to build a native library through cargo")?;

let artifact = artifacts
Expand All @@ -215,7 +213,7 @@ impl BuildContext {

if !self.skip_auditwheel && self.target.is_linux() {
#[cfg(feature = "auditwheel")]
auditwheel_rs(&artifact).context("Failed to ensure manylinux compliance")?;
auditwheel_rs(&artifact).context("Failed to ensure manylinux compliance")?;
}

let (tag, tags) = self.get_unversal_tags();
Expand Down
Loading

0 comments on commit 6f57592

Please sign in to comment.