Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion crates/proc-macro-srv-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ paths.workspace = true
span = { path = "../span", default-features = false}
tt.workspace = true
intern.workspace = true
temp-dir.workspace = true
line-index.workspace = true
object.workspace = true

# used as proc macro test target
proc-macro-test.path = "../proc-macro-srv/proc-macro-test"
proc-macro-test.path = "./proc-macro-test"

[features]
default = []
Expand Down
2 changes: 2 additions & 0 deletions crates/proc-macro-srv-cli/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod test_utils;
pub mod utils;
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ use span::{
};
use std::ops::Range;

use crate::{
EnvSnapshot, ProcMacroClientInterface, ProcMacroSrv, SpanId, dylib, proc_macro_test_dylib_path,
token_stream::TokenStream,
use proc_macro_srv::{
EnvSnapshot, ProcMacroClientInterface, ProcMacroSrv, SpanId, dylib, token_stream::TokenStream,
};

fn proc_macro_test_dylib_path() -> paths::Utf8PathBuf {
proc_macro_test::PROC_MACRO_TEST_LOCATION.into()
}

fn parse_string(call_site: SpanId, src: &str) -> TokenStream<SpanId> {
TokenStream::from_str(src, call_site).unwrap()
}
Expand All @@ -24,7 +27,7 @@ fn parse_string_spanned(
.unwrap()
}

pub fn assert_expand(
pub(crate) fn assert_expand(
macro_name: &str,
#[rust_analyzer::rust_fixture] ra_fixture: &str,
expect: Expect,
Expand All @@ -33,7 +36,7 @@ pub fn assert_expand(
assert_expand_impl(macro_name, ra_fixture, None, expect, expect_spanned);
}

pub fn assert_expand_attr(
pub(crate) fn assert_expand_attr(
macro_name: &str,
#[rust_analyzer::rust_fixture] ra_fixture: &str,
attr_args: &str,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
//! proc-macro tests

#[macro_use]
mod utils;
use utils::*;
#![cfg(feature = "sysroot-abi")]
#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]

#[cfg(feature = "in-rust-tree")]
extern crate rustc_driver as _;

#[allow(warnings)]
mod common;

use common::test_utils::*;
use expect_test::expect;

#[test]
Expand Down Expand Up @@ -727,3 +733,22 @@ hello",
"#]],
);
}

#[test]
fn test_version_check() {
let info = proc_macro_srv::dylib::version::read_dylib_info(
&object::File::parse(
&*std::fs::read(crate::common::utils::proc_macro_test_dylib_path()).unwrap(),
)
.unwrap(),
)
.unwrap();

assert_eq!(
info.version_string,
proc_macro_srv::RUSTC_VERSION_STRING,
"sysroot ABI mismatch: dylib rustc version (read from .rustc section): {:?} != proc-macro-srv version (read from 'rustc --version'): {:?}",
info.version_string,
proc_macro_srv::RUSTC_VERSION_STRING,
);
}
6 changes: 0 additions & 6 deletions crates/proc-macro-srv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ ra-ap-rustc_lexer.workspace = true
[target.'cfg(unix)'.dependencies]
libc.workspace = true

[dev-dependencies]
expect-test.workspace = true
line-index.workspace = true

# used as proc macro test targets
proc-macro-test.path = "./proc-macro-test"

[features]
default = []
Expand Down
11 changes: 4 additions & 7 deletions crates/proc-macro-srv/src/dylib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Handles dynamic library loading for proc macro

mod proc_macros;
mod version;
pub mod version;

use rustc_proc_macro::bridge;
use std::{fmt, fs, io, time::SystemTime};
Expand All @@ -16,16 +16,13 @@ use crate::{
dylib::proc_macros::ProcMacros, token_stream::TokenStream,
};

pub(crate) struct Expander {
pub struct Expander {
inner: ProcMacroLibrary,
modified_time: SystemTime,
}

impl Expander {
pub(crate) fn new(
temp_dir: &TempDir,
lib: &Utf8Path,
) -> Result<Expander, LoadProcMacroDylibError> {
pub fn new(temp_dir: &TempDir, lib: &Utf8Path) -> Result<Expander, LoadProcMacroDylibError> {
// Some libraries for dynamic loading require canonicalized path even when it is
// already absolute
let lib = lib.canonicalize_utf8()?;
Expand All @@ -37,7 +34,7 @@ impl Expander {
Ok(Expander { inner: library, modified_time })
}

pub(crate) fn expand<'a, S: ProcMacroSrvSpan + 'a>(
pub fn expand<'a, S: ProcMacroSrvSpan + 'a>(
&self,
macro_name: &str,
macro_body: TokenStream<S>,
Expand Down
17 changes: 0 additions & 17 deletions crates/proc-macro-srv/src/dylib/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,3 @@ pub fn read_version(obj: &object::File<'_>) -> io::Result<String> {
let version_string = String::from_utf8(version_string_utf8);
version_string.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
}

#[test]
fn test_version_check() {
let info = read_dylib_info(
&object::File::parse(&*std::fs::read(crate::proc_macro_test_dylib_path()).unwrap())
.unwrap(),
)
.unwrap();

assert_eq!(
info.version_string,
crate::RUSTC_VERSION_STRING,
"sysroot ABI mismatch: dylib rustc version (read from .rustc section): {:?} != proc-macro-srv version (read from 'rustc --version'): {:?}",
info.version_string,
crate::RUSTC_VERSION_STRING,
);
}
12 changes: 2 additions & 10 deletions crates/proc-macro-srv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ extern crate ra_ap_rustc_lexer as rustc_lexer;
extern crate rustc_lexer;

mod bridge;
mod dylib;
pub mod dylib;
mod server_impl;
mod token_stream;
pub mod token_stream;

use std::{
collections::{HashMap, hash_map::Entry},
Expand Down Expand Up @@ -374,11 +374,3 @@ impl Drop for EnvChange<'_> {
}
}
}

#[cfg(test)]
mod tests;

#[cfg(test)]
pub fn proc_macro_test_dylib_path() -> paths::Utf8PathBuf {
proc_macro_test::PROC_MACRO_TEST_LOCATION.into()
}
4 changes: 2 additions & 2 deletions crates/proc-macro-srv/src/token_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_proc_macro::Delimiter;
use crate::bridge::{DelimSpan, Group, Ident, LitKind, Literal, Punct, TokenTree};

/// Trait for allowing tests to parse tokenstreams with dynamic span ranges
pub(crate) trait SpanLike {
pub trait SpanLike {
fn derive_ranged(&self, range: std::ops::Range<usize>) -> Self;
}

Expand Down Expand Up @@ -47,7 +47,7 @@ impl<S> TokenStream<S> {
}
}

pub(crate) fn from_str(s: &str, span: S) -> Result<Self, String>
pub fn from_str(s: &str, span: S) -> Result<Self, String>
where
S: SpanLike + Copy,
{
Expand Down
Loading