Skip to content

Commit 86a6b2a

Browse files
committed
Use feature for proc_macro_hack
1 parent bd749ea commit 86a6b2a

8 files changed

Lines changed: 143 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 120 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ name = "bench"
1515
path = "./benchmarks/bench.rs"
1616

1717
[features]
18-
default = []
18+
default = ["rustpython-vm/use-proc-macro-hack"]
1919
flame-it = ["rustpython-vm/flame-it", "flame", "flamescope"]
2020

2121
[dependencies]
2222
log="0.4.1"
2323
env_logger="0.5.10"
2424
clap = "2.31.2"
25+
rustpython-vm = {path = "vm", version = "0.1.0"}
2526
rustpython-compiler = {path = "compiler", version = "0.1.0"}
2627
rustpython-parser = {path = "parser", version = "0.1.0"}
27-
rustpython-vm = {path = "vm", version = "0.1.0"}
2828
xdg = "2.2.0"
2929

3030
flame = { version = "0.2", optional = true }
@@ -33,6 +33,7 @@ flamescope = { version = "0.1", optional = true }
3333
[target.'cfg(not(target_os = "redox"))'.dependencies]
3434
rustyline = "4.1.0"
3535

36+
3637
[dev-dependencies.cpython]
3738
version = "0.2"
3839

derive/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ edition = "2018"
1010
[lib]
1111
proc-macro = true
1212

13+
[features]
14+
default = ["proc-macro-hack"]
15+
1316
[dependencies]
1417
syn = { version = "0.15.29", features = ["full"] }
1518
quote = "0.6.11"
1619
proc-macro2 = "0.4.27"
1720
rustpython-compiler = { path = "../compiler", version = "0.1.0" }
1821
rustpython-bytecode = { path = "../bytecode", version = "0.1.0" }
1922
bincode = "1.1"
23+
proc-macro-hack = { version = "0.5", optional = true }

derive/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ pub fn pystruct_sequence(attr: TokenStream, item: TokenStream) -> TokenStream {
5050
result_to_tokens(pyclass::impl_pystruct_sequence(attr, item))
5151
}
5252

53-
#[proc_macro]
53+
#[cfg_attr(feature = "proc-macro-hack", proc_macro_hack::proc_macro_hack)]
54+
#[cfg_attr(not(feature = "proc-macro-hack"), proc_macro)]
5455
pub fn py_compile_bytecode(input: TokenStream) -> TokenStream {
5556
result_to_tokens(compile_bytecode::impl_py_compile_bytecode(input.into()))
5657
}

src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustpython_vm::{
1616
util, VirtualMachine,
1717
};
1818

19-
use std::io::{self, BufRead, Write};
2019
use std::path::PathBuf;
2120
use std::process;
2221

@@ -301,7 +300,7 @@ fn get_prompt(vm: &VirtualMachine, prompt_name: &str) -> String {
301300
#[cfg(not(target_os = "redox"))]
302301
fn run_shell(vm: &VirtualMachine) -> PyResult {
303302
use rustyline::{error::ReadlineError, Editor};
304-
303+
305304
println!(
306305
"Welcome to the magnificent Rust Python {} interpreter \u{1f631} \u{1f596}",
307306
crate_version!()
@@ -376,12 +375,14 @@ fn run_shell(vm: &VirtualMachine) -> PyResult {
376375

377376
#[cfg(target_os = "redox")]
378377
fn run_shell(vm: &VirtualMachine) -> PyResult {
379-
println!(
378+
use std::io::{self, BufRead, Write};
379+
380+
println!(
380381
"Welcome to the magnificent Rust Python {} interpreter \u{1f631} \u{1f596}",
381382
crate_version!()
382383
);
383384
let vars = vm.new_scope_with_builtins();
384-
385+
385386
let stdin = io::stdin();
386387
let stdout = io::stdout();
387388
let mut stdout = stdout.lock();

vm/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ edition = "2018"
99
include = ["src/**/*.rs", "Cargo.toml", "build.rs", "Lib/**/*.py"]
1010

1111
[features]
12-
default = ["rustpython-parser", "rustpython-compiler"]
12+
default = ["rustpython-parser", "rustpython-compiler", "use-proc-macro-hack"]
1313
vm-tracing-logging = []
1414
flame-it = ["flame", "flamer"]
15+
use-proc-macro-hack = ["proc-macro-hack", "rustpython-derive/proc-macro-hack"]
1516

1617
[dependencies]
1718
# Crypto:
@@ -56,6 +57,7 @@ unicode_names2 = "0.2.2"
5657
unicode-casing = "0.1.0"
5758
unic = "0.9.0"
5859
maplit = "1.0"
60+
proc-macro-hack = { version = "0.5", optional = true }
5961
bitflags = "1.1"
6062

6163
flame = { version = "0.2", optional = true }

vm/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
)]
1414
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/master/logo.png")]
1515
#![doc(html_root_url = "https://docs.rs/rustpython-vm/")]
16-
// For redox:
17-
#![feature(proc_macro_hygiene, vecdeque_rotate)]
16+
#![cfg_attr(not(feature = "use-proc-macro-hack"), feature(proc_macro_hygiene))]
17+
#![cfg_attr(target_os = "redox", feature(vecdeque_rotate))]
1818

1919
#[cfg(feature = "flame-it")]
2020
#[macro_use]
@@ -38,6 +38,10 @@ extern crate self as rustpython_vm;
3838

3939
pub use rustpython_derive::*;
4040

41+
#[cfg(feature = "use-proc-macro-hack")]
42+
#[proc_macro_hack::proc_macro_hack]
43+
pub use rustpython_derive::py_compile_bytecode;
44+
4145
//extern crate eval; use eval::eval::*;
4246
// use py_code_object::{Function, NativeType, PyCodeObject};
4347

vm/src/stdlib/os.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ fn os_stat(
607607
.map_err(|s| vm.new_os_error(s.to_string()))
608608
}
609609

610-
611610
#[cfg(not(any(
612611
target_os = "linux",
613612
target_os = "macos",

0 commit comments

Comments
 (0)