Skip to content

Extend Travis build matrix, patch SDL2 2.0.8 #797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 28 additions & 38 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
language: rust
sudo: required
rust:
- beta
- nightly
- stable
- beta
- nightly
- stable
os:
- linux
- osx
- linux
- osx
env:
matrix:
- CI_BUILD_FEATURES="bundled"
- CI_BUILD_FEATURES="gfx image ttf mixer"
global:
- RUST_TEST_THREADS=1
- TRAVIS_CARGO_NIGHTLY_FEATURE=""
- LD_LIBRARY_PATH: "/usr/local/lib"
- secure: MJhmVnQ2IM7+sVmc3vU4ndKOcQgLLeHUPW3qaQBQHKQmvoswCwQK60N17uSgWn1Ln8teqvSRHq4KclIjdMHI+VuQXJHQKHDgjcYbHxwmc3AM1Whnp0XB44ksKUmD109BGWSfZQxzF+6dA+YNOQ+mti+bpydMu8n2FMVjA/SXwQ8=

install:
- wget https://www.libsdl.org/release/SDL2-2.0.8.tar.gz -O sdl2.tar.gz
- tar xzf sdl2.tar.gz
- pushd SDL2-* && ./configure && make && sudo make install && popd
- wget -q https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.tar.gz
- wget -q https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.1.tar.gz
- wget -q https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.2.tar.gz
- wget -q -O SDL2_gfx-1.0.1.tar.gz https://sourceforge.net/projects/sdl2gfx/files/SDL2_gfx-1.0.1.tar.gz/download
- tar xzf SDL2_ttf-*.tar.gz
- tar xzf SDL2_image-*.tar.gz
- tar xzf SDL2_mixer-*.tar.gz
- tar xzf SDL2_gfx-*.tar.gz
- pushd SDL2_ttf-* && ./configure && make && sudo make install && popd
- pushd SDL2_image-* && ./configure && make && sudo make install && popd
- pushd SDL2_mixer-* && ./configure && make && sudo make install && popd
- pushd SDL2_gfx-* && ./autogen.sh && ./configure && make && sudo make install && popd
- if [[ $CI_BUILD_FEATURES != *"bundled"* ]]; then bash scripts/travis-install-sdl2.sh; fi

before_script:
- shopt -s expand_aliases
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then alias pip=pip2; fi
- |
pip install 'travis-cargo<0.2' --user &&
export PATH=$HOME/.local/bin:$PATH &&
export PATH=~/Library/Python/2.7/bin:$PATH
- shopt -s expand_aliases
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then alias pip=pip2; fi
- |
pip install 'travis-cargo<0.2' --user &&
export PATH=$HOME/.local/bin:$PATH &&
export PATH=~/Library/Python/2.7/bin:$PATH
script:
- |
travis-cargo build -- --features "gfx image ttf mixer" &&
travis-cargo build -- --examples --features "gfx image ttf mixer" &&
travis-cargo test -- --features "gfx image ttf mixer" &&
travis-cargo --only stable doc -- --features "gfx image ttf mixer"
- |
travis-cargo build -- --features "${CI_BUILD_FEATURES}" &&
travis-cargo build -- --examples --features "${CI_BUILD_FEATURES}" &&
travis-cargo test -- --features "${CI_BUILD_FEATURES}" &&
travis-cargo --only stable doc -- --features "${CI_BUILD_FEATURES}"
after_success:
- travis-cargo --only stable doc-upload
env:
global:
- RUST_TEST_THREADS=1
- TRAVIS_CARGO_NIGHTLY_FEATURE=""
- LD_LIBRARY_PATH: "/usr/local/lib"
- secure: MJhmVnQ2IM7+sVmc3vU4ndKOcQgLLeHUPW3qaQBQHKQmvoswCwQK60N17uSgWn1Ln8teqvSRHq4KclIjdMHI+VuQXJHQKHDgjcYbHxwmc3AM1Whnp0XB44ksKUmD109BGWSfZQxzF+6dA+YNOQ+mti+bpydMu8n2FMVjA/SXwQ8=
- travis-cargo --only stable doc-upload
19 changes: 19 additions & 0 deletions scripts/travis-install-sdl2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -xueo pipefail

wget https://www.libsdl.org/release/SDL2-2.0.8.tar.gz -O sdl2.tar.gz
tar xzf sdl2.tar.gz
pushd SDL2-* && ./configure && make && sudo make install && popd
wget -q https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.tar.gz
wget -q https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.1.tar.gz
wget -q https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.2.tar.gz
wget -q -O SDL2_gfx-1.0.1.tar.gz https://sourceforge.net/projects/sdl2gfx/files/SDL2_gfx-1.0.1.tar.gz/download
tar xzf SDL2_ttf-*.tar.gz
tar xzf SDL2_image-*.tar.gz
tar xzf SDL2_mixer-*.tar.gz
tar xzf SDL2_gfx-*.tar.gz
pushd SDL2_ttf-* && ./configure && make && sudo make install && popd
pushd SDL2_image-* && ./configure && make && sudo make install && popd
pushd SDL2_mixer-* && ./configure && make && sudo make install && popd
pushd SDL2_gfx-* && ./autogen.sh && ./configure && make && sudo make install && popd
6 changes: 5 additions & 1 deletion sdl2-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ optional = true
version = "0.2"
optional = true

[build-dependencies.unidiff]
version = "0.2.1"
optional = true

[build-dependencies]
cfg-if = "0.1"

Expand All @@ -49,7 +53,7 @@ use-pkgconfig = ["pkg-config"]
use-bindgen = ["bindgen"]
static-link = []
use_mac_framework = []
bundled = ["cmake", "reqwest", "tar", "flate2"]
bundled = ["cmake", "reqwest", "tar", "flate2", "unidiff"]
mixer = []
image = []
ttf = []
Expand Down
123 changes: 123 additions & 0 deletions sdl2-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ extern crate tar;
extern crate flate2;
#[cfg(feature="bundled")]
extern crate reqwest;
#[cfg(feature="bundled")]
extern crate unidiff;

#[macro_use]
extern crate cfg_if;
Expand Down Expand Up @@ -112,6 +114,126 @@ fn download_sdl2() -> PathBuf {
sdl2_build_path
}

// apply patches to sdl2 source
#[cfg(feature = "bundled")]
fn patch_sdl2(sdl2_source_path: &Path) {
// vector of <(patch_file_name, patch_file_contents)>
let patches: Vec<(&str, &'static str)> = vec![
// This patch fixes a CMake installation bug introduced in SDL2 2.0.4 on
// the Mac OS platform. Without this patch, the libSDL2.dylib generated
// during the SDL2 build phase will be overwritten by a symlink pointing
// to nothing. A variation of this patch was accepted upstream and
// should be included in SDL2 2.0.9.
// https://bugzilla.libsdl.org/show_bug.cgi?id=4234
("SDL2-2.0.8-4234-mac-os-dylib-fix.patch", include_str!("patches/SDL2-2.0.8-4234-mac-os-dylib-fix.patch")),
];
let sdl_version = format!("SDL2-{}", LASTEST_SDL2_VERSION);

for patch in &patches {
// Only apply patches whose file name is prefixed with the currently
// targeted version of SDL2.
if !patch.0.starts_with(&sdl_version) {
continue;
}
let mut patch_set = unidiff::PatchSet::new();
patch_set.parse(patch.1).expect("Error parsing diff");

// For every modified file, copy the existing file to <file_name>_old,
// open a new copy of <file_name>. and fill the new file with a
// combination of the unmodified contents, and the patched sections.
// TOOD: This code is untested (save for the immediate application), and
// probably belongs in the unidiff (or similar) package.
for modified_file in patch_set.modified_files() {
use std::io::{Write, BufRead};

let file_path = sdl2_source_path.join(modified_file.path());
let old_path = sdl2_source_path.join(format!("{}_old", modified_file.path()));
fs::rename(&file_path, &old_path)
.expect(&format!(
"Rename of {} to {} failed",
file_path.to_string_lossy(),
old_path.to_string_lossy()));

let dst_file = fs::File::create(file_path).unwrap();
let mut dst_buf = io::BufWriter::new(dst_file);
let old_file = fs::File::open(old_path).unwrap();
let mut old_buf = io::BufReader::new(old_file);
let mut cursor = 0;

for (i, hunk) in modified_file.into_iter().enumerate() {
// Write old lines from cursor to the start of this hunk.
let num_lines = hunk.source_start - cursor - 1;
for _ in 0..num_lines {
let mut line = String::new();
old_buf.read_line(&mut line).unwrap();
dst_buf.write_all(line.as_bytes()).unwrap();
}
cursor += num_lines;

// Skip lines in old_file, and verify that what we expect to
// replace is present in the old_file.
for expected_line in hunk.source_lines() {
let mut actual_line = String::new();
old_buf.read_line(&mut actual_line).unwrap();
actual_line.pop(); // Remove the trailing newline.
if expected_line.value != actual_line {
panic!("Can't apply patch; mismatch between expected and actual in hunk {}", i);
}
}
cursor += hunk.source_length;

// Write the new lines into the destination.
for line in hunk.target_lines() {
dst_buf.write_all(line.value.as_bytes()).unwrap();
dst_buf.write_all(b"\n").unwrap();
}
}

// Write all remaining lines from the old file into the new.
for line in old_buf.lines() {
dst_buf.write_all(&line.unwrap().into_bytes()).unwrap();
dst_buf.write_all(b"\n").unwrap();
}
}
// For every removed file, simply delete the original.
// TODO: This is entirely untested code. There are likely bugs here, and
// this really should be part of the unidiff library, not a function
// defined here. Hopefully this gets moved somewhere else before it
// bites someone.
for removed_file in patch_set.removed_files() {
fs::remove_file(sdl2_source_path.join(removed_file.path()))
.expect(
&format!("Failed to remove file {} from {}",
removed_file.path(),
sdl2_source_path.to_string_lossy()));
}
// For every new file, copy the entire contents of the patched file into
// a newly created <file_name>.
// TODO: This is entirely untested code. There are likely bugs here, and
// this really should be part of the unidiff library, not a function
// defined here. Hopefully this gets moved somewhere else before it
// bites someone.
for added_file in patch_set.added_files() {
use std::io::Write;

// This should be superfluous. I don't know how a new file would
// ever have more than one hunk.
assert!(added_file.len() == 1);
let file_path = sdl2_source_path.join(added_file.path());
let mut dst_file = fs::File::create(&file_path)
.expect(&format!(
"Failed to create file {}",
file_path.to_string_lossy()));
let mut dst_buf = io::BufWriter::new(&dst_file);

for line in added_file.into_iter().nth(0).unwrap().target_lines() {
dst_buf.write_all(line.value.as_bytes()).unwrap();
dst_buf.write_all(b"\n").unwrap();
}
}
}
}

// compile a shared or static lib depending on the feature
#[cfg(feature = "bundled")]
fn compile_sdl2(sdl2_build_path: &Path, target_os: &str) -> PathBuf {
Expand Down Expand Up @@ -333,6 +455,7 @@ fn main() {
let sdl2_compiled_path: PathBuf;
#[cfg(feature = "bundled")] {
let sdl2_source_path = download_sdl2();
patch_sdl2(sdl2_source_path.as_path());
sdl2_compiled_path = compile_sdl2(sdl2_source_path.as_path(), target_os);

let sdl2_downloaded_include_path = sdl2_source_path.join("include");
Expand Down
44 changes: 44 additions & 0 deletions sdl2-sys/patches/SDL2-2.0.8-4234-mac-os-dylib-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# HG changeset patch
# User Drew Pirrone-Brusse <[email protected]>
# Date 1537744393 14400
# Sun Sep 23 19:13:13 2018 -0400
# Node ID b66fb83b6897137c1c2b857ee5490e602f8c31b0
# Parent f1084c419f33610cf274e309a8b2798d2ae665c7
Correct the name of the SDL shared library in CMake for Mac OS

diff -r f1084c419f33 -r b66fb83b6897 CMakeLists.txt
--- a/CMakeLists.txt Thu Mar 01 08:26:10 2018 -0800
+++ b/CMakeLists.txt Sun Sep 23 19:13:13 2018 -0400
@@ -1704,7 +1704,9 @@
if(SDL_SHARED)
add_library(SDL2 SHARED ${SOURCE_FILES} ${VERSION_SOURCES})
if(APPLE)
- set_target_properties(SDL2 PROPERTIES MACOSX_RPATH 1)
+ set_target_properties(SDL2 PROPERTIES
+ MACOSX_RPATH 1
+ OUTPUT_NAME "SDL2-${LT_RELEASE}")
elseif(UNIX AND NOT ANDROID)
set_target_properties(SDL2 PROPERTIES
VERSION ${LT_VERSION}
@@ -1810,16 +1812,14 @@

if(NOT (WINDOWS OR CYGWIN))
if(SDL_SHARED)
- if (APPLE)
- set(SOEXT "dylib")
- else()
- set(SOEXT "so")
- endif()
+ set(SOEXT ${CMAKE_SHARED_LIBRARY_SUFFIX}) # ".so", ".dylib", etc.
+ get_target_property(SONAME SDL2 OUTPUT_NAME)
if(NOT ANDROID)
install(CODE "
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
- \"libSDL2-2.0.${SOEXT}\" \"libSDL2.${SOEXT}\")")
- install(FILES ${SDL2_BINARY_DIR}/libSDL2.${SOEXT} DESTINATION "lib${LIB_SUFFIX}")
+ \"lib${SONAME}${SOPOSTFIX}${SOEXT}\" \"libSDL2${SOPOSTFIX}${SOEXT}\")"
+ WORKING_DIR "${SDL2_BINARY_DIR}")
+ install(FILES ${SDL2_BINARY_DIR}/libSDL2${SOPOSTFIX}${SOEXT} DESTINATION "lib${LIB_SUFFIX}")
endif()
endif()
if(FREEBSD)
2 changes: 1 addition & 1 deletion src/sdl2/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ mod test {
assert!(cvt.is_conversion_needed());

// since we're going from mono to stereo, our capacity must be at least twice the original (255) vec size
assert!(cvt.capacity(255) > 255*2, "capacity must be able to hold the converted audio sample");
assert!(cvt.capacity(255) >= 255*2, "capacity must be able to hold the converted audio sample");

let new_buffer = cvt.convert(buffer);
assert_eq!(new_buffer.len(), new_buffer_expected.len(), "capacity must be exactly equal to twice the original vec size");
Expand Down