Skip to content

Commit

Permalink
Minor v19 2 (#59)
Browse files Browse the repository at this point in the history
* Fix failing test for new rustc

* Move to edition 2021. Fix repo-link in repo

* format

* fix: Better span-info in derive macro error-messages

* feat: Better diagnostics when correct traits not implemented by user, and also explicit minimum rustc version specified

Signed-off-by: Anders Musikka <[email protected]>
  • Loading branch information
avl committed May 12, 2024
1 parent 6c2ea4f commit b8b2fba
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install nightly
run: rustup toolchain install nightly && rustup toolchain install stable
run: rustup toolchain install nightly && rustup toolchain install stable && rustup toolchain install 1.74
- name: Miri (nightly)
run: rustup component add --toolchain nightly miri && cd savefile-test && cargo +nightly miri test
- name: Build (nightly)
Expand All @@ -34,4 +34,6 @@ jobs:
run: cargo +stable build -p savefile-min-build
- name: compile_tests (stable)
run: cd compile_tests && cargo +stable test
- name: Build (1.74)
run: cargo +1.74 build --workspace

7 changes: 4 additions & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions savefile-abi-min/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "savefile-abi-min"
version = "0.1.0"
edition = "2021"
rust-version = "1.74"



Expand Down
2 changes: 1 addition & 1 deletion savefile-abi-min/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub extern "C" fn call_do_nothing(adder: &AbiConnection<dyn AdderInterface>) {

fn main() {
let connection = AbiConnection::<dyn AdderInterface>::load_shared_library(
"c:/savefile/target/debug/savefile_abi_min_lib_impl.dll", //Change this to the proper path on your machine
"../target/debug/libsavefile_abi_min_lib_impl.so", //Change this to the proper path on your machine
)
.unwrap();

Expand Down
10 changes: 10 additions & 0 deletions savefile-abi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.17.4](https://github.com/avl/savefile/compare/savefile-abi-v0.17.3...savefile-abi-v0.17.4) - 2024-05-12

### Added
- Better diagnostics when correct traits not implemented by user, and also explicit minimum rustc version specified

### Other
- Merge branch 'minor_v19' of github.com:avl/savefile into minor_v19
- format
- release ([#54](https://github.com/avl/savefile/pull/54))

## [0.17.3](https://github.com/avl/savefile/compare/savefile-abi-v0.17.2...savefile-abi-v0.17.3) - 2024-05-09

### Other
Expand Down
16 changes: 13 additions & 3 deletions savefile-abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "savefile-abi"
version = "0.17.3"
version = "0.17.4"
edition = "2021"
authors = ["Anders Musikka <[email protected]>"]
documentation = "https://docs.rs/savefile-abi/"
homepage = "https://github.com/avl/savefile/blob/master/savefile-abi/README.md"
repository = "https://github.com/avl/savefile"
rust-version = "1.74"

description = "Easy to use, simple, stable ABI for Rust-libraries. Allows creating dynamically loadable plugins written in rust."

Expand All @@ -16,7 +17,16 @@ keywords = ["dylib", "dlopen", "ffi"]
license = "MIT/Apache-2.0"

[dependencies]
savefile = { path="../savefile", version = "=0.17.3" }
savefile-derive = { path="../savefile-derive", version = "=0.17.3" }
savefile = { path="../savefile", version = "=0.17.4" }
savefile-derive = { path="../savefile-derive", version = "=0.17.4" }
byteorder = "1.4"
libloading = "0.8"

[features]
# Rust version is > 1.78
# Automatically set by build.rs
rust1_78=[]


[build-dependencies]
rustc_version="0.2"
8 changes: 8 additions & 0 deletions savefile-abi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern crate rustc_version;
use rustc_version::{version_meta, Channel, Version};
fn main() {
let version = version_meta().unwrap();
if version.semver >= Version::new(1,78,0) {
println!("cargo:rustc-cfg=feature=\"rust1_78\"");
}
}
15 changes: 15 additions & 0 deletions savefile-abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,23 @@ use libloading::{Library, Symbol};
/// If trait `MyExampleTrait` is to be exportable, the trait `AbiExportable` must
/// be implemented for `dyn MyExampleTrait`.
///
/// NOTE!
/// This trait is not meant to be implemented manually. It is mostly an implementation
/// detail of SavefileAbi, it is only ever meant to be implemented by the savefile-derive
/// proc macro.
///
/// # Safety
/// The implementor must:
/// * Make sure that the ABI_ENTRY function implements all parts of AbiProtocol
/// in a correct manner
/// * Has a correct 'get_definition' function, which must return a AbiTraitDefinition instance
/// that is truthful.
/// * Implement 'call' correctly
#[cfg_attr(feature = "rust1_78", diagnostic::on_unimplemented(
message = "`{Self}` cannot be used across an ABI-boundary. Try adding a `#[savefile_abi_exportable(version=X)]` attribute to the declaration of the relevant trait.",
label = "`{Self}` cannot be called across an ABI-boundary",
note = "This error probably occurred because `{Self}` occurred as a return-value or argument to a method in a trait marked with `#[savefile_abi_exportable(version=X)]`, or because savefile_abi_export!-macro was used to export `{Self}`.",
))]
pub unsafe trait AbiExportable {
/// A function which implements the savefile-abi contract.
const ABI_ENTRY: unsafe extern "C" fn(AbiProtocol);
Expand Down Expand Up @@ -381,6 +391,11 @@ pub unsafe trait AbiExportable {
/// * ABI_ENTRY must be a valid function, implementing the AbiProtocol-protocol.
/// * AbiInterface must be 'dyn SomeTrait', where 'SomeTrait' is an exported trait.
///
#[cfg_attr(feature = "rust1_78", diagnostic::on_unimplemented(
message = "`{Self}` cannot be the concrete type of an AbiExportable dyn trait.",
label = "Does not implement `AbiExportableImplementation`",
note = "You should not be using this trait directly, and should never see this error.",
))]
pub unsafe trait AbiExportableImplementation {
/// An entry point which implements the AbiProtocol protocol
const ABI_ENTRY: unsafe extern "C" fn(AbiProtocol);
Expand Down
9 changes: 9 additions & 0 deletions savefile-derive/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.17.4](https://github.com/avl/savefile/compare/savefile-derive-v0.17.3...savefile-derive-v0.17.4) - 2024-05-12

### Added
- Better diagnostics when correct traits not implemented by user, and also explicit minimum rustc version specified

### Other
- Merge branch 'minor_v19' of github.com:avl/savefile into minor_v19
- Merge remote-tracking branch 'origin/master' into minor_v19

## [0.17.3](https://github.com/avl/savefile/compare/savefile-derive-v0.17.2...savefile-derive-v0.17.3) - 2024-05-09

### Other
Expand Down
4 changes: 2 additions & 2 deletions savefile-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "savefile-derive"
version = "0.17.3"
version = "0.17.4"
authors = ["Anders Musikka <[email protected]>"]
repository = "https://github.com/avl/savefile"

rust-version = "1.74"
description = "Custom derive macros for savefile crate - simple, convenient, fast, versioned, binary serialization/deserialization library."

readme = "../README.md"
Expand Down
2 changes: 1 addition & 1 deletion savefile-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ nightly=["savefile/nightly"]

[dependencies]
savefile = { path = "../savefile", features = ["size_sanity_checks", "encryption", "compression","bit-set","bit-vec","rustc-hash","serde_derive", "quickcheck"]}
savefile-derive = { path = "../savefile-derive", version = "=0.17.3" }
savefile-derive = { path = "../savefile-derive", version = "=0.17.4" }
savefile-abi = { path = "../savefile-abi" }
bit-vec = "0.6"
arrayvec="0.7"
Expand Down
9 changes: 9 additions & 0 deletions savefile/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.17.4](https://github.com/avl/savefile/compare/savefile-v0.17.3...savefile-v0.17.4) - 2024-05-12

### Added
- Better diagnostics when correct traits not implemented by user, and also explicit minimum rustc version specified

### Other
- Merge branch 'minor_v19' of github.com:avl/savefile into minor_v19
- Merge remote-tracking branch 'origin/master' into minor_v19

## [0.17.3](https://github.com/avl/savefile/compare/savefile-v0.17.2...savefile-v0.17.3) - 2024-05-09

### Fixed
Expand Down
12 changes: 9 additions & 3 deletions savefile/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "savefile"
version = "0.17.3"
version = "0.17.4"
authors = ["Anders Musikka <[email protected]>"]
documentation = "https://docs.rs/savefile/"
homepage = "https://github.com/avl/savefile/"
Expand Down Expand Up @@ -32,8 +32,14 @@ serde_derive = ["dep:serde_derive","serde"]
size_sanity_checks = []
# Use features only available on the nightly rust-compiler.
# Enabling this provides slightly better introspection support.
# Automatically set by build.rs for nightly compilers
nightly=[]

# Rust version is > 1.78
# Automatically set by build.rs
rust1_78=[]


compression = ["bzip2"]

encryption = ["ring", "rand"]
Expand All @@ -53,13 +59,13 @@ bit-set = {version = "0.5", optional = true}
rustc-hash = {version = "1.1", optional = true}
memoffset = "0.9"
byteorder = "1.4"
savefile-derive = {path="../savefile-derive", version = "=0.17.3", optional = true }
savefile-derive = {path="../savefile-derive", version = "=0.17.4", optional = true }
serde_derive = {version= "1.0", optional = true}
serde = {version= "1.0", optional = true}
quickcheck = {version= "1.0", optional = true}

[dev-dependencies]
savefile-derive = { path="../savefile-derive", version = "=0.17.3" }
savefile-derive = { path="../savefile-derive", version = "=0.17.4" }

[build-dependencies]
rustc_version="0.2"
Expand Down
8 changes: 6 additions & 2 deletions savefile/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
extern crate rustc_version;
use rustc_version::{version_meta, Channel};
use rustc_version::{version_meta, Channel, Version};
fn main() {
if version_meta().unwrap().channel == Channel::Nightly {
let version = version_meta().unwrap();
if version.channel == Channel::Nightly {
println!("cargo:rustc-cfg=feature=\"nightly\"");
}
if version.semver >= Version::new(1,78,0) {
println!("cargo:rustc-cfg=feature=\"rust1_78\"");
}
}
Loading

0 comments on commit b8b2fba

Please sign in to comment.