Skip to content

Commit

Permalink
fix not compiling without enabled features
Browse files Browse the repository at this point in the history
  • Loading branch information
lenscas committed Nov 15, 2024
1 parent 3b8edc1 commit 3c53d0d
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 104 deletions.
65 changes: 33 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,59 @@ on:
pull_request:
paths:
- "**/*.rs"
- 'Cargo.toml'
- 'tealr/Cargo.lock'
- 'tealr_derive/Cargo.toml'
- '.github/workflows/ci.yml'
- "Cargo.toml"
- "tealr/Cargo.lock"
- "tealr_derive/Cargo.toml"
- ".github/workflows/ci.yml"
jobs:
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
components: rustfmt
- name: Formatting check
run: cargo fmt --all -- --check
- uses: actions/checkout@v2
- uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
components: rustfmt
- name: Formatting check
run: cargo fmt --all -- --check

test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
tests :
tests:
- "cargo test --features mlua,mlua_vendored,mlua_lua53,mlua_async,mlua_send"
- "cargo test --features mlua,mlua_vendored,mlua_lua54,mlua_async,mlua_send"
- "cargo test --features mlua,mlua_vendored,mlua_lua53,mlua_async --no-run"
- "cargo test --features mlua,mlua_vendored,mlua_lua54,mlua_async --no-run"
- "cargo build"
steps:
- uses: actions/checkout@master
- uses: hecrj/[email protected]
with:
rust-version: stable
- uses: leafo/[email protected]
with:
luaVersion: "5.4"
- uses: leafo/[email protected]
- name: Install dependencies
run: luarocks install tl
- name: run tests
run: ${{matrix.tests}}
- uses: actions/checkout@master
- uses: hecrj/[email protected]
with:
rust-version: stable
- uses: leafo/[email protected]
with:
luaVersion: "5.4"
- uses: leafo/[email protected]
- name: Install dependencies
run: luarocks install tl
- name: run tests
run: ${{matrix.tests}}
clippy:
runs-on: ubuntu-latest
strategy:
matrix:
tests :
tests:
- "cargo clippy --features mlua,mlua_vendored,mlua_lua54,mlua_async,mlua_send -- -D warnings"
- "cargo clippy --features mlua,mlua_vendored,mlua_lua53,mlua_async,mlua_send -- -D warnings"
- "cargo clippy --features mlua,mlua_vendored,mlua_luau,mlua_async,mlua_send -- -D warnings"
steps:
- uses: hecrj/[email protected]
with:
rust-version: stable
components: clippy
- uses: actions/checkout@master
- name: Clippy
run: ${{matrix.tests}}
- uses: hecrj/[email protected]
with:
rust-version: stable
components: clippy
- uses: actions/checkout@master
- name: Clippy
run: ${{matrix.tests}}
4 changes: 3 additions & 1 deletion src/export_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub(crate) struct InstanceWalker {
doc: String,
pub(crate) instances: Vec<GlobalInstance>,
}

#[cfg(feature = "mlua")]
impl crate::mlu::InstanceCollector for InstanceWalker {
fn add_instance<P, T, F>(&mut self, global_name: P, _: F) -> Result<&mut Self, mlua::Error>
where
Expand All @@ -30,6 +30,7 @@ impl InstanceWalker {
instances: Default::default(),
}
}
#[allow(dead_code)]
fn add_instance<T: ToTypename>(&mut self, name: Cow<'static, str>) {
let teal_type = T::get_type_parts_as_global();
let z = T::get_type_kind();
Expand All @@ -43,6 +44,7 @@ impl InstanceWalker {
ty: T::to_typename(),
});
}
#[allow(dead_code)]
fn document_instance(&mut self, doc: &'static str) {
self.doc.push_str(doc);
self.doc.push('\n');
Expand Down
11 changes: 7 additions & 4 deletions src/exported_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ use std::{
};

use crate::{get_generics, type_generator::NameContainer, FunctionParam, Name, NamePart, Type};

#[allow(dead_code)]
type X = Vec<NamePart>;

///Contains the data needed to write down the type of a function
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "derive", derive(crate::mlu::FromToLua, crate::ToTypename))]
#[cfg_attr(
feature = "derive",
all(feature = "derive", feature = "mlua"),
derive(crate::mlu::FromToLua, crate::ToTypename)
)]
#[cfg_attr(
all(feature = "derive", feature = "mlua"),
tealr(tealr_name = crate)
)]
pub struct ExportedFunction {
Expand All @@ -21,7 +24,7 @@ pub struct ExportedFunction {
///The full layout of the function based on teal's syntax
#[deprecated]
#[cfg_attr(
feature = "derive",
all(feature = "derive", feature = "mlua"),
tealr(remote = X)
)]
pub signature: Cow<'static, [crate::NamePart]>,
Expand Down
57 changes: 38 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![doc = include_str!("../README.md")]

///traits and types specific to mlua
#[cfg(feature = "mlua")]
pub mod mlu;

mod export_instance;
Expand Down Expand Up @@ -44,15 +45,18 @@ pub fn get_tealr_version() -> &'static str {
}

