Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(toolchain): bump rust toolchain + simple Nix #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
Empty file added .direnv/.keep
Empty file.
15 changes: 10 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ on:
- master
pull_request:

# Should discard previous running build on same branch
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
# == CHECK == #
check:
name: "Check beta stable and MSRV=1.45.0"
name: "Check beta stable and MSRV=1.64.0"
runs-on: ubuntu-latest
strategy:
matrix:
rust-toolchains:
- 1.45.0
- 1.64.0
- stable
- beta
cargo-locked: ["--locked", ""]
Expand Down Expand Up @@ -52,7 +57,7 @@ jobs:
- macos-latest
- windows-latest
rust-toolchains:
- 1.45.0
- 1.64.0
- stable
steps:
- name: Install Rust toolchain
Expand All @@ -66,14 +71,14 @@ jobs:
uses: actions/checkout@v2

- name: Cargo test (no raw identifier)
if: matrix.rust-toolchains == '1.45.0'
if: matrix.rust-toolchains == '1..0'
uses: actions-rs/cargo@v1
with:
command: test
args: ${{ matrix.cargo-locked }}

- name: Cargo test (all)
if: matrix.rust-toolchains != '1.45.0'
if: matrix.rust-toolchains != '1.64.0'
uses: actions-rs/cargo@v1
with:
command: test
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/future-proof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
schedule:
- cron: '0 8 * * 1,5'

# Should discard previous running build on same branch
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
# == TEST == #
test-no-ui:
Expand All @@ -21,7 +26,7 @@ jobs:
- macos-latest
- windows-latest
rust-toolchains:
- 1.45.0
- 1.64.0
- stable
- beta
- nightly
Expand All @@ -42,14 +47,14 @@ jobs:
run: rm Cargo.lock

- name: Cargo test (no raw identifier)
if: matrix.rust-toolchains == '1.45.0'
if: matrix.rust-toolchains == '1.64.0'
uses: actions-rs/cargo@v1
with:
command: test
args: ${{ matrix.cargo-locked }}

- name: Cargo test (all)
if: matrix.rust-toolchains != '1.45.0'
if: matrix.rust-toolchains != '1.64.0'
uses: actions-rs/cargo@v1
with:
command: test
Expand Down
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
debug/
/target

static/
documentation/

.env.local

**/*.~undo-tree~

.DS_Store

# These are backup files generated by rustfmt
**/*.rs.bk

**/.cache
**/local/

.direnv/
tarpaulin-report.html

.vscode/

.env

result
result/
7 changes: 2 additions & 5 deletions examples/readme-basic.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use ::function_name::named;

#[named]
fn my_super_duper_function ()
{
fn my_super_duper_function() {
dbg!(function_name!());
}

fn main ()
{
fn main() {
my_super_duper_function();
}

18 changes: 9 additions & 9 deletions examples/readme-function_path.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#[macro_use] extern crate function_name;
#[macro_use]
extern crate function_name;

macro_rules! function_path {() => (concat!(
module_path!(), "::", function_name!()
))}
macro_rules! function_path {
() => {
concat!(module_path!(), "::", function_name!())
};
}

pub mod foo {
pub mod bar {
#[named]
pub fn baz ()
{
pub fn baz() {
dbg!(function_path!());
}
}
}

fn main ()
{
fn main() {
foo::bar::baz();
}

92 changes: 92 additions & 0 deletions flake.lock

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

49 changes: 49 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
description = "Rust Function Name";

inputs = {
utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};

outputs = { self, nixpkgs, utils, rust-overlay }:
utils.lib.eachDefaultSystem
(system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain;

baseInputs = with pkgs; [
## Rust
rust
pkg-config
openssl
openssl.dev
llvm
wllvm
rust-bindgen
];

rust-function_name = pkgs.rustPlatform.buildRustPackage rec {
name = "rust-function_name-${version}";
version = "master";

src = pkgs.fetchFromGitHub {
owner = "Unbox-infinity";
repo = "rust-function_name";
rev = "${version}";
sha256 = "sha256-EVv6X2hhS5OVeNCRg7Ut8cVpF5FZ2RB4bMQDv/pgc58=";
};

cargoSha256 = "sha256-LmhCymOgUi9llEnR4ZZ4g/a+eSng0ZzFefY1wQtIRZ8=";
};

in
{
defaultPackage = rust-function_name;
devShells.default = import ./shell.nix { inherit pkgs; };
}
);

}
33 changes: 10 additions & 23 deletions proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
#[allow(unused_imports)]
use {
::core::{
ops::Not as _,
},
::proc_macro::{*,
TokenStream,
},
::core::ops::Not as _,
::proc_macro::{TokenStream, *},
};

#[proc_macro_attribute] pub
fn named (
params: TokenStream,
input: TokenStream,
) -> TokenStream
{
#[proc_macro_attribute]
pub fn named(params: TokenStream, input: TokenStream) -> TokenStream {
named_impl(params.into(), input.into())
.unwrap_or_else(|err| {
let err = Some(TokenTree::from(Literal::string(err)));
quote!(
::core::compile_error! { #err }
)
quote!(::core::compile_error! { #err })
})
.into()
}

fn named_impl (
params: TokenStream,
input: TokenStream,
) -> Result<TokenStream, &'static str>
{
fn named_impl(params: TokenStream, input: TokenStream) -> Result<TokenStream, &'static str> {
// parse::Nothing for `params`.
if let Some(_) = params.into_iter().next() {
return Err("unexpected attribute arguments".into());
Expand Down Expand Up @@ -56,8 +42,8 @@ fn named_impl (
};

let g = match input.last_mut() {
| Some(TokenTree::Group(g)) if g.delimiter() == Delimiter::Brace => g,
| _ => return Err("expected a `fn`"),
Some(TokenTree::Group(g)) if g.delimiter() == Delimiter::Brace => g,
_ => return Err("expected a `fn`"),
};
let g_span = g.span();
*g = Group::new(g.delimiter(), {
Expand Down Expand Up @@ -150,4 +136,5 @@ macro_rules! quote_ {
quote!(@_q $($code)*);
_q.into_iter().collect::<TokenStream>()
});
} use quote_ as quote;
}
use quote_ as quote;
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.45.0
1.65.0
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tab_spaces = 4
edition = "2021"
Loading