Skip to content

Commit

Permalink
Merge pull request #55 from ubolonton/non-zero-integer-types
Browse files Browse the repository at this point in the history
`NonZero` integer types
  • Loading branch information
ubolonton authored Mar 16, 2024
2 parents 9a29b07 + f6e6f31 commit 5a1c4ab
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 65 deletions.
99 changes: 70 additions & 29 deletions .azure-pipelines/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,55 @@ pr:

strategy:
matrix:
vs2017-win2016:
IMAGE_NAME: 'vs2017-win2016'
# ----------------------------------------------------------------

# Latest Emacs version on Windows.
windows-2019:
IMAGE_NAME: 'windows-2019'
windows-2022:
IMAGE_NAME: 'windows-2022'

macos-10.14-emacs-25.3:
IMAGE_NAME: 'macos-10.14'
EVM_EMACS: emacs-25.3
macos-10.14-emacs-26.3:
IMAGE_NAME: 'macos-10.14'
EVM_EMACS: emacs-26.3
macos-10.14-emacs-27.1:
IMAGE_NAME: 'macos-10.14'
EVM_EMACS: emacs-27.1
# ----------------------------------------------------------------

# Emacs is getting "Killed 9" on these agents, probably due to macOS 10.15 updates.
# macos-10.15-emacs-25.3:
# IMAGE_NAME: 'macos-10.15'
# EVM_EMACS: emacs-25.3
# macos-10.15-emacs-26.3:
# IMAGE_NAME: 'macos-10.15'
# EVM_EMACS: emacs-26.3
macos-10.15-emacs-27.1:
IMAGE_NAME: 'macos-10.15'
EVM_EMACS: emacs-27.1
# XXX: There's no easy way to make evm-built binaries of Emacs 26- work on macOS
# 10.15+ (Catalina). They get `Killed: 9`. Basically syspolicyd got a lot more shitty
# (checking notarization of unsigned executables by connecting to Apple servers), and
# there's no easy way to disable it. So we just don't test these cases.
#
# Example troubleshooting commands:
#
# syslog -f /var/log/DiagnosticMessages/2021.08.07.asl
#
# See also:
# - https://github.com/rust-lang/cargo/issues/7821#issuecomment-584469149
# - https://lapcatsoftware.com/articles/catalina-executables.html
# - https://news.ycombinator.com/item?id=23281564
# - https://kittywhiskers.eu/disable-syspolicyd-on-your-hackintosh/
# - https://knight.sc/reverse%20engineering/2019/02/20/syspolicyd-internals.html
# - https://www.naut.ca/blog/2020/11/13/forbidden-commands-to-liberate-macos/

macOS-11-emacs-27.2:
IMAGE_NAME: 'macOS-11'
EVM_EMACS: emacs-27.2
macOS-11-emacs-28.1:
IMAGE_NAME: 'macOS-11'
EVM_EMACS: emacs-28.1

macOS-12-emacs-27.2:
IMAGE_NAME: 'macOS-12'
EVM_EMACS: emacs-27.2
macOS-12-emacs-28.1:
IMAGE_NAME: 'macOS-12'
EVM_EMACS: emacs-28.1

macOS-13-emacs-27.2:
IMAGE_NAME: 'macOS-13'
EVM_EMACS: emacs-27.2
macOS-13-emacs-28.1:
IMAGE_NAME: 'macOS-13'
EVM_EMACS: emacs-28.1

# ----------------------------------------------------------------

# thread 'main' panicked at '`libclang` function not loaded: `clang_createIndex`. This crate requires that `libclang` 3.9 or later be installed on your system. For more information on how to accomplish this, see here: https://rust-lang.github.io/rust-bindgen/requirements.html#installing-clang-39', /home/vsts/.cargo/registry/src/github.com-1ecc6299db9ec823/clang-sys-1.2.0/src/lib.rs:1682:1
# ubuntu-16.04-emacs-25.3:
Expand All @@ -54,23 +78,40 @@ strategy:
# IMAGE_NAME: 'ubuntu-16.04'
# EVM_EMACS: emacs-26.3

ubuntu-18.04-emacs-25.3:
IMAGE_NAME: 'ubuntu-18.04'
ubuntu-20.04-emacs-25.3:
IMAGE_NAME: 'ubuntu-20.04'
EVM_EMACS: emacs-25.3
ubuntu-18.04-emacs-26.3:
IMAGE_NAME: 'ubuntu-18.04'
ubuntu-20.04-emacs-26.3:
IMAGE_NAME: 'ubuntu-20.04'
EVM_EMACS: emacs-26.3
ubuntu-18.04-emacs-27.1:
IMAGE_NAME: 'ubuntu-18.04'
EVM_EMACS: emacs-27.1
ubuntu-20.04-emacs-27.2:
IMAGE_NAME: 'ubuntu-20.04'
EVM_EMACS: emacs-27.2
ubuntu-20.04-emacs-28.1:
IMAGE_NAME: 'ubuntu-20.04'
EVM_EMACS: emacs-28.1

