Skip to content

Commit 5bc109a

Browse files
authored
Support no_std (apache#332)
* Support `no_std` Signed-off-by: koushiro <[email protected]> * Fix typo Signed-off-by: koushiro <[email protected]>
1 parent 293133f commit 5bc109a

File tree

13 files changed

+71
-14
lines changed

13 files changed

+71
-14
lines changed

.github/workflows/rust.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ jobs:
3535
- uses: actions/checkout@master
3636
- run: cargo check --all-targets --all-features
3737

38+
compile-no-std:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Set up Rust
42+
uses: hecrj/setup-rust-action@v1
43+
with:
44+
targets: 'thumbv6m-none-eabi'
45+
- uses: actions/checkout@master
46+
- run: cargo check --no-default-features --target thumbv6m-none-eabi
47+
3848
test:
3949
strategy:
4050
matrix:

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ include = [
1313
"Cargo.toml",
1414
]
1515
edition = "2018"
16+
resolver = "2"
1617

1718
[lib]
1819
name = "sqlparser"
1920
path = "src/lib.rs"
2021

2122
[features]
23+
default = ["std"]
24+
std = []
2225
# Enable JSON output in the `cli` example:
2326
json_example = ["serde_json", "serde"]
2427

src/ast/data_type.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
// See the License for the specific language governing permissions and
1111
// limitations under the License.
1212

13-
use std::fmt;
13+
#[cfg(not(feature = "std"))]
14+
use alloc::boxed::Box;
15+
use core::fmt;
1416

1517
#[cfg(feature = "serde")]
1618
use serde::{Deserialize, Serialize};

src/ast/ddl.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
//! AST types specific to CREATE/ALTER variants of [Statement]
1414
//! (commonly referred to as Data Definition Language, or DDL)
1515
16-
use std::fmt;
16+
#[cfg(not(feature = "std"))]
17+
use alloc::{boxed::Box, string::ToString, vec::Vec};
18+
use core::fmt;
1719

1820
#[cfg(feature = "serde")]
1921
use serde::{Deserialize, Serialize};

src/ast/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ mod operator;
1818
mod query;
1919
mod value;
2020

21-
use std::fmt;
21+
#[cfg(not(feature = "std"))]
22+
use alloc::{
23+
boxed::Box,
24+
string::{String, ToString},
25+
vec::Vec,
26+
};
27+
use core::fmt;
2228

2329
#[cfg(feature = "serde")]
2430
use serde::{Deserialize, Serialize};

src/ast/operator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// See the License for the specific language governing permissions and
1111
// limitations under the License.
1212

13-
use std::fmt;
13+
use core::fmt;
1414

1515
#[cfg(feature = "serde")]
1616
use serde::{Deserialize, Serialize};

src/ast/query.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
// See the License for the specific language governing permissions and
1111
// limitations under the License.
1212

13+
#[cfg(not(feature = "std"))]
14+
use alloc::{boxed::Box, vec::Vec};
15+
1316
#[cfg(feature = "serde")]
1417
use serde::{Deserialize, Serialize};
1518

src/ast/value.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
// See the License for the specific language governing permissions and
1111
// limitations under the License.
1212

13-
use std::fmt;
13+
#[cfg(not(feature = "std"))]
14+
use alloc::string::String;
15+
use core::fmt;
1416

1517
#[cfg(feature = "bigdecimal")]
1618
use bigdecimal::BigDecimal;

src/dialect/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ mod postgresql;
2020
mod snowflake;
2121
mod sqlite;
2222

23-
use std::any::{Any, TypeId};
24-
use std::fmt::Debug;
23+
use core::any::{Any, TypeId};
24+
use core::fmt::Debug;
2525

2626
pub use self::ansi::AnsiDialect;
2727
pub use self::generic::GenericDialect;

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@
3232
//!
3333
//! println!("AST: {:?}", ast);
3434
//! ```
35+
36+
#![cfg_attr(not(feature = "std"), no_std)]
3537
#![allow(clippy::upper_case_acronyms)]
3638

39+
#[cfg(not(feature = "std"))]
40+
extern crate alloc;
41+
3742
pub mod ast;
3843
#[macro_use]
3944
pub mod dialect;

0 commit comments

Comments
 (0)