From 5105b4c6236b5e4d010b3ee550d8561e466dac3d Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Sat, 19 Nov 2022 14:09:03 +1000 Subject: [PATCH] Change xcoff to be an unstable feature The xcoff feature needs further work before being ready for release. Also, the default resolver can be changed to "2" now that the MSRV is at least 1.51. This works better with features in workspaces. --- .github/workflows/rust.yml | 6 ++++-- Cargo.toml | 16 ++++++++++------ crates/examples/Cargo.toml | 2 ++ crates/examples/tests/testfiles.rs | 25 ++++++++++++++++--------- src/lib.rs | 3 +++ 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0e02c551..ba020b53 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -25,7 +25,9 @@ jobs: rustup install ${{matrix.rust_channel}} rustup default ${{matrix.rust_channel}} - name: Test debug - run: cargo test --verbose --features all + run: | + cargo test --verbose --features all + cargo test --verbose --features unstable-all - name: Test release run: cargo test --verbose --features all --release @@ -42,7 +44,7 @@ jobs: - run: cargo build --no-default-features --features read_core,write_core,macho - run: cargo build --no-default-features --features read_core,pe - run: cargo build --no-default-features --features read_core,wasm - - run: cargo build --no-default-features --features read_core,xcoff + - run: cargo build --no-default-features --features read_core,xcoff,unstable - run: cargo build --no-default-features --features doc cross: diff --git a/Cargo.toml b/Cargo.toml index 1717a981..ca07ab74 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [package] name = "object" -# Note: disable resolver in workspace setting before releases. version = "0.29.0" edition = "2018" exclude = ["/.github", "/testfiles"] @@ -32,8 +31,8 @@ alloc = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-all # Core read support. You will need to enable some file formats too. read_core = [] -# Read support for all file formats (including unaligned files). -read = ["read_core", "archive", "coff", "elf", "macho", "pe", "unaligned", "xcoff"] +# Read support for most file formats (including unaligned files). +read = ["read_core", "archive", "coff", "elf", "macho", "pe", "unaligned"] # Core write support. You will need to enable some file formats too. write_core = ["crc32fast", "indexmap", "hashbrown"] # Core write support with libstd features. You will need to enable some file formats too. @@ -65,7 +64,6 @@ elf = [] macho = [] pe = ["coff"] wasm = ["wasmparser"] -xcoff = [] #======================================= # By default, support all read features. @@ -85,9 +83,15 @@ cargo-all = [] doc = [ "read_core", "write_std", "std", "compression", - "archive", "coff", "elf", "macho", "pe", "wasm", "xcoff" + "archive", "coff", "elf", "macho", "pe", "wasm", ] +#======================================= +# Unstable features. Breaking changes in these features will not affect versioning. +unstable = [] +xcoff = [] +unstable-all = ["all", "unstable", "xcoff"] + #======================================= # Internal feature, only used when building as part of libstd, not part of the # stable interface of this crate. @@ -96,4 +100,4 @@ rustc-dep-of-std = ['core', 'compiler_builtins', 'alloc', 'memchr/rustc-dep-of-s [workspace] members = ["crates/examples"] default-members = [".", "crates/examples"] -#resolver = "2" +resolver = "2" diff --git a/crates/examples/Cargo.toml b/crates/examples/Cargo.toml index 312d50fb..19d9edb3 100644 --- a/crates/examples/Cargo.toml +++ b/crates/examples/Cargo.toml @@ -12,6 +12,8 @@ glob = "0.3" [features] read = ["object/read"] +wasm = ["object/wasm"] +xcoff = ["object/xcoff"] default = ["read"] [[bin]] diff --git a/crates/examples/tests/testfiles.rs b/crates/examples/tests/testfiles.rs index dc3f9ac9..fc105452 100644 --- a/crates/examples/tests/testfiles.rs +++ b/crates/examples/tests/testfiles.rs @@ -6,14 +6,18 @@ use std::io::Write; use std::path::PathBuf; use std::{env, fs}; -#[cfg(feature = "wasm")] -fn skip_wasm_test_if_unsupport(_: &PathBuf) -> bool { - true -} +const DISABLED_TEST_DIRS: &[&'static str] = &[ + #[cfg(not(feature = "wasm"))] + "wasm", + #[cfg(not(feature = "xcoff"))] + "xcoff", +]; -#[cfg(not(feature = "wasm"))] -fn skip_wasm_test_if_unsupport(path: &PathBuf) -> bool { - path.extension().and_then(OsStr::to_str) != Some("wasm") +fn test_dir_filter(path: &PathBuf) -> bool { + match path.file_name().and_then(OsStr::to_str) { + Some(dir) => !DISABLED_TEST_DIRS.contains(&dir), + None => true, + } } #[test] @@ -22,12 +26,15 @@ fn testfiles() { env::set_current_dir("../..").unwrap(); let mut fail = false; - for dir in glob::glob("testfiles/*").unwrap().filter_map(Result::ok) { + for dir in glob::glob("testfiles/*") + .unwrap() + .filter_map(Result::ok) + .filter(test_dir_filter) + { let dir = dir.to_str().unwrap(); for path in glob::glob(&format!("{}/*", dir)) .unwrap() .filter_map(Result::ok) - .filter(skip_wasm_test_if_unsupport) { let path = path.to_str().unwrap(); if glob::glob(&format!("crates/examples/{}.*", path)) diff --git a/src/lib.rs b/src/lib.rs index 40a610b1..40f17c01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,6 +73,9 @@ #[cfg(feature = "cargo-all")] compile_error!("'--all-features' is not supported; use '--features all' instead"); +#[cfg(all(feature = "xcoff", not(feature = "unstable")))] +compile_error!("'xcoff` is an unstable feature; enable 'unstable' as well"); + #[cfg(any(feature = "read_core", feature = "write_core"))] #[allow(unused_imports)] #[macro_use]