Skip to content

Commit

Permalink
Split diesel_codegen into two crates.
Browse files Browse the repository at this point in the history
Having the same crate for both has caused a ton of problems with
linking. I had hoped to just use cargo features for this, but it wasn't
working out that way.

`diesel_codegen` now only targets nightly. `diesel_codegen_syntex`
handles syntex separately (and also contains the common code between the
two crates). Neither crate includes the postgres feature by default.

How to migrate
--------------

If your Cargo.toml previously looked like this:

```rust
[build-dependencies]
diesel_codegen = "0.6.0"
```

it should change to

```rust
[build-dependencies]
diesel_codegen_syntex = { version = "0.7.0", features = ["postgres"] }
```

(You'll need to change the `extern crate` line in `build.rs`)

If your Cargo.toml previously looked like this:

```rust
[dependencies]
diesel_codegen = { version = "0.6.0", default-features = false, features = ["nightly", "postgres"] }
```

it should change to

```rust
[dependencies]
diesel_codegen = { version = "0.7.0", features = ["postgres"] }
```

I've had to split out the cargo features in our test suite, since Cargo
doesn't give me a way to say "turn on the
diesel_codegen_syntex/postgres" feature only if the `with-syntex`
and `postgres` features are on, and I don't want to have to build syntex
every time I run the tests against nightly.
  • Loading branch information
sgrif committed Aug 1, 2016
1 parent b33f8b6 commit 36b8801
Show file tree
Hide file tree
Showing 30 changed files with 113 additions and 258 deletions.
2 changes: 1 addition & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
paths = ["diesel"]
paths = ["diesel", "diesel_codegen_syntex"]
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ script:
fi &&
(cd diesel_cli && travis-cargo test -- --no-default-features --features "$BACKEND") &&
if [[ "$TRAVIS_RUST_VERSION" == nightly* ]]; then
(cd diesel_codegen && travis-cargo test -- --no-default-features --features "nightly $BACKEND")
(cd diesel_codegen_syntex && travis-cargo test -- --no-default-features --features "$BACKEND")
else
(cd diesel_codegen && travis-cargo test -- --no-default-features --features "with-syntex $BACKEND")
(cd diesel_codegen_syntex && travis-cargo test -- --no-default-features --features "with-syntex $BACKEND")
fi &&
if [[ "$TRAVIS_RUST_VERSION" == nightly* ]]; then
(cd diesel_tests && travis-cargo test -- --no-default-features --features "unstable $BACKEND")
(cd diesel_tests && travis-cargo test -- --no-default-features --features "unstable_$BACKEND")
else
(cd diesel_tests && travis-cargo test -- --no-default-features --features "with-syntex $BACKEND")
(cd diesel_tests && travis-cargo test -- --no-default-features --features "stable_$BACKEND")
fi &&
if [[ "$TRAVIS_RUST_VERSION" == nightly* ]]; then
(cd diesel_compile_tests && travis-cargo test)
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/
* Diesel now targets `nightly-2016-07-07`. Future releases will update to a
newer nightly version on the date that Rust releases.

* `diesel_codegen` has been split into two crates. `diesel_codegen` and
`diesel_codegen_syntex`. See [this commit](FIXME COMMIT LINK HERE) for
migration information.

* Most structs that implement `Queryable` will now also need
`#[derive(Identifiable)]`.

Expand Down
10 changes: 5 additions & 5 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
set -e

if [ "$1" == "integration" ] && [ "$2" == "sqlite" ]; then
(cd diesel_tests && DATABASE_URL=/tmp/test.db cargo test --features "unstable sqlite" --no-default-features)
(cd diesel_tests && DATABASE_URL=/tmp/test.db cargo test --features "unstable_sqlite" --no-default-features)
elif [ "$1" == "integration" ]; then
(cd diesel_tests && cargo test --features "unstable postgres" --no-default-features)
(cd diesel_tests && cargo test --features "unstable_postgres" --no-default-features)
elif [ "$1" == "compile" ]; then
(cd diesel_compile_tests && cargo test)
else
(cd diesel && cargo test --features "unstable chrono sqlite")
(cd diesel_cli && cargo test --features "postgres" --no-default-features)
(cd diesel_cli && cargo test --features "sqlite" --no-default-features)
(cd diesel_codegen && cargo test --no-default-features --features "nightly postgres")
(cd diesel_tests && cargo test --features "unstable postgres" --no-default-features)
(cd diesel_tests && DATABASE_URL=/tmp/test.db cargo test --features "unstable sqlite" --no-default-features)
(cd diesel_codegen_syntex && cargo test --no-default-features --features "postgres")
(cd diesel_tests && cargo test --features "unstable_postgres" --no-default-features)
(cd diesel_tests && DATABASE_URL=/tmp/test.db cargo test --features "unstable_sqlite" --no-default-features)
(cd diesel_compile_tests && cargo test)
fi;
22 changes: 4 additions & 18 deletions diesel_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,18 @@ name = "diesel_codegen"
version = "0.6.1"
authors = ["Sean Griffin <sean@seantheprogrammer.com>"]
license = "MIT OR Apache-2.0"
build = "build.rs"
description = "Annotations to remove boilerplate from Diesel"
documentation = "https://github.com/diesel-rs/diesel/blob/master/diesel_codegen"
homepage = "http://diesel.rs"
repository = "https://github.com/diesel-rs/diesel/tree/master/diesel_codegen"
keywords = ["orm", "database", "postgres", "sql", "codegen"]

[build-dependencies]
syntex = { version = ">= 0.37.0, < 0.39.0", optional = true }
syntex_syntax = { version = ">= 0.37.0, < 0.39.0", optional = true }

[dependencies]
syntex = { version = ">= 0.37.0, < 0.39.0", optional = true }
syntex_syntax = { version = ">= 0.37.0, < 0.39.0", optional = true }
diesel = { git = "https://github.com/diesel-rs/diesel.git", default-features = false }

[dev-dependencies]
tempdir = "0.3.4"
diesel_codegen_syntex = { path = "../diesel_codegen_syntex", default-features = false }

[features]
default = ["with-syntex", "postgres"]
nightly = []
with-syntex = ["syntex", "syntex_syntax"]
postgres = ["diesel/postgres"]
sqlite = ["diesel/sqlite"]
postgres = ["diesel_codegen_syntex/postgres"]
sqlite = ["diesel_codegen_syntex/sqlite"]

[lib]
name = "diesel_codegen"
crate-type = ["rlib", "dylib"]
plugin = true
173 changes: 0 additions & 173 deletions diesel_codegen/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions diesel_codegen/src/lib.in.rs

This file was deleted.

44 changes: 4 additions & 40 deletions diesel_codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,12 @@
#![cfg_attr(not(feature = "with-syntex"), feature(rustc_private, plugin_registrar, quote))]
#![deny(warnings)]
#![feature(rustc_private, plugin_registrar)]

#[macro_use] extern crate diesel;

#[cfg(feature = "with-syntex")]
extern crate syntex;

#[cfg(feature = "with-syntex")]
extern crate syntex_syntax as syntax;

#[cfg(not(feature = "with-syntex"))]
extern crate diesel_codegen_syntex;
extern crate syntax;

#[cfg(not(feature = "with-syntex"))]
extern crate rustc_plugin;

#[cfg(feature = "with-syntex")]
include!(concat!(env!("OUT_DIR"), "/lib.rs"));

#[cfg(not(feature = "with-syntex"))]
include!("lib.in.rs");

mod util;

#[cfg(feature = "with-syntex")]
pub fn register(reg: &mut syntex::Registry) {
reg.add_attr("feature(custom_derive)");
reg.add_attr("feature(custom_attribute)");

reg.add_decorator("derive_Queryable", queryable::expand_derive_queryable);
reg.add_decorator("derive_Identifiable", identifiable::expand_derive_identifiable);
reg.add_decorator("insertable_into", insertable::expand_insert);
reg.add_decorator("changeset_for", update::expand_changeset_for);
reg.add_decorator("has_many", associations::expand_has_many);
reg.add_decorator("belongs_to", associations::expand_belongs_to);
reg.add_macro("embed_migrations", migrations::expand_embed_migrations);
reg.add_macro("infer_table_from_schema", schema_inference::expand_load_table);
reg.add_macro("infer_schema", schema_inference::expand_infer_schema);

reg.add_post_expansion_pass(util::strip_attributes);
}
use diesel_codegen_syntex::*;

#[cfg_attr(not(feature = "with-syntex"), plugin_registrar)]
#[cfg(not(feature = "with-syntex"))]
#[plugin_registrar]
pub fn register(reg: &mut rustc_plugin::Registry) {
use syntax::parse::token::intern;
use syntax::ext::base::MultiDecorator;
Expand Down
29 changes: 29 additions & 0 deletions diesel_codegen_syntex/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "diesel_codegen_syntex"
version = "0.6.1"
authors = ["Sean Griffin <sean@seantheprogrammer.com>"]
license = "MIT OR Apache-2.0"
build = "build.rs"
description = "Allows use of `diesel_codegen` with `syntex`"
documentation = "https://github.com/diesel-rs/diesel/blob/master/diesel_codegen"
homepage = "http://diesel.rs"
repository = "https://github.com/diesel-rs/diesel/tree/master/diesel_codegen"
keywords = ["orm", "database", "postgres", "sql", "codegen"]

[build-dependencies]
syntex = { version = ">= 0.37.0, < 0.39.0", optional = true }
syntex_syntax = { version = ">= 0.37.0, < 0.39.0", optional = true }

[dependencies]
syntex = { version = ">= 0.37.0, < 0.39.0", optional = true }
syntex_syntax = { version = ">= 0.37.0, < 0.39.0", optional = true }
diesel = { git = "https://github.com/diesel-rs/diesel.git", default-features = false }

[dev-dependencies]
tempdir = "0.3.4"

[features]
default = ["with-syntex"]
with-syntex = ["syntex", "syntex_syntax"]
postgres = ["diesel/postgres"]
sqlite = ["diesel/sqlite"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions diesel_codegen_syntex/src/lib.in.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod associations;
mod attr;
pub mod identifiable;
pub mod insertable;
pub mod migrations;
mod model;
pub mod queryable;
pub mod schema_inference;
pub mod update;
Loading

0 comments on commit 36b8801

Please sign in to comment.