#[derive(PartialEq, Eq, Hash, Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "derive", derive(crate::mlu::FromToLua, crate::ToTypename))]
#[cfg_attr(
feature = "derive",
all(feature = "mlua", feature = "derive"),
derive(crate::mlu::FromToLua, crate::ToTypename)
)]
#[cfg_attr(
all(feature = "mlua",feature = "derive"),
tealr(tealr_name = crate)
)]
///The name of a type
pub struct Name(
#[cfg_attr(
feature = "derive",
all(feature = "mlua",feature = "derive"),
tealr(remote = String))]
pub Cow<'static, str>,
);
Expand All @@ -68,9 +72,12 @@ impl<T: AsRef<str>> From<T> for Name {
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "derive", derive(crate::mlu::FromToLua, crate::ToTypename))]
#[cfg_attr(
feature = "derive",
all(feature = "mlua", feature = "derive"),
derive(crate::mlu::FromToLua, crate::ToTypename)
)]
#[cfg_attr(
all(feature = "mlua",feature = "derive"),
tealr(tealr_name = crate)
)]
///A singular type
Expand All @@ -81,9 +88,12 @@ pub struct SingleType {
pub kind: KindOfType,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "derive", derive(crate::mlu::FromToLua, crate::ToTypename))]
#[cfg_attr(
feature = "derive",
all(feature = "mlua", feature = "derive"),
derive(crate::mlu::FromToLua, crate::ToTypename)
)]
#[cfg_attr(
all(feature = "mlua",feature = "derive"),
tealr(tealr_name = crate)
)]
///A parameter for a function
Expand All @@ -94,9 +104,12 @@ pub struct FunctionParam {
pub ty: Type,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "derive", derive(crate::mlu::FromToLua, crate::ToTypename))]
#[cfg_attr(
feature = "derive",
all(feature = "mlua", feature = "derive"),
derive(crate::mlu::FromToLua, crate::ToTypename)
)]
#[cfg_attr(
all(feature = "mlua",feature = "derive"),
tealr(tealr_name = crate)
)]
///The representation of a function type
Expand All @@ -107,31 +120,37 @@ pub struct FunctionRepresentation {
pub returns: Vec<Type>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "derive", derive(crate::mlu::FromToLua, crate::ToTypename))]
#[cfg_attr(
feature = "derive",
all(feature = "mlua", feature = "derive"),
derive(crate::mlu::FromToLua, crate::ToTypename)
)]
#[cfg_attr(
all(feature = "mlua",feature = "derive"),
tealr(tealr_name = crate)
)]
///The representation of a Map<K,T> type
pub struct MapRepresentation {
#[cfg_attr(
feature = "derive",
all(feature = "mlua",feature = "derive"),
tealr(remote = Type))]
///The type of the key
pub key: Box<Type>,
#[cfg_attr(
feature = "derive",
all(feature = "mlua",feature = "derive"),
tealr(remote = Type))]
///The type of the value
pub value: Box<Type>,
}

#[allow(dead_code)]
type NewTypeArray = Vec<Type>;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "derive", derive(crate::mlu::FromToLua, crate::ToTypename))]
#[cfg_attr(
feature = "derive",
all(feature = "mlua", feature = "derive"),
derive(crate::mlu::FromToLua, crate::ToTypename)
)]
#[cfg_attr(
all(feature = "mlua",feature = "derive"),
tealr(tealr_name = crate)
)]
///A type
Expand All @@ -145,14 +164,14 @@ pub enum Type {
///The type is a union (A | B)
Or(
#[cfg_attr(
feature = "derive",
all(feature = "mlua",feature = "derive"),
tealr(remote = NewTypeArray))]
Vec<Type>,
),
///The type is an array
Array(
#[cfg_attr(
feature = "derive",
all(feature = "mlua",feature = "derive"),
tealr(remote = Type))]
Box<Type>,
),
Expand All @@ -161,7 +180,7 @@ pub enum Type {
///As it can _easily_ break things
Tuple(
#[cfg_attr(
feature = "derive",
all(feature = "mlua",feature = "derive"),
tealr(remote = NewTypeArray))]
Vec<Type>,
),
Expand Down
9 changes: 6 additions & 3 deletions src/teal_multivalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ use crate::{type_representation::KindOfType, ToTypename, Type};

///Represents a type
#[derive(Debug, PartialEq, Eq, Clone, Hash, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "derive", derive(crate::mlu::FromToLua, crate::ToTypename))]
#[cfg_attr(
all(feature = "derive"),
all(feature = "derive", feature = "mlua"),
derive(crate::mlu::FromToLua, crate::ToTypename)
)]
#[cfg_attr(
all(feature = "mlua",feature = "derive"),
tealr(tealr_name = crate)
)]
pub struct TealType {
///Name of the type
#[cfg_attr(
all(feature = "derive"),
all(feature = "mlua", feature = "derive"),
tealr(remote = String))]
pub name: Cow<'static, str>,
///If the type is build in, a generic or from a library
Expand Down
Loading

0 comments on commit 3c53d0d

Please sign in to comment.