Skip to content

Commit a925a30

Browse files
committed
WIP add support for building in "decoupled" mode
TODO: reintroduce monomorphization
1 parent c285e28 commit a925a30

File tree

23 files changed

+596
-376
lines changed

23 files changed

+596
-376
lines changed

Cargo.lock

Lines changed: 71 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ default = [ "macros", "runtime-async-std" ]
3939
macros = [ "sqlx-macros" ]
4040
tls = [ "sqlx-core/tls" ]
4141

42+
# offline building support in `sqlx-macros`
43+
offline = ["sqlx-macros/offline"]
44+
4245
# intended mainly for CI and docs
4346
all = [ "tls", "all-database", "all-type" ]
4447
all-database = [ "mysql", "sqlite", "postgres" ]

sqlx-core/src/describe.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::database::Database;
77
/// The return type of [`Executor::describe`].
88
///
99
/// [`Executor::describe`]: crate::executor::Executor::describe
10+
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
1011
#[non_exhaustive]
1112
pub struct Describe<DB>
1213
where
@@ -35,6 +36,7 @@ where
3536
}
3637

3738
/// A single column of a result set.
39+
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
3840
#[non_exhaustive]
3941
pub struct Column<DB>
4042
where

sqlx-core/src/mysql/protocol/type.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// https://dev.mysql.com/doc/dev/mysql-server/8.0.12/binary__log__types_8h.html
22
// https://mariadb.com/kb/en/library/resultset/#field-types
33
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4+
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
45
pub struct TypeId(pub u8);
56

67
// https://github.com/google/mysql/blob/c01fc2134d439282a21a2ddf687566e198ddee28/include/mysql_com.h#L429

sqlx-core/src/mysql/type_info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::mysql::protocol::{ColumnDefinition, FieldFlags, TypeId};
44
use crate::types::TypeInfo;
55

66
#[derive(Clone, Debug, Default)]
7+
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
78
pub struct MySqlTypeInfo {
89
pub(crate) id: TypeId,
910
pub(crate) is_unsigned: bool,

sqlx-core/src/postgres/protocol/type_id.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::postgres::types::try_resolve_type_name;
22
use std::fmt::{self, Display};
33

44
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5+
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
56
pub struct TypeId(pub(crate) u32);
67

78
// DEVELOPER PRO TIP: find builtin type OIDs easily by grepping this file

sqlx-core/src/postgres/type_info.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::sync::Arc;
99

1010
/// Type information for a Postgres SQL type.
1111
#[derive(Debug, Clone)]
12+
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
1213
pub struct PgTypeInfo {
1314
pub(crate) id: Option<TypeId>,
1415
pub(crate) name: SharedStr,
@@ -137,6 +138,8 @@ impl TypeInfo for PgTypeInfo {
137138

138139
/// Copy of `Cow` but for strings; clones guaranteed to be cheap.
139140
#[derive(Clone, Debug, PartialEq, Eq)]
141+
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
142+
#[cfg_attr(feature = "offline", serde(from = "String", into = "String"))]
140143
pub(crate) enum SharedStr {
141144
Static(&'static str),
142145
Arc(Arc<str>),

sqlx-core/src/sqlite/type_info.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::types::TypeInfo;
44

55
// https://www.sqlite.org/c3ref/c_blob.html
66
#[derive(Debug, PartialEq, Clone, Copy)]
7+
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
78
pub(crate) enum SqliteType {
89
Integer = 1,
910
Float = 2,
@@ -16,6 +17,7 @@ pub(crate) enum SqliteType {
1617

1718
// https://www.sqlite.org/datatype3.html#type_affinity
1819
#[derive(Debug, PartialEq, Clone, Copy)]
20+
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
1921
pub(crate) enum SqliteTypeAffinity {
2022
Text,
2123
Numeric,
@@ -25,6 +27,7 @@ pub(crate) enum SqliteTypeAffinity {
2527
}
2628

2729
#[derive(Debug, Clone)]
30+
#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
2831
pub struct SqliteTypeInfo {
2932
pub(crate) r#type: SqliteType,
3033
pub(crate) affinity: Option<SqliteTypeAffinity>,

sqlx-core/src/url.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ impl<'s> TryFrom<&'s String> for Url {
2828
}
2929
}
3030

31+
impl TryFrom<url::Url> for Url {
32+
type Error = url::ParseError;
33+
34+
fn try_from(value: url::Url) -> Result<Self, Self::Error> {
35+
Ok(Url(value))
36+
}
37+
}
38+
3139
impl Url {
3240
#[allow(dead_code)]
3341
pub(crate) fn as_str(&self) -> &str {

sqlx-macros/Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ proc-macro = true
1919
default = [ "runtime-async-std" ]
2020

2121
runtime-async-std = [ "sqlx/runtime-async-std", "async-std" ]
22-
runtime-tokio = [ "sqlx/runtime-tokio", "tokio", "lazy_static" ]
22+
runtime-tokio = [ "sqlx/runtime-tokio", "tokio", "once_cell" ]
23+
24+
# offline building support
25+
offline = ["serde", "serde_json", "hex", "sha2"]
2326

2427
# database
2528
mysql = [ "sqlx/mysql" ]
@@ -39,11 +42,14 @@ async-std = { version = "1.5.0", default-features = false, optional = true }
3942
tokio = { version = "0.2.13", default-features = false, features = [ "rt-threaded" ], optional = true }
4043
dotenv = { version = "0.15.0", default-features = false }
4144
futures = { version = "0.3.4", default-features = false, features = [ "executor" ] }
45+
hex = { version = "0.4.2", optional = true }
4246
heck = "0.3"
4347
proc-macro2 = { version = "1.0.9", default-features = false }
4448
sqlx = { version = "0.3.4", default-features = false, path = "../sqlx-core", package = "sqlx-core" }
49+
serde = { version = "1.0", optional = true }
4550
serde_json = { version = "1.0", features = [ "raw_value" ], optional = true }
51+
sha2 = { verison = "0.8.1", optional = true }
4652
syn = { version = "1.0.16", default-features = false, features = [ "full" ] }
4753
quote = { version = "1.0.2", default-features = false }
4854
url = { version = "2.1.1", default-features = false }
49-
lazy_static = { version = "1.4.0", optional = true }
55+
once_cell = { version = "1.3", features = ["std"], optional = true }

0 commit comments

Comments
 (0)