# sysdep.c:1821:22: error: variably modified ‘sigsegv_stack’ at file scope
# ubuntu-22.04-emacs-25.3:
# IMAGE_NAME: 'ubuntu-22.04'
# EVM_EMACS: emacs-25.3
# ubuntu-22.04-emacs-26.3:
# IMAGE_NAME: 'ubuntu-22.04'
# EVM_EMACS: emacs-26.3
# ubuntu-22.04-emacs-27.2:
# IMAGE_NAME: 'ubuntu-22.04'
# EVM_EMACS: emacs-27.2
ubuntu-22.04-emacs-28.1:
IMAGE_NAME: 'ubuntu-22.04'
EVM_EMACS: emacs-28.1

pool:
vmImage: $(IMAGE_NAME)

steps:
- template: steps/setup-rust.yml
parameters:
version: '1.45.0'
version: '1.56.0'
- template: steps/-build.yml
- template: steps/setup-emacs.yml
- template: steps/-test.yml
2 changes: 1 addition & 1 deletion .azure-pipelines/steps/setup-emacs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ steps:
# XXX: Please don't use homebrew!
- bash: |
set -e
brew install pkg-config gnutls libxml2
brew install pkg-config gnutls
# https://github.com/remacs/remacs/issues/155 (pkg-config)
brew outdated pkg-config || brew upgrade pkg-config
# https://github.com/remacs/remacs/issues/886 (libxml2, macOS 10.14)
Expand Down
28 changes: 15 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ jobs:
fail-fast: false
matrix:
os:
- macos-10.15
- ubuntu-18.04
- macos-11
- macos-12
- ubuntu-20.04
- ubuntu-22.04
- windows-2019
- windows-2022
emacs-version:
- '25.3'
- '26.3'
- '27.2'
- '28.2'
- '29.2'
include:
# Older Emacs binaries for Windows don't have dynamic modules enabled.
- os: windows-2016
emacs-version: '27.2'
- os: windows-2019
emacs-version: '27.2'
- os: macos-11
emacs-version: '26.3'
- os: ubuntu-20.04
emacs-version: '26.3'
runs-on: ${{ matrix.os }}
steps:
- name: Set up Rust
Expand All @@ -41,19 +43,19 @@ jobs:
rustc -Vv
cargo -V
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Build
run: ./bin/build

- run: cargo test --all

- uses: purcell/setup-emacs@v3.0
- uses: purcell/setup-emacs@v6.0
if: runner.os != 'Windows'
with:
version: ${{ matrix.emacs-version }}

- uses: jcs090218/setup-emacs-windows@v4
- uses: jcs090218/setup-emacs-windows@master
if: runner.os == 'Windows'
with:
version: ${{ matrix.emacs-version }}
Expand All @@ -70,7 +72,7 @@ jobs:
rustc -Vv
cargo -V
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Build
run: ./bin/build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/shell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
build:
runs-on: ${{ github.event.inputs.platform }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.revision }}
- uses: mxschmitt/action-tmate@v3
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]
- Upgraded to Rust 2021 edition.
- This also raised the minimum supported Rust version to 1.56.
- Added support for Rust's non-zero integer types.

## [0.18.0] - 2021-09-26
- Eliminated the build-time dependency on LLVM by putting the raw Rust bindings in source, instead of generating them at build time. This would also make builds faster.
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "emacs"
version = "0.18.0"
edition = "2018"
edition = "2021"
description = "Rust library for creating Emacs's dynamic modules"
homepage = "https://github.com/ubolonton/emacs-module-rs"
documentation = "https://ubolonton.github.io/emacs-module-rs/"
Expand Down Expand Up @@ -37,6 +37,7 @@ rustc_version = "0.2.3"
default = []
utf-8-validation = []
lossy-integer-conversion = []
nonzero-integer-conversion = []
# This feature is intended as a workaround when building on new untested platforms. If the crate
# cannot be built without this feature, please report the issue at
# https://github.com/ubolonton/emacs-module-rs/issues/new.
Expand Down
27 changes: 14 additions & 13 deletions bin/build.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
$here = $PSScriptRoot
$project_root = (Get-Item $here).Parent.FullName

$target = $args[0]
if ($target -eq "release") {
$extra = "--release"
} else {
$target = "debug"
$extra = ""
}

$module_dir = "$project_root\target\$target"

Push-Location $project_root

cargo build --all $extra

Pop-Location
try {
switch ($target) {
'release' {
$module_dir = "$project_root\target\release"
cargo build --all --release
}
default {
$module_dir = "$project_root\target\debug"
cargo build --all
}
}
} finally {
Pop-Location
}

Copy-Item $module_dir\emacs_rs_module.dll $module_dir\rs-module.dll
Copy-Item $module_dir\test_module.dll $module_dir\t.dll
7 changes: 5 additions & 2 deletions bin/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ $module_dir = "$project_root\target\$target"

