diff --git a/.travis.yml b/.travis.yml index 9314eadd..4610bad4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,61 @@ cache: cargo dist: trusty -env: TARGET=x86_64-unknown-linux-gnu language: rust -rust: nightly-2016-09-30 +rust: stable services: docker sudo: required +env: + global: + - CRATE_NAME=svd2rust + - TARGET=x86_64-unknown-linux-gnu + +matrix: + include: + # OSX + - env: TARGET=i686-apple-darwin + os: osx + - env: TARGET=x86_64-apple-darwin + os: osx + + # Linux + - env: TARGET=i686-unknown-linux-gnu + - env: TARGET=i686-unknown-linux-musl + - env: TARGET=x86_64-unknown-linux-musl + +install: + # `std for cross-compilation + - curl https://static.rust-lang.org/rustup.sh | + sh -s -- --add-target=$TARGET --disable-sudo -y --prefix=`rustc --print sysroot` + script: - cargo generate-lockfile - - sh ci/run-docker.sh $TARGET + - if [[ $TRAVIS_OS_NAME = linux ]]; then + sh ci/run-docker.sh $TARGET; + else + sh ci/run.sh; + fi # Travis can't cache files that are not readable by "others" - chmod -R a+r $HOME/.cargo +before_deploy: + - sh ci/package.sh $TARGET + +deploy: + provider: releases + api_key: + secure: b+q2Uul+hA1OyFbfWaQTF02xwZNTl5x8uumHkx7eeZZYtrXZh8aKyMgUiCVbcdch+p8r0QqvGYXyHUqtCmeFzLrFiudoleQBojs+0Pbrfnw5PH93k4Bf2snOJu6Sp5xjl5X34C+eM/hT3vIrAmEZCXFwVG7piZsdXWBdvkudz6pit8R2hsa6uxbyCs2lXmS/aWHSygg25DtrP/cezILxwS0VtXwgFOUTn8AQMd4bZeEz6ezTcUuCKEHdC9SUmFiNIwR7rjVzL4+Z7ffOz3TF4UHyTa+DLRM4pIO4L/DH+G2KJ3kw2C/98tLGwyObYChwiKXY1lW+bjauD38rwIMpzbAEAx+oPZQNLwdLXjIk9ZN9K3Dm0yWs5aZC+8O7QiOgxMTA3zQmZJdSRpnHLZJKns8hmxOyVeGr+RlTt+sJXqErgN8yzUSdn918kTbAqvc1x0zb/eC+wAx7ULvgjGmO6AuWZWRVM6SrXoKjANUCH1OdkpFA7T0pZ3Nx4p503234hKFyIoS/sd1I17bcBElP59zdv/NlpBAndxRdzPk/V2W40736xxLdQWgRgTMP95+/AJmsf8orscVag/wOdN4ACmwdAi6YxZB+bO9mMzuLJ8Z9BoudGqzaw3uCxkNNQSn+KJ+MrkhBnct7TnDPuAhy4pAOtmwgW3PTPrxsiNQQw+4= + file: $CRATE_NAME-$TRAVIS_TAG-$TARGET.* + # don't delete the target directory + skip_cleanup: true + on: + condition: $TRAVIS_RUST_VERSION = stable + tags: true + branches: only: + # Release tags + - /^v\d+\.\d+\.\d+.*$/ - auto - try diff --git a/Cargo.toml b/Cargo.toml index e7b19fbe..46738f5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [package] authors = ["Jorge Aparicio "] -build = "build.rs" name = "svd2rust" version = "0.1.0" diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..8d406982 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,49 @@ +environment: + global: + CRATE_NAME: svd2rust + RUST_VERSION: nightly + matrix: + - TARGET: i686-pc-windows-gnu + - TARGET: i686-pc-windows-msvc + - TARGET: x86_64-pc-windows-gnu + - TARGET: x86_64-pc-windows-msvc + +install: + - ps: ci\install.ps1 + +build: false + +test_script: + - if [%APPVEYOR_REPO_TAG%]==[false] ( + cargo build --target %TARGET% + ) else ( + cargo rustc --target %TARGET% --release --bin svd2rust -- -C lto + ) + +before_deploy: + - ps: ci\package.ps1 + +deploy: + description: 'Windows release' + artifact: /.*\.zip/ + auth_token: + secure: bQ29dEXeNG5VP2hQcWiZ1xsfmkGosteCDNeYu/cXTX4lOeghOp0qANpQXmGfal29 + provider: GitHub + on: + RUST_VERSION: nightly + appveyor_repo_tag: true + +cache: + - C:\Users\appveyor\.cargo\registry + - target + +branches: + only: + # Release tags + - /^v\d+\.\d+\.\d+.*$/ + - auto + - try + +notifications: + - provider: Email + on_build_success: false diff --git a/build.rs b/build.rs deleted file mode 100644 index 39d0e8e1..00000000 --- a/build.rs +++ /dev/null @@ -1,10 +0,0 @@ -use std::fs::File; -use std::io::Write; -use std::path::Path; - -fn main() { - File::create(Path::new(env!("OUT_DIR")).join("version.txt")) - .unwrap() - .write_all(env!("CARGO_PKG_VERSION").as_bytes()) - .unwrap(); -} diff --git a/ci/docker/i686-unknown-linux-gnu/Dockerfile b/ci/docker/i686-unknown-linux-gnu/Dockerfile new file mode 100644 index 00000000..ce01b524 --- /dev/null +++ b/ci/docker/i686-unknown-linux-gnu/Dockerfile @@ -0,0 +1,6 @@ +FROM ubuntu:12.04 +RUN apt-get update +RUN apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + gcc-multilib diff --git a/ci/docker/i686-unknown-linux-musl/Dockerfile b/ci/docker/i686-unknown-linux-musl/Dockerfile new file mode 100644 index 00000000..e742e299 --- /dev/null +++ b/ci/docker/i686-unknown-linux-musl/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:16.04 +RUN apt-get update +RUN apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + gcc-multilib \ + musl-tools +ENV CARGO_TARGET_I686_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc \ + CC_i686_unknown_linux_musl=musl-gcc diff --git a/ci/docker/x86_64-unknown-linux-gnu/Dockerfile b/ci/docker/x86_64-unknown-linux-gnu/Dockerfile index c6c44f1d..4438e1ec 100644 --- a/ci/docker/x86_64-unknown-linux-gnu/Dockerfile +++ b/ci/docker/x86_64-unknown-linux-gnu/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM ubuntu:12.04 RUN apt-get update RUN apt-get install -y --no-install-recommends \ ca-certificates \ diff --git a/ci/docker/x86_64-unknown-linux-musl/Dockerfile b/ci/docker/x86_64-unknown-linux-musl/Dockerfile new file mode 100644 index 00000000..b7fd2c2c --- /dev/null +++ b/ci/docker/x86_64-unknown-linux-musl/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:16.04 +RUN apt-get update +RUN apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + gcc \ + libc6-dev \ + musl-tools diff --git a/ci/install.ps1 b/ci/install.ps1 new file mode 100644 index 00000000..d889b45c --- /dev/null +++ b/ci/install.ps1 @@ -0,0 +1,26 @@ +$Env:HOST = $Env:TARGET + +If ($Env:TARGET -Match 'gnu') { + if ($Env:TARGET -Match 'x86_64') { + $Env:PATH += ';C:\msys64\mingw64\bin' + } else { + $Env:PATH += ';C:\msys64\mingw32\bin' + } +} ElseIf ($Env:TARGET -Match 'i586') { + $Env:HOST = 'i686-pc-windows-msvc' +} + +[Net.ServicePointManager]::SecurityProtocol = 'Ssl3, Tls, Tls12' +Start-FileDownload 'https://win.rustup.rs' 'rustup-init.exe' + +.\rustup-init --default-host $Env:HOST --default-toolchain $Env:RUST_VERSION -y + +$Env:PATH = 'C:\Users\appveyor\.cargo\bin;' + $Env:PATH + +If ($Env:TARGET -ne $Env:HOST) { + rustup target add $Env:TARGET +} + +rustc -Vv + +cargo -V diff --git a/ci/package.ps1 b/ci/package.ps1 new file mode 100644 index 00000000..0a55779f --- /dev/null +++ b/ci/package.ps1 @@ -0,0 +1,17 @@ +$SRC_DIR = $PWD.Path +$STAGE = [System.Guid]::NewGuid().ToString() + +Set-Location $ENV:Temp +New-Item -Type Directory -Name $STAGE +Set-Location $STAGE + +$ZIP = "$SRC_DIR\$($Env:CRATE_NAME)-$($Env:APPVEYOR_REPO_TAG_NAME)-$($Env:TARGET).zip" +Copy-Item "$SRC_DIR\target\$($Env:TARGET)\release\svd2rust.exe" '.\' +7z a "$ZIP" * + +Push-AppveyorArtifact "$ZIP" + +Remove-Item *.* -Force +Set-Location .. +Remove-Item $STAGE +Set-Location $SRC_DIR diff --git a/ci/package.sh b/ci/package.sh new file mode 100644 index 00000000..bfdababf --- /dev/null +++ b/ci/package.sh @@ -0,0 +1,27 @@ +set -ex + +run() { + local src_dir=$(pwd)\ + stage=$(mk_temp_dir) + + cp target/$TARGET/release/svd2rust $stage/ + + cd $stage + tar czf $src_dir/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz * + cd $src_dir + + rm -rf $stage +} + +mk_temp_dir() { + case $TRAVIS_OS_NAME in + linux) + mktemp -d + ;; + osx) + mktemp -d -t tmp + ;; + esac +} + +run diff --git a/ci/run-docker.sh b/ci/run-docker.sh index a739ca05..2fe831b7 100755 --- a/ci/run-docker.sh +++ b/ci/run-docker.sh @@ -1,28 +1,28 @@ set -ex run() { - local target=$1 - - echo $target - # This directory needs to exist before calling docker, otherwise docker will create it but it # will be owned by root mkdir -p target - docker build -t $target ci/docker/$target + docker build -t $1 ci/docker/$1 docker run \ --rm \ --user $(id -u):$(id -g) \ -e CARGO_HOME=/cargo \ -e CARGO_TARGET_DIR=/target \ - -e HOME=/tmp \ + -e TARGET=$1 \ + -e TRAVIS_OS_NAME=linux \ + -e TRAVIS_RUST_VERSION=$TRAVIS_RUST_VERSION \ + -e TRAVIS_TAG=$TRAVIS_TAG \ + -e USER=$USER \ -v $HOME/.cargo:/cargo \ -v `pwd`/target:/target \ -v `pwd`:/checkout:ro \ -v `rustc --print sysroot`:/rust:ro \ -w /checkout \ - -it $target \ - sh -c "PATH=\$PATH:/rust/bin ci/run.sh $target" + -it $1 \ + sh -c "HOME=/tmp PATH=\$PATH:/rust/bin ci/run.sh" } if [ -z $1 ]; then diff --git a/ci/run.sh b/ci/run.sh index 61ac9174..3da7dfd5 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -1,27 +1,25 @@ set -ex test_gen() { - echo 'extern crate volatile_register;' > /tmp/foo/src/lib.rs - cargo run --release -- -i /tmp/STM32F30x.svd $1 >> /tmp/foo/src/lib.rs - cargo build --manifest-path /tmp/foo/Cargo.toml + echo 'extern crate volatile_register;' > $td/src/lib.rs + cargo run $flags --release -- -i $td/STM32F30x.svd $1 >> $td/src/lib.rs + cargo build $flags --manifest-path $td/Cargo.toml } -main() { - export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib/rustlib/${1}/lib - export USER=rust +test_mode() { + # test crate + cargo init --name foo $td + echo 'volatile-register = "0.1.0"' >> $td/Cargo.toml curl -L \ - https://raw.githubusercontent.com/posborne/cmsis-svd/master/data/STMicro/STM32F30x.svd \ - > /tmp/STM32F30x.svd + https://raw.githubusercontent.com/posborne/cmsis-svd/python-0.4/data/STMicro/STM32F30x.svd \ + > $td/STM32F30x.svd # test the library - cargo build --release + cargo build $flags + cargo build $flags --release - # test repository - cargo new /tmp/foo - echo 'volatile-register = "0.1.0"' >> /tmp/foo/Cargo.toml - - # test generated code + # test the generated code test_gen test_gen dbgmcu test_gen gpioa @@ -31,4 +29,27 @@ main() { test_gen tim6 } -main $1 +deploy_mode() { + cargo rustc $flags --release --bin svd2rust -- -C lto +} + +run() { + flags="--target $TARGET" + + case $TRAVIS_OS_NAME in + linux) + td=$(mktemp -d) + ;; + osx) + td=$(mktemp -d -t tmp) + ;; + esac + + if [ -z $TRAVIS_TAG ]; then + test_mode + else + deploy_mode + fi +} + +run diff --git a/src/lib.rs b/src/lib.rs index fcb58462..7c946487 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(plugin)] #![recursion_limit="100"] extern crate inflections; diff --git a/src/main.rs b/src/main.rs index 90faded8..01dcf0b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ fn main() { .arg(Arg::with_name("peripheral") .help("Pattern used to select a single peripheral") .value_name("PATTERN")) - .version(include_str!(concat!(env!("OUT_DIR"), "/version.txt"))) + .version(env!("CARGO_PKG_VERSION")) .get_matches(); let xml = &mut String::new();