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

No CMake required for non-FIPS #317

Merged
merged 29 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8329702
Setup for build w/o CMake
justsmth Apr 2, 2024
c4a10d2
Symbols from macos-13-xlarge
Apr 3, 2024
5e8f145
Symbols from ubuntu-latest
Apr 3, 2024
b9707e2
Symbols from macos-12
Apr 3, 2024
1d90cf4
Symbols for i686-unknown-linux-gnu
Apr 3, 2024
fc04d44
Symbols for aarch64-unknown-linux-gnu
Apr 3, 2024
dcfcae6
Symbols for x86_64-unknown-linux-musl
Apr 3, 2024
25b82c2
Symbols for aarch64-unknown-linux-musl
Apr 3, 2024
f551488
Generated headers
Apr 3, 2024
9d776c9
Generated bindings from macos-13-xlarge
Apr 3, 2024
24cc0c6
Generated bindings from ubuntu-latest
Apr 3, 2024
0056ffe
Generated bindings from macos-12
Apr 3, 2024
38709b3
Generated bindings for i686-unknown-linux-gnu
Apr 3, 2024
50dff8d
Generated bindings for aarch64-unknown-linux-gnu
Apr 3, 2024
247c3e5
Generated bindings for x86_64-unknown-linux-musl
Apr 3, 2024
b492a7a
Generated bindings for aarch64-unknown-linux-musl
Apr 3, 2024
6be0a15
Collected source files from macos-13-xlarge
Apr 3, 2024
b1dc043
Collected source files from ubuntu-latest
Apr 3, 2024
4892faf
Collected source files from macos-12
Apr 3, 2024
bcd394c
Collected source files for x86_64-unknown-linux-musl
Apr 3, 2024
940fb65
Collected source files for i686-unknown-linux-gnu
Apr 3, 2024
adb3667
Collected source files for aarch64-unknown-linux-gnu
Apr 3, 2024
85f9c5e
Collected source files for aarch64-unknown-linux-musl
Apr 3, 2024
8a5b0ef
Make clippy happy
justsmth Apr 3, 2024
243bc4e
Fix MSRV
justsmth Apr 3, 2024
9f051fb
Include compiler checks
justsmth Apr 3, 2024
8a069b5
Better align sys-crate builder/main.rs
justsmth Apr 3, 2024
e2423f2
Per PR feedback
justsmth Apr 5, 2024
9baf363
Per PR feedback; add some comments/documentation
justsmth Apr 10, 2024
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
41 changes: 41 additions & 0 deletions .github/workflows/sys-bindings-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,44 @@ jobs:
cross test -p aws-lc-sys --features bindgen,ssl --target ${{ matrix.target }}
- name: Commit & Push changes
run: ./scripts/ci/ci_add_commit_rebase_push.sh "Generated bindings for ${{ matrix.target }}"
collect-src-and-commit:
needs: generate-bindings-and-commit
if: github.repository == 'aws/aws-lc-rs'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-12, macos-13-xlarge ]
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
ref: ${{ github.ref_name }}
- uses: dtolnay/rust-toolchain@stable
- name: Install current Bash on macOS
if: runner.os == 'macOS'
run: brew install bash coreutils
- name: Collect source from ${{ matrix.os }}
run: ./scripts/build/collect_build_src.sh
- name: Commit & Push changes
run: ./scripts/ci/ci_add_commit_rebase_push.sh "Collected source files from ${{ matrix.os }}"
collect-cross-src-and-commit:
needs: generate-cross-bindings-and-commit
if: github.repository == 'aws/aws-lc-rs'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [ aarch64-unknown-linux-gnu, i686-unknown-linux-gnu, aarch64-unknown-linux-musl, x86_64-unknown-linux-musl ]
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
ref: ${{ github.ref_name }}
- uses: dtolnay/rust-toolchain@stable
- name: Install cross
run: cargo install cross --locked --git https://github.com/cross-rs/cross
- name: Collect source for ${{ matrix.target }}
run: ./scripts/build/collect_build_src.sh -t ${{ matrix.target }}
- name: Commit & Push changes
run: ./scripts/ci/ci_add_commit_rebase_push.sh "Collected source files for ${{ matrix.target }}"
2 changes: 1 addition & 1 deletion Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ dockerfile = "./docker/linux-cross/Dockerfile"
[build.env]
passthrough = [
"AWS_LC_SYS_INTERNAL_NO_PREFIX", "AWS_LC_RUST_INTERNAL_BINDGEN", "AWS_LC_FIPS_SYS_INTERNAL_NO_PREFIX", "GOPROXY",
"AWS_LC_FIPS_SYS_STATIC", "AWS_LC_SYS_STATIC"
"AWS_LC_FIPS_SYS_STATIC", "AWS_LC_SYS_STATIC", "AWS_LC_SYS_CMAKE_BUILDER", "AWS_LC_SYS_CC_SRC_COLLECTOR"
justsmth marked this conversation as resolved.
Show resolved Hide resolved
]
8 changes: 4 additions & 4 deletions aws-lc-fips-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn test_perl_command() -> bool {
fn test_go_command() -> bool {
let result = test_command("go".as_ref(), &["version".as_ref()]);
if !result.status && result.executed {
eprintln!("Go stdout:\n--------\n{}\n--------", result.output);
eprintln!("Go stdout:\n--------\n{}\n--------", result.stdout);
}
result.status
}
Expand Down Expand Up @@ -166,11 +166,11 @@ impl CmakeBuilder {
let script_path = self.manifest_dir.join("builder").join("printenv.bat");
let result = test_command(script_path.as_os_str(), &[]);
if !result.status {
eprintln!("{}", result.output);
eprintln!("{}", result.stdout);
return Err("Failed to run vcvarsall.bat.".to_owned());
}
eprintln!("{}", result.output);
let lines = result.output.lines();
eprintln!("{}", result.stdout);
let lines = result.stdout.lines();
for line in lines {
if let Some((var, val)) = line.split_once('=') {
map.insert(var.to_string(), val.to_string());
Expand Down
164 changes: 87 additions & 77 deletions aws-lc-fips-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,39 +130,43 @@ fn prefix_string() -> String {
format!("aws_lc_fips_{}", VERSION.to_string().replace('.', "_"))
}

#[cfg(any(
feature = "bindgen",
not(all(
any(target_arch = "x86_64", target_arch = "aarch64"),
any(target_os = "linux", target_os = "macos"),
any(target_env = "gnu", target_env = "musl", target_env = "")
))
))]
#[cfg(feature = "bindgen")]
fn target_platform_prefix(name: &str) -> String {
format!("{}_{}", target().replace('-', "_"), name)
}

pub(crate) struct TestCommandResult {
output: Box<str>,
status: bool,
#[allow(dead_code)]
stderr: Box<str>,
#[allow(dead_code)]
stdout: Box<str>,
executed: bool,
status: bool,
}

const MAX_CMD_OUTPUT_SIZE: usize = 1 << 12;
fn test_command(executable: &OsStr, args: &[&OsStr]) -> TestCommandResult {
if let Ok(result) = Command::new(executable).args(args).output() {
let output = String::from_utf8(result.stdout)
if let Ok(mut result) = Command::new(executable).args(args).output() {
result.stderr.truncate(MAX_CMD_OUTPUT_SIZE);
let stderr = String::from_utf8(result.stderr)
.unwrap_or_default()
.into_boxed_str();
result.stdout.truncate(MAX_CMD_OUTPUT_SIZE);
let stdout = String::from_utf8(result.stdout)
.unwrap_or_default()
.into_boxed_str();
return TestCommandResult {
output,
status: result.status.success(),
stderr,
stdout,
executed: true,
status: result.status.success(),
};
}
TestCommandResult {
output: String::new().into_boxed_str(),
status: false,
stderr: String::new().into_boxed_str(),
stdout: String::new().into_boxed_str(),
executed: false,
status: false,
}
}

Expand Down Expand Up @@ -249,95 +253,101 @@ fn current_dir() -> PathBuf {
std::env::current_dir().unwrap()
}

macro_rules! cfg_bindgen_platform {
($binding:ident, $target:literal, $additional:expr) => {
let $binding = {
(target() == $target && $additional)
.then(|| {
emit_rustc_cfg(&$target.replace('-', "_"));
true
})
.unwrap_or(false)
};
};
fn get_builder(prefix: &Option<String>, manifest_dir: &Path, out_dir: &Path) -> Box<dyn Builder> {
Box::new(CmakeBuilder::new(
manifest_dir.to_path_buf(),
out_dir.to_path_buf(),
prefix.clone(),
OutputLibType::default(),
))
}

trait Builder {
fn check_dependencies(&self) -> Result<(), String>;
fn build(&self) -> Result<(), String>;
}

#[allow(clippy::too_many_lines)]
fn main() {
let is_internal_no_prefix =
env_var_to_bool("AWS_LC_FIPS_SYS_INTERNAL_NO_PREFIX").unwrap_or(false);
let is_internal_generate = env_var_to_bool("AWS_LC_RUST_INTERNAL_BINDGEN").unwrap_or(false);
let mut is_bindgen_required =
is_internal_no_prefix || is_internal_generate || cfg!(feature = "bindgen");

let pregenerated = !is_bindgen_required || is_internal_generate;

cfg_bindgen_platform!(
x86_64_unknown_linux_gnu,
"x86_64-unknown-linux-gnu",
pregenerated
);
cfg_bindgen_platform!(
aarch64_unknown_linux_gnu,
"aarch64-unknown-linux-gnu",
pregenerated
);
cfg_bindgen_platform!(
x86_64_unknown_linux_musl,
"x86_64-unknown-linux-musl",
pregenerated
);
cfg_bindgen_platform!(
aarch64_unknown_linux_musl,
"aarch64-unknown-linux-musl",
pregenerated
);
cfg_bindgen_platform!(x86_64_apple_darwin, "x86_64-apple-darwin", pregenerated);
cfg_bindgen_platform!(aarch64_apple_darwin, "aarch64-apple-darwin", pregenerated);

if !(x86_64_unknown_linux_gnu
|| aarch64_unknown_linux_gnu
|| x86_64_unknown_linux_musl
|| aarch64_unknown_linux_musl
|| x86_64_apple_darwin
|| aarch64_apple_darwin)
{
is_bindgen_required = true;
static mut PREGENERATED: bool = false;
static mut AWS_LC_SYS_INTERNAL_NO_PREFIX: bool = false;
static mut AWS_LC_RUST_INTERNAL_BINDGEN: bool = false;

fn initialize() {
unsafe {
AWS_LC_SYS_INTERNAL_NO_PREFIX =
env_var_to_bool("AWS_LC_SYS_INTERNAL_NO_PREFIX").unwrap_or(false);
AWS_LC_RUST_INTERNAL_BINDGEN =
env_var_to_bool("AWS_LC_RUST_INTERNAL_BINDGEN").unwrap_or(false);
}

if is_internal_generate() || !has_bindgen_feature() {
let target = target();
let supported_platform = match target.as_str() {
"x86_64-unknown-linux-gnu"
| "aarch64-unknown-linux-gnu"
| "x86_64-unknown-linux-musl"
| "aarch64-unknown-linux-musl"
| "x86_64-apple-darwin"
| "aarch64-apple-darwin" => Some(target),
_ => None,
};
if let Some(platform) = supported_platform {
emit_rustc_cfg(platform.as_str());
unsafe {
PREGENERATED = true;
}
}
}
}

fn is_bindgen_required() -> bool {
is_internal_no_prefix()
|| is_internal_generate()
|| has_bindgen_feature()
|| !has_pregenerated()
}

fn is_internal_no_prefix() -> bool {
unsafe { AWS_LC_SYS_INTERNAL_NO_PREFIX }
}

fn is_internal_generate() -> bool {
unsafe { AWS_LC_RUST_INTERNAL_BINDGEN }
}

fn has_bindgen_feature() -> bool {
cfg!(feature = "bindgen")
}

fn has_pregenerated() -> bool {
unsafe { PREGENERATED }
}

fn main() {
initialize();

let manifest_dir = current_dir();
let manifest_dir = dunce::canonicalize(Path::new(&manifest_dir)).unwrap();
let prefix_str = prefix_string();
let prefix = if is_internal_no_prefix {
let prefix = if is_internal_no_prefix() {
None
} else {
Some(prefix_str)
};

let builder = CmakeBuilder::new(
manifest_dir.clone(),
out_dir(),
prefix.clone(),
OutputLibType::default(),
);
let builder = get_builder(&prefix, &manifest_dir, &out_dir());

builder.check_dependencies().unwrap();

#[allow(unused_assignments)]
let mut bindings_available = false;
if is_internal_generate {
if is_internal_generate() {
#[cfg(feature = "bindgen")]
{
let src_bindings_path = Path::new(&manifest_dir).join("src");
generate_src_bindings(&manifest_dir, prefix, &src_bindings_path);
bindings_available = true;
}
} else if is_bindgen_required {
} else if is_bindgen_required() {
#[cfg(any(
feature = "bindgen",
not(all(
Expand Down
4 changes: 3 additions & 1 deletion aws-lc-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ regex-automata = "~0.3.9"
regex-syntax = "~0.7.5"
# Pinned to avoid build failure in older versions
proc-macro2 = "1.0.60"
# Pinned dependency to preserve MSRV: ??? <= rust-version < 1.63.0
jobserver = "=0.1.26"

[package.metadata.cargo-udeps.ignore]
development = ["which", "home", "regex", "regex-automata", "regex-syntax", "proc-macro2"]
development = ["which", "home", "regex", "regex-automata", "regex-syntax", "proc-macro2", "jobserver"]
1 change: 1 addition & 0 deletions aws-lc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ bindgen = ["dep:bindgen"] # Generate the bindings on the targetted platform as a
cmake = "0.1.48"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does cmake have to be a part of build-dependencies?

dunce = "1.0"
fs_extra = "1.3"
cc = { version = "1.0.83", features = ["parallel"] }

[target.'cfg(any(all(any(target_arch = "x86_64", target_arch = "aarch64"), any(target_os = "linux", target_os = "macos"), any(target_env = "gnu", target_env = "musl", target_env = "")), all(target_arch = "i686", target_os = "linux", target_env = "gnu")))'.build-dependencies]
bindgen = { version = "0.69.2", optional = true }
Expand Down
Loading
Loading