if ($args[0] -eq "watch") {
Push-Location $project_root
cargo watch -s "powershell bin\build.ps1" -s "powershell bin\test.ps1"
Pop-Location
try {
cargo watch -s "powershell bin\build.ps1" -s "powershell bin\test.ps1"
} finally {
Pop-Location
}
} else {
# XXX: It seems that Emacs writes to stderr, so PowerShell thinks it's an error. Redirecting to
# stdout alone doesn't help, because it's the processed stderr, which contain error records, not
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use rustc_version::{version, Version};

fn main() {
let version = version().unwrap();
if version < Version::parse("1.45.0").unwrap() {
eprintln!("emacs-module-rs requires rustc 1.45.0 or newer, got {}", version);
if version < Version::parse("1.56.0").unwrap() {
eprintln!("emacs-module-rs requires rustc 1.56.0 or newer, got {}", version);
exit(1);
}
}
2 changes: 1 addition & 1 deletion guide/src/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
`emacs-module-rs` provides high-level Rust binding and tools to write Emacs's dynamic modules. It is easy to use if you know either Rust or Emacs.

It currently supports:
- Stable Rust 1.45+.
- Stable Rust 1.56+.
- Emacs 25 or above, built with module support.
- macOS, Linux, Windows.

Expand Down
6 changes: 6 additions & 0 deletions guide/src/type-conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ To disable this behavior, use the `lossy-integer-conversion` feature:
features = ["lossy-integer-conversion"]
```

Support for Rust's `NonZero` integer types is disabled by default. To enable it, use the `nonzero-integer-conversion` feature:
```toml
[dependencies.emacs]
features = ["nonzero-integer-conversion"]
```

## Strings

By default, no utf-8 validation is done when converting Lisp strings into Rust strings, because the string data returned by Emacs is guaranteed to be valid utf-8 sequence. If you think you've otherwise encountered an Emacs bug, utf-8 validation can be enabled through a feature:
Expand Down
64 changes: 62 additions & 2 deletions src/types/integer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::convert::TryInto;

use super::*;

impl FromLisp<'_> for i64 {
Expand Down Expand Up @@ -37,6 +35,42 @@ int_from_lisp!(u32);
int_from_lisp!(u64);
int_from_lisp!(usize);

// -------------------------------------------------------------------------------------------------

macro_rules! nonzero_int_from_lisp {
($name:ident($primitive:ident)) => {
impl FromLisp<'_> for std::num::$name {
#[cfg(not(feature = "lossy-integer-conversion"))]
fn from_lisp(value: Value<'_>) -> Result<std::num::$name> {
let i: i64 = value.into_rust()?;
let i: $primitive = i.try_into()?;
Ok(i.try_into()?)
}

#[cfg(feature = "lossy-integer-conversion")]
fn from_lisp(value: Value<'_>) -> Result<std::num::$name> {
let i: i64 = value.into_rust()?;
let i: $primitive = i as $primitive;
Ok(i.try_into()?)
}
}
}
}

nonzero_int_from_lisp!(NonZeroU8(u8));
nonzero_int_from_lisp!(NonZeroU16(u16));
nonzero_int_from_lisp!(NonZeroU32(u32));
nonzero_int_from_lisp!(NonZeroU64(u64));
nonzero_int_from_lisp!(NonZeroUsize(usize));

nonzero_int_from_lisp!(NonZeroI8(i8));
nonzero_int_from_lisp!(NonZeroI16(i16));
nonzero_int_from_lisp!(NonZeroI32(i32));
nonzero_int_from_lisp!(NonZeroI64(i64));
nonzero_int_from_lisp!(NonZeroIsize(isize));

// -------------------------------------------------------------------------------------------------

impl IntoLisp<'_> for i64 {
fn into_lisp(self, env: &Env) -> Result<Value<'_>> {
unsafe_raw_call_value_unprotected!(env, make_integer, self)
Expand Down Expand Up @@ -83,3 +117,29 @@ int_into_lisp!(isize, lossless);
int_into_lisp!(u64, lossless);
#[cfg(not(feature = "lossy-integer-conversion"))]
int_into_lisp!(usize, lossless);

// -------------------------------------------------------------------------------------------------

macro_rules! nonzero_int_into_lisp {
($name:ident) => {
#[cfg(feature = "nonzero-integer-conversion")]
impl IntoLisp<'_> for std::num::$name {
#[inline]
fn into_lisp(self, env: &Env) -> Result<Value<'_>> {
self.get().into_lisp(env)
}
}
};
}

nonzero_int_into_lisp!(NonZeroU8);
nonzero_int_into_lisp!(NonZeroU16);
nonzero_int_into_lisp!(NonZeroU32);
nonzero_int_into_lisp!(NonZeroU64);
nonzero_int_into_lisp!(NonZeroUsize);

nonzero_int_into_lisp!(NonZeroI8);
nonzero_int_into_lisp!(NonZeroI16);
nonzero_int_into_lisp!(NonZeroI32);
nonzero_int_into_lisp!(NonZeroI64);
nonzero_int_into_lisp!(NonZeroIsize);

0 comments on commit 5a1c4ab

Please sign in to comment.