Skip to content
This repository was archived by the owner on Jul 6, 2019. It is now read-only.

Commit d11e991

Browse files
committed
Get Cargo working for the zinc rlib
1 parent c5bcdff commit d11e991

File tree

9 files changed

+94
-83
lines changed

9 files changed

+94
-83
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/target/
12
/build/
23
/thirdparty/
34
.DS_Store
5+
Cargo.lock

Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "zinc"
3+
version = "0.0.1"
4+
authors = ["[email protected]"]
5+
#build = ["rake target_deps", "support/cargo_deps"]
6+
7+
[lib]
8+
name = "zinc"
9+
path = "src/zinc/lib.rs"
10+
11+
[dependencies.rlibc]
12+
git = "https://github.com/bharrisau/rust-librlibc.git"
13+
14+
[dependencies.core]
15+
git = "https://github.com/bharrisau/rust-libcore.git"
16+
17+
[dependencies.ioreg]
18+
path = "src/ioreg"
19+
20+
[dev-dependencies.hamcrest]
21+
git = "https://github.com/carllerche/hamcrest-rust.git"

Rakefile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ provide_stdlibs
1111
desc "Run tests"
1212
task :test
1313

14+
# task for target specific rust crates
15+
desc "Build target libraries"
16+
task :target_deps => [
17+
'thirdparty/libcore/lib.rs'.in_root.as_rlib.in_build,
18+
'thirdparty/librlibc/lib.rs'.in_root.as_rlib.in_build]
19+
1420
# external dependencies
1521
compile_rust :shiny_crate, {
1622
source: 'thirdparty/shiny/src/lib.rs'.in_root,
@@ -51,24 +57,16 @@ compile_rust :ioreg_crate, {
5157
build_for: :host,
5258
}
5359

54-
compile_rust :macro_ioreg, {
55-
source: 'macro/ioreg.rs'.in_source,
56-
deps: [:ioreg_crate],
57-
produce: 'macro/ioreg.rs'.in_source.as_dylib.in_build,
58-
out_dir: true,
59-
build_for: :host,
60-
}
61-
6260
rust_tests :ioreg_test, {
6361
source: 'ioreg/test.rs'.in_source,
64-
deps: [:core_crate, :macro_ioreg, :shiny_crate],
62+
deps: [:core_crate, :ioreg_crate, :shiny_crate],
6563
produce: 'ioreg_test'.in_build,
6664
}
6765

6866
# zinc crate
6967
compile_rust :zinc_crate, {
7068
source: 'zinc/lib.rs'.in_source,
71-
deps: [:core_crate, :rlibc_crate, :macro_ioreg],
69+
deps: [:core_crate, :rlibc_crate, :ioreg_crate],
7270
produce: 'zinc/lib.rs'.in_source.as_rlib.in_build,
7371
out_dir: true,
7472
recompile_on: [:triple, :platform],
@@ -108,7 +106,7 @@ rust_tests :platformtree_test, {
108106
# zinc test
109107
rust_tests :zinc_test, {
110108
source: 'zinc/lib.rs'.in_source,
111-
deps: [:core_crate, :macro_ioreg, :hamcrest_crate, :shiny_crate],
109+
deps: [:core_crate, :ioreg_crate, :hamcrest_crate, :shiny_crate],
112110
produce: 'zinc_test'.in_build,
113111
recompile_on: [:platform],
114112
build_for: :host,

src/ioreg/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "ioreg"
3+
version = "0.0.1"
4+
authors = ["[email protected]"]
5+
6+
[lib]
7+
name = "ioreg"
8+
path = "ioreg.rs"
9+
plugin = true
10+
11+
[dev-dependencies.hamcrest]
12+
git = "https://github.com/carllerche/hamcrest-rust.git"

src/ioreg/ioreg.rs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,56 @@ N => NAME
327327
328328
*/
329329

330-
#![feature(quote, struct_variant)]
330+
#![feature(quote, struct_variant, plugin_registrar)]
331331
#![crate_name="ioreg"]
332-
#![crate_type="rlib"]
332+
#![crate_type="dylib"]
333333

334+
extern crate rustc;
334335
extern crate syntax;
335336
extern crate serialize;
336337

338+
use rustc::plugin::Registry;
339+
use syntax::ast;
340+
use syntax::ptr::P;
341+
use syntax::codemap::Span;
342+
use syntax::ext::base::{ExtCtxt, MacResult};
343+
use syntax::util::small_vector::SmallVector;
344+
337345
pub mod node;
338346
pub mod parser;
339347
pub mod builder;
348+
349+
#[plugin_registrar]
350+
pub fn plugin_registrar(reg: &mut Registry) {
351+
reg.register_macro("ioregs", macro_ioregs);
352+
}
353+
354+
pub fn macro_ioregs(cx: &mut ExtCtxt, _: Span, tts: &[ast::TokenTree])
355+
-> Box<MacResult+'static> {
356+
match parser::Parser::new(cx, tts).parse_ioregs() {
357+
Some(group) => {
358+
let mut builder = builder::Builder::new();
359+
let items = builder.emit_items(cx, group);
360+
MacItems::new(items)
361+
},
362+
None => {
363+
panic!();
364+
}
365+
}
366+
}
367+
368+
pub struct MacItems {
369+
items: Vec<P<ast::Item>>
370+
}
371+
372+
impl MacItems {
373+
pub fn new(items: Vec<P<ast::Item>>) -> Box<MacResult+'static> {
374+
box MacItems { items: items } as Box<MacResult>
375+
}
376+
}
377+
378+
impl MacResult for MacItems {
379+
fn make_items(self: Box<MacItems>) -> Option<SmallVector<P<ast::Item>>> {
380+
Some(SmallVector::many(self.items.clone()))
381+
}
382+
}

src/ioreg/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//! Tests for ioreg! syntax extension
1717
1818
#![feature(phase)]
19-
#[phase(plugin)] extern crate macro_ioreg;
19+
#[phase(plugin)] extern crate ioreg;
2020
#[phase(plugin,link)] extern crate shiny;
2121
extern crate core;
2222

src/macro/ioreg.rs

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/zinc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extern crate rlibc;
4949

5050
#[cfg(test)] #[phase(plugin,link)] extern crate std;
5151
#[cfg(test)] extern crate native;
52-
#[phase(plugin)] extern crate macro_ioreg;
52+
#[phase(plugin)] extern crate ioreg;
5353

5454
pub mod drivers;
5555
pub mod hal;

support/cargo_deps

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
mkdir -p ./target/$TARGET/deps
3+
cp ./build/libcore.rlib ./build/librlibc.rlib ./target/$TARGET/deps

0 commit comments

Comments
 (0)