Merge branch 'ci/github-workflow'
This commit is contained in:
commit
cff4fa9484
|
@ -0,0 +1,84 @@
|
||||||
|
name: Tests
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: true
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- os: ubuntu-latest
|
||||||
|
target: x86_64-unknown-linux-gnu
|
||||||
|
toolchain: stable
|
||||||
|
- os: macos-latest
|
||||||
|
target: x86_64-apple-darwin
|
||||||
|
toolchain: stable
|
||||||
|
- os: windows-latest
|
||||||
|
target: x86_64-pc-windows-gnu
|
||||||
|
toolchain: stable
|
||||||
|
- os: windows-latest
|
||||||
|
target: x86_64-pc-windows-msvc
|
||||||
|
toolchain: beta
|
||||||
|
- os: ubuntu-latest
|
||||||
|
target: x86_64-unknown-linux-gnu
|
||||||
|
toolchain: 1.42.0 # MSRV
|
||||||
|
- os: ubuntu-latest
|
||||||
|
target: x86_64-unknown-linux-gnu
|
||||||
|
toolchain: nightly
|
||||||
|
- os: ubuntu-latest
|
||||||
|
deps: sudo apt install gcc-multilib
|
||||||
|
target: i686-unknown-linux-gnu
|
||||||
|
toolchain: nightly
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install toolchain
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
target: ${{ matrix.target }}
|
||||||
|
toolchain: ${{ matrix.toolchain }}
|
||||||
|
override: true
|
||||||
|
- run: ${{ matrix.deps }}
|
||||||
|
- name: Test sailfish
|
||||||
|
run: |
|
||||||
|
cargo test --target ${{ matrix.target }} --manifest-path sailfish/Cargo.toml --no-default-features
|
||||||
|
cargo test --target ${{ matrix.target }} --manifest-path sailfish/Cargo.toml --all-features
|
||||||
|
- name: Test sailfish-compiler
|
||||||
|
run: |
|
||||||
|
cargo test --target ${{ matrix.target }} --manifest-path sailfish-compiler/Cargo.toml
|
||||||
|
- name: Integration tests
|
||||||
|
# Currently integration tests have some issue related to line feeds
|
||||||
|
if: ${{ matrix.os != 'windows-latest' }}
|
||||||
|
run: |
|
||||||
|
cargo test --target ${{ matrix.target }} --manifest-path sailfish-tests/integration-tests/Cargo.toml
|
||||||
|
|
||||||
|
test-miri:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install toolchain
|
||||||
|
run: |
|
||||||
|
MIRI_NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)
|
||||||
|
rustup default "$MIRI_NIGHTLY"
|
||||||
|
rustup component add miri
|
||||||
|
- name: Test sailfish
|
||||||
|
run: |
|
||||||
|
cargo miri test --manifest-path sailfish/Cargo.toml --no-default-features
|
||||||
|
cargo miri test --manifest-path sailfish/Cargo.toml --all-features
|
||||||
|
|
||||||
|
test-ios:
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Install toolchain
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: nightly
|
||||||
|
target: aarch64-apple-ios
|
||||||
|
override: true
|
||||||
|
- name: Build only
|
||||||
|
run: cargo build --target=aarch64-apple-ios --workspace
|
29
.travis.yml
29
.travis.yml
|
@ -1,29 +0,0 @@
|
||||||
dist: bionic
|
|
||||||
language: rust
|
|
||||||
|
|
||||||
branches:
|
|
||||||
except:
|
|
||||||
- stable
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
fast_finish: true
|
|
||||||
include:
|
|
||||||
- os: linux
|
|
||||||
rust: stable
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
rust: nightly
|
|
||||||
|
|
||||||
# minimum supported version
|
|
||||||
- os: linux
|
|
||||||
rust: 1.42.0
|
|
||||||
|
|
||||||
- os: osx
|
|
||||||
rust: stable
|
|
||||||
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- RUST_BACKTRACE=1
|
|
||||||
|
|
||||||
script:
|
|
||||||
- bash ./scripts/travis.sh
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
Simple, small, and extremely fast template engine for Rust
|
Simple, small, and extremely fast template engine for Rust
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/Kogia-sima/sailfish.svg?branch=master)](https://travis-ci.org/Kogia-sima/sailfish)
|
[![Tests](https://github.com/Kogia-sima/sailfish/workflows/Tests/badge.svg)](https://github.com/Kogia-sima/sailfish/actions?query=workflow%3ATests)
|
||||||
[![Build status](https://ci.appveyor.com/api/projects/status/fa3et4rft4dyvdn9/branch/master?svg=true)](https://ci.appveyor.com/project/Kogiasima/sailfish/branch/master)
|
|
||||||
[![Version](https://img.shields.io/crates/v/sailfish)](https://crates.io/crates/sailfish)
|
[![Version](https://img.shields.io/crates/v/sailfish)](https://crates.io/crates/sailfish)
|
||||||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Kogia-sima/sailfish/blob/master/LICENSE)
|
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Kogia-sima/sailfish/blob/master/LICENSE)
|
||||||
|
|
||||||
|
|
28
appveyor.yml
28
appveyor.yml
|
@ -1,28 +0,0 @@
|
||||||
platform:
|
|
||||||
- x64
|
|
||||||
|
|
||||||
environment:
|
|
||||||
matrix:
|
|
||||||
- RUST_VERSION: stable
|
|
||||||
PLATFORM_TARGET: x86_64
|
|
||||||
PLATFORM_VS: x64
|
|
||||||
|
|
||||||
install:
|
|
||||||
# Install Rust.
|
|
||||||
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
|
|
||||||
- rustup-init.exe -yv --default-toolchain %RUST_VERSION% --default-host x86_64-pc-windows-msvc
|
|
||||||
- set PATH=%USERPROFILE%\.cargo\bin;%PATH%
|
|
||||||
- rustc -vV
|
|
||||||
- cargo -vV
|
|
||||||
|
|
||||||
build_script:
|
|
||||||
- cargo build --all-features -p sailfish -p sailfish-compiler
|
|
||||||
|
|
||||||
test_script:
|
|
||||||
- cargo test --all-features -p sailfish -p sailfish-compiler -p integration-tests
|
|
||||||
|
|
||||||
notifications:
|
|
||||||
- provider: Email
|
|
||||||
on_build_success: false
|
|
||||||
on_build_failure: false
|
|
||||||
on_build_status_changed: false
|
|
|
@ -2,20 +2,8 @@
|
||||||
//!
|
//!
|
||||||
//! By default sailfish replaces the characters `&"'<>` with the equivalent html.
|
//! By default sailfish replaces the characters `&"'<>` with the equivalent html.
|
||||||
|
|
||||||
#![cfg_attr(target_feature = "avx2", allow(dead_code))]
|
|
||||||
|
|
||||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
|
||||||
mod avx2;
|
|
||||||
mod fallback;
|
mod fallback;
|
||||||
mod naive;
|
mod naive;
|
||||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
|
||||||
mod sse2;
|
|
||||||
|
|
||||||
use std::sync::atomic::{AtomicPtr, Ordering};
|
|
||||||
|
|
||||||
use super::buffer::Buffer;
|
|
||||||
|
|
||||||
type FnRaw = *mut ();
|
|
||||||
|
|
||||||
static ESCAPE_LUT: [u8; 256] = [
|
static ESCAPE_LUT: [u8; 256] = [
|
||||||
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
||||||
|
@ -33,11 +21,20 @@ static ESCAPE_LUT: [u8; 256] = [
|
||||||
const ESCAPED: [&str; 5] = [""", "&", "'", "<", ">"];
|
const ESCAPED: [&str; 5] = [""", "&", "'", "<", ">"];
|
||||||
const ESCAPED_LEN: usize = 5;
|
const ESCAPED_LEN: usize = 5;
|
||||||
|
|
||||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), not(miri)))]
|
||||||
static FN: AtomicPtr<()> = AtomicPtr::new(escape as FnRaw);
|
macro_rules! generate_impl {
|
||||||
|
() => {
|
||||||
|
mod avx2;
|
||||||
|
mod sse2;
|
||||||
|
|
||||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
use super::buffer::Buffer;
|
||||||
fn escape(feed: &str, buf: &mut Buffer) {
|
use std::sync::atomic::{AtomicPtr, Ordering};
|
||||||
|
|
||||||
|
type FnRaw = *mut ();
|
||||||
|
|
||||||
|
static FN: AtomicPtr<()> = AtomicPtr::new(escape as FnRaw);
|
||||||
|
|
||||||
|
fn escape(feed: &str, buf: &mut Buffer) {
|
||||||
debug_assert!(feed.len() >= 16);
|
debug_assert!(feed.len() >= 16);
|
||||||
let fun = if is_x86_feature_detected!("avx2") {
|
let fun = if is_x86_feature_detected!("avx2") {
|
||||||
avx2::escape
|
avx2::escape
|
||||||
|
@ -49,39 +46,52 @@ fn escape(feed: &str, buf: &mut Buffer) {
|
||||||
|
|
||||||
FN.store(fun as FnRaw, Ordering::Relaxed);
|
FN.store(fun as FnRaw, Ordering::Relaxed);
|
||||||
unsafe { fun(feed, buf) };
|
unsafe { fun(feed, buf) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// write the escaped contents into `Buffer`
|
/// write the escaped contents into `Buffer`
|
||||||
#[cfg_attr(feature = "perf-inline", inline)]
|
#[cfg_attr(feature = "perf-inline", inline)]
|
||||||
pub fn escape_to_buf(feed: &str, buf: &mut Buffer) {
|
pub fn escape_to_buf(feed: &str, buf: &mut Buffer) {
|
||||||
unsafe {
|
unsafe {
|
||||||
if feed.len() < 16 {
|
if feed.len() < 16 {
|
||||||
buf.reserve_small(feed.len() * 6);
|
buf.reserve_small(feed.len() * 6);
|
||||||
let l = naive::escape_small(feed, buf.as_mut_ptr().add(buf.len()));
|
let l = naive::escape_small(feed, buf.as_mut_ptr().add(buf.len()));
|
||||||
buf.advance(l);
|
buf.advance(l);
|
||||||
} else {
|
} else if cfg!(target_feature = "avx2") {
|
||||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
|
||||||
{
|
|
||||||
#[cfg(target_feature = "avx2")]
|
|
||||||
{
|
|
||||||
avx2::escape(feed, buf);
|
avx2::escape(feed, buf);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
#[cfg(not(target_feature = "avx2"))]
|
|
||||||
{
|
|
||||||
let fun = FN.load(Ordering::Relaxed);
|
let fun = FN.load(Ordering::Relaxed);
|
||||||
std::mem::transmute::<FnRaw, fn(&str, &mut Buffer)>(fun)(feed, buf);
|
std::mem::transmute::<FnRaw, fn(&str, &mut Buffer)>(fun)(feed, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
|
||||||
{
|
|
||||||
fallback::escape(feed, buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(all(any(target_arch = "x86", target_arch = "x86_64"), not(miri))))]
|
||||||
|
macro_rules! generate_impl {
|
||||||
|
() => {
|
||||||
|
use super::buffer::Buffer;
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "perf-inline", inline)]
|
||||||
|
pub fn escape_to_buf(feed: &str, buf: &mut Buffer) {
|
||||||
|
unsafe {
|
||||||
|
if cfg!(miri) {
|
||||||
|
let bp = feed.as_ptr();
|
||||||
|
naive::escape(buf, bp, bp, bp.add(feed.len()))
|
||||||
|
} else if feed.len() < 16 {
|
||||||
|
buf.reserve_small(feed.len() * 6);
|
||||||
|
let l = naive::escape_small(feed, buf.as_mut_ptr().add(buf.len()));
|
||||||
|
buf.advance(l);
|
||||||
|
} else {
|
||||||
|
fallback::escape(feed, buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_impl!();
|
||||||
|
|
||||||
/// write the escaped contents into `String`
|
/// write the escaped contents into `String`
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
@ -153,6 +163,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(not(miri))]
|
||||||
fn random() {
|
fn random() {
|
||||||
const ASCII_CHARS: &'static [u8] = br##"abcdefghijklmnopqrstuvwxyz0123456789-^\@[;:],./\!"#$%&'()~=~|`{+*}<>?_"##;
|
const ASCII_CHARS: &'static [u8] = br##"abcdefghijklmnopqrstuvwxyz0123456789-^\@[;:],./\!"#$%&'()~=~|`{+*}<>?_"##;
|
||||||
let mut state = 88172645463325252u64;
|
let mut state = 88172645463325252u64;
|
||||||
|
@ -184,11 +195,12 @@ mod tests {
|
||||||
s.as_ptr().add(s.len()),
|
s.as_ptr().add(s.len()),
|
||||||
);
|
);
|
||||||
|
|
||||||
dbg!(s);
|
|
||||||
fallback::escape(s, &mut buf);
|
fallback::escape(s, &mut buf);
|
||||||
assert_eq!(buf.as_str(), buf_naive.as_str());
|
assert_eq!(buf.as_str(), buf_naive.as_str());
|
||||||
buf.clear();
|
buf.clear();
|
||||||
|
|
||||||
|
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||||
|
{
|
||||||
if is_x86_feature_detected!("sse2") {
|
if is_x86_feature_detected!("sse2") {
|
||||||
sse2::escape(s, &mut buf);
|
sse2::escape(s, &mut buf);
|
||||||
assert_eq!(buf.as_str(), buf_naive.as_str());
|
assert_eq!(buf.as_str(), buf_naive.as_str());
|
||||||
|
@ -201,6 +213,7 @@ mod tests {
|
||||||
buf.clear();
|
buf.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buf_naive.clear();
|
buf_naive.clear();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue