Support no_std (#332)

* Support `no_std`

Signed-off-by: koushiro <koushiro.cqx@gmail.com>

* Fix typo

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
This commit is contained in:
Qinxuan Chen 2021-08-21 16:15:43 +08:00 committed by GitHub
parent 293133f910
commit 5bc109a7ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 71 additions and 14 deletions

View file

@ -35,6 +35,16 @@ jobs:
- uses: actions/checkout@master - uses: actions/checkout@master
- run: cargo check --all-targets --all-features - run: cargo check --all-targets --all-features
compile-no-std:
runs-on: ubuntu-latest
steps:
- name: Set up Rust
uses: hecrj/setup-rust-action@v1
with:
targets: 'thumbv6m-none-eabi'
- uses: actions/checkout@master
- run: cargo check --no-default-features --target thumbv6m-none-eabi
test: test:
strategy: strategy:
matrix: matrix:

View file

@ -13,12 +13,15 @@ include = [
"Cargo.toml", "Cargo.toml",
] ]
edition = "2018" edition = "2018"
resolver = "2"
[lib] [lib]
name = "sqlparser" name = "sqlparser"
path = "src/lib.rs" path = "src/lib.rs"
[features] [features]
default = ["std"]
std = []
# Enable JSON output in the `cli` example: # Enable JSON output in the `cli` example:
json_example = ["serde_json", "serde"] json_example = ["serde_json", "serde"]

View file

@ -10,7 +10,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::fmt; #[cfg(not(feature = "std"))]
use alloc::boxed::Box;
use core::fmt;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -13,7 +13,9 @@
//! AST types specific to CREATE/ALTER variants of [Statement] //! AST types specific to CREATE/ALTER variants of [Statement]
//! (commonly referred to as Data Definition Language, or DDL) //! (commonly referred to as Data Definition Language, or DDL)
use std::fmt; #[cfg(not(feature = "std"))]
use alloc::{boxed::Box, string::ToString, vec::Vec};
use core::fmt;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -18,7 +18,13 @@ mod operator;
mod query; mod query;
mod value; mod value;
use std::fmt; #[cfg(not(feature = "std"))]
use alloc::{
boxed::Box,
string::{String, ToString},
vec::Vec,
};
use core::fmt;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -10,7 +10,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::fmt; use core::fmt;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -10,6 +10,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, vec::Vec};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -10,7 +10,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::fmt; #[cfg(not(feature = "std"))]
use alloc::string::String;
use core::fmt;
#[cfg(feature = "bigdecimal")] #[cfg(feature = "bigdecimal")]
use bigdecimal::BigDecimal; use bigdecimal::BigDecimal;

View file

@ -20,8 +20,8 @@ mod postgresql;
mod snowflake; mod snowflake;
mod sqlite; mod sqlite;
use std::any::{Any, TypeId}; use core::any::{Any, TypeId};
use std::fmt::Debug; use core::fmt::Debug;
pub use self::ansi::AnsiDialect; pub use self::ansi::AnsiDialect;
pub use self::generic::GenericDialect; pub use self::generic::GenericDialect;

View file

@ -32,8 +32,13 @@
//! //!
//! println!("AST: {:?}", ast); //! println!("AST: {:?}", ast);
//! ``` //! ```
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::upper_case_acronyms)] #![allow(clippy::upper_case_acronyms)]
#[cfg(not(feature = "std"))]
extern crate alloc;
pub mod ast; pub mod ast;
#[macro_use] #[macro_use]
pub mod dialect; pub mod dialect;

View file

@ -12,8 +12,15 @@
//! SQL Parser //! SQL Parser
use std::error::Error; #[cfg(not(feature = "std"))]
use std::fmt; use alloc::{
boxed::Box,
format,
string::{String, ToString},
vec,
vec::Vec,
};
use core::fmt;
use log::debug; use log::debug;
@ -81,7 +88,8 @@ impl fmt::Display for ParserError {
} }
} }
impl Error for ParserError {} #[cfg(feature = "std")]
impl std::error::Error for ParserError {}
pub struct Parser<'a> { pub struct Parser<'a> {
tokens: Vec<Token>, tokens: Vec<Token>,

View file

@ -16,7 +16,15 @@
// //
// Integration tests (i.e. everything under `tests/`) import this // Integration tests (i.e. everything under `tests/`) import this
// via `tests/test_utils/mod.rs`. // via `tests/test_utils/mod.rs`.
use std::fmt::Debug;
#[cfg(not(feature = "std"))]
use alloc::{
boxed::Box,
string::{String, ToString},
vec,
vec::Vec,
};
use core::fmt::Debug;
use crate::ast::*; use crate::ast::*;
use crate::dialect::*; use crate::dialect::*;

View file

@ -16,9 +16,17 @@
//! //!
//! The tokens then form the input for the parser, which outputs an Abstract Syntax Tree (AST). //! The tokens then form the input for the parser, which outputs an Abstract Syntax Tree (AST).
use std::fmt; #[cfg(not(feature = "std"))]
use std::iter::Peekable; use alloc::{
use std::str::Chars; borrow::ToOwned,
format,
string::{String, ToString},
vec,
vec::Vec,
};
use core::fmt;
use core::iter::Peekable;
use core::str::Chars;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};