Skip to content

Commit

Permalink
Support alpine via ???-unknown-linux-musl bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Jan 30, 2025
1 parent 99dbc3e commit e728d8a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
12 changes: 6 additions & 6 deletions aws-lc-sys/builder/cc_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ mod x86_64_unknown_linux_gnu;
mod x86_64_unknown_linux_musl;

use crate::{
cargo_env, emit_warning, env_var_to_bool, execute_command, get_crate_cflags, is_no_asm,
option_env, out_dir, requested_c_std, target, target_arch, target_env, target_os,
cargo_env, effective_target, emit_warning, env_var_to_bool, execute_command, get_crate_cflags,
is_no_asm, option_env, out_dir, requested_c_std, target, target_arch, target_env, target_os,
target_vendor, CStdRequested, OutputLibType,
};
use std::path::PathBuf;
Expand Down Expand Up @@ -78,7 +78,7 @@ impl PlatformConfig {

impl Default for PlatformConfig {
fn default() -> Self {
Self::default_for(&target()).unwrap()
Self::default_for(&effective_target()).unwrap()
}
}

Expand Down Expand Up @@ -394,12 +394,12 @@ impl crate::Builder for CcBuilder {
return Err("CcBuilder only supports static builds".to_string());
}

if PlatformConfig::default_for(&target()).is_none() {
return Err(format!("Platform not supported: {}", target()));
if PlatformConfig::default_for(&effective_target()).is_none() {
return Err(format!("Platform not supported: {}", effective_target()));
}

if Some(true) == env_var_to_bool("CARGO_FEATURE_SSL") {
return Err(format!("libssl not supported: {}", target()));
return Err(format!("cc_builder for libssl not supported"));
}

Ok(())
Expand Down
12 changes: 6 additions & 6 deletions aws-lc-sys/builder/cmake_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
use crate::cc_builder::CcBuilder;
use crate::OutputLib::{Crypto, RustWrapper, Ssl};
use crate::{
allow_prebuilt_nasm, cargo_env, emit_warning, execute_command, get_crate_cflags, is_crt_static,
is_no_asm, option_env, requested_c_std, target, target_arch, target_env, target_os,
target_underscored, target_vendor, test_nasm_command, use_prebuilt_nasm, CStdRequested,
OutputLibType,
allow_prebuilt_nasm, cargo_env, effective_target, emit_warning, execute_command,
get_crate_cflags, is_crt_static, is_no_asm, option_env, requested_c_std, target_arch,
target_env, target_os, target_underscored, target_vendor, test_nasm_command, use_prebuilt_nasm,
CStdRequested, OutputLibType,
};
use std::env;
use std::ffi::OsString;
Expand Down Expand Up @@ -215,7 +215,7 @@ impl CmakeBuilder {

if target_vendor() == "apple" && target_os().to_lowercase() == "ios" {
cmake_cfg.define("CMAKE_SYSTEM_NAME", "iOS");
if target().ends_with("-ios-sim") || target_arch() == "x86_64" {
if effective_target().ends_with("-ios-sim") || target_arch() == "x86_64" {
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphonesimulator");
} else {
cmake_cfg.define("CMAKE_OSX_SYSROOT", "iphoneos");
Expand Down Expand Up @@ -331,7 +331,7 @@ impl CmakeBuilder {
}
}

match target().as_str() {
match effective_target().as_str() {
"aarch64-unknown-linux-ohos" => {
cmake_cfg.define("OHOS_ARCH", "arm64-v8a");
}
Expand Down
19 changes: 14 additions & 5 deletions aws-lc-sys/builder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn prefix_string() -> String {

#[cfg(feature = "bindgen")]
fn target_platform_prefix(name: &str) -> String {
format!("{}_{}", target().replace('-', "_"), name)
format!("{}_{}", effective_target().replace('-', "_"), name)
}

pub(crate) struct TestCommandResult {
Expand Down Expand Up @@ -319,9 +319,18 @@ fn target() -> String {
cargo_env("TARGET")
}

fn effective_target() -> String {
let target = target();
match target.as_str() {
"x86_64-alpine-linux-musl" => "x86_64-unknown-linux-musl".to_string(),
"aarch64-alpine-linux-musl" => "aarch64-unknown-linux-musl".to_string(),
_ => target,
}
}

#[allow(unused)]
fn target_underscored() -> String {
target().replace('-', "_")
effective_target().replace('-', "_")
}

fn out_dir() -> PathBuf {
Expand Down Expand Up @@ -428,7 +437,7 @@ fn initialize() {
}

if !is_external_bindgen() && (is_pregenerating_bindings() || !has_bindgen_feature()) {
let target = target();
let target = effective_target();
let supported_platform = match target.as_str() {
"aarch64-apple-darwin"
| "aarch64-linux-android"
Expand Down Expand Up @@ -548,7 +557,7 @@ bindgen_available!(
if internal_bindgen_supported() && !is_external_bindgen() {
emit_warning(&format!(
"Generating bindings - internal bindgen. Platform: {}",
target()
effective_target()
));
let gen_bindings_path = out_dir().join("bindings.rs");
generate_bindings(manifest_dir, prefix, &gen_bindings_path);
Expand Down Expand Up @@ -764,7 +773,7 @@ fn invoke_external_bindgen(

emit_warning(&format!(
"Generating bindings - external bindgen. Platform: {}",
target()
effective_target()
));

let options = BindingOptions {
Expand Down
22 changes: 12 additions & 10 deletions docker/alpine-3.20/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ RUN apk add \
build-base \
busybox-suid \
clang-dev \
curl \
cargo \
curl \
cmake \
openssl-dev

Expand All @@ -17,12 +18,13 @@ USER satoshi
WORKDIR /home/satoshi
ENV CARGO_HTTP_MULTIPLEXING=false

RUN cd "${HOME}" && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > ./rustup.sh && \
chmod +x ./rustup.sh && \
./rustup.sh -y && \
. "${HOME}/.cargo/env" && \
echo '. "${HOME}/.cargo/env"' >> ${HOME}/.profile && \
cargo install --locked bindgen-cli && \
rustup component add rustfmt clippy && \
rm ./rustup.sh
# If needed, setup Rust environment for user
#RUN cd "${HOME}" && \
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > ./rustup.sh && \
# chmod +x ./rustup.sh && \
# ./rustup.sh -y && \
# . "${HOME}/.cargo/env" && \
# echo '. "${HOME}/.cargo/env"' >> ${HOME}/.profile && \
# cargo install --locked bindgen-cli && \
# rustup component add rustfmt clippy && \
# rm ./rustup.sh

0 comments on commit e728d8a

Please sign in to comment.