Skip to content

Commit

Permalink
Prepare for publishing on crates.io.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Aug 15, 2016
1 parent f8bb867 commit caa4df6
Show file tree
Hide file tree
Showing 5 changed files with 312 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
pregenerated/
ssl/test/runner/runner
*.swp
*.swo
Expand Down
245 changes: 245 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,251 @@ readme = "README.md"
repository = "https://github.com/briansmith/ring"
version = "0.2.0"

exclude = [
# The presence of .gitignore is used to differentiate non-packaged builds
# from packaged builds in build.rs.
".gitignore"
]
include = [
"LICENSE",
"Cargo.toml",

"Makefile",
"mk/ring.mk",
"mk/bottom_of_makefile.mk",
"mk/top_of_makefile.mk",

"pregenerated/msvc-ring-asm-i686.lib",
"pregenerated/msvc-ring-asm-x86_64.lib",

"ring.sln",
"crypto/libring-asm.Windows.vcxproj",
"crypto/libring-test.Windows.vcxproj",
"crypto/libring.Windows.vcxproj",
"mk/Common.props",
"mk/Windows.props",
"mk/WindowsTest.props",
"mk/perlasm-msbuild.targets",
"mk/perlasm-msbuild.xml",

"build.rs",

"src/aead/aead.rs",
"src/aead/aes_gcm.rs",
"src/aead/chacha20_poly1305.rs",
"src/agreement.rs",
"src/bssl.rs",
"src/c.rs",
"src/constant_time.rs",
"src/der.rs",
"src/digest/digest.rs",
"src/digest/digest_tests.txt",
"src/digest/sha1.rs",
"src/ec/ec.rs",
"src/ec/ecdh_tests.txt",
"src/ec/ed25519_tests.txt",
"src/ec/eddsa.rs",
"src/ec/suite_b/ecdh.rs",
"src/ec/suite_b/ecdsa.rs",
"src/ec/suite_b/ecdsa_digest_scalar_tests.txt",
"src/ec/suite_b/ecdsa_verify_tests.txt",
"src/ec/suite_b/ops/ops.rs",
"src/ec/suite_b/ops/p256.rs",
"src/ec/suite_b/ops/p256_neg_tests.txt",
"src/ec/suite_b/ops/p256_point_mul_base_tests.txt",
"src/ec/suite_b/ops/p256_point_mul_tests.txt",
"src/ec/suite_b/ops/p256_point_sum_tests.txt",
"src/ec/suite_b/ops/p256_sum_tests.txt",
"src/ec/suite_b/ops/p384.rs",
"src/ec/suite_b/ops/p384_div_by_2_tests.txt",
"src/ec/suite_b/ops/p384_neg_tests.txt",
"src/ec/suite_b/ops/p384_point_mul_base_tests.txt",
"src/ec/suite_b/ops/p384_point_mul_tests.txt",
"src/ec/suite_b/ops/p384_point_sum_tests.txt",
"src/ec/suite_b/ops/p384_sum_tests.txt",
"src/ec/suite_b/private_key.rs",
"src/ec/suite_b/public_key.rs",
"src/ec/suite_b/suite_b.rs",
"src/ec/suite_b/suite_b_public_key_tests.txt",
"src/ec/x25519.rs",
"src/error.rs",
"src/hkdf.rs",
"src/hkdf_tests.txt",
"src/hmac.rs",
"src/hmac_tests.txt",
"src/init.rs",
"src/lib.rs",
"src/pbkdf2.rs",
"src/pbkdf2_tests.txt",
"src/polyfill.rs",
"src/rand.rs",
"src/rsa/rsa.rs",
"src/rsa/rsa_pkcs1_sign_tests.txt",
"src/rsa/rsa_pkcs1_verify_tests.txt",
"src/rsa/signature_rsa_example_private_key.der",
"src/rsa/signature_rsa_example_public_key.der",
"src/signature.rs",
"src/test.rs",
"src/test_1_syntax_error_tests.txt",
"src/test_1_tests.txt",
"src/test_3_tests.txt",
"crypto/aes/aes.c",
"crypto/aes/aes_test.cc",
"crypto/aes/asm/aes-586.pl",
"crypto/aes/asm/aes-armv4.pl",
"crypto/aes/asm/aes-x86_64.pl",
"crypto/aes/asm/aesni-x86.pl",
"crypto/aes/asm/aesni-x86_64.pl",
"crypto/aes/asm/aesv8-armx.pl",
"crypto/aes/asm/bsaes-armv7.pl",
"crypto/aes/asm/bsaes-x86_64.pl",
"crypto/aes/asm/vpaes-x86.pl",
"crypto/aes/asm/vpaes-x86_64.pl",
"crypto/bn/add.c",
"crypto/bn/asm/armv4-mont.pl",
"crypto/bn/asm/armv8-mont.pl",
"crypto/bn/asm/rsaz-avx2.pl",
"crypto/bn/asm/x86-mont.pl",
"crypto/bn/asm/x86_64-mont.pl",
"crypto/bn/asm/x86_64-mont5.pl",
"crypto/bn/bn.c",
"crypto/bn/bn_test.cc",
"crypto/bn/bn_tests.txt",
"crypto/bn/cmp.c",
"crypto/bn/convert.c",
"crypto/bn/ctx.c",
"crypto/bn/div.c",
"crypto/bn/exponentiation.c",
"crypto/bn/gcd.c",
"crypto/bn/generic.c",
"crypto/bn/internal.h",
"crypto/bn/montgomery.c",
"crypto/bn/montgomery_inv.c",
"crypto/bn/mul.c",
"crypto/bn/random.c",
"crypto/bn/rsaz_exp.c",
"crypto/bn/rsaz_exp.h",
"crypto/bn/shift.c",
"crypto/chacha/asm/chacha-armv4.pl",
"crypto/chacha/asm/chacha-armv8.pl",
"crypto/chacha/asm/chacha-x86.pl",
"crypto/chacha/asm/chacha-x86_64.pl",
"crypto/chacha/chacha_test.cc",
"crypto/cipher/e_aes.c",
"crypto/cipher/internal.h",
"crypto/cipher/test/aes_128_gcm_tests.txt",
"crypto/cipher/test/aes_128_key_wrap_tests.txt",
"crypto/cipher/test/aes_256_gcm_tests.txt",
"crypto/cipher/test/aes_256_key_wrap_tests.txt",
"crypto/cipher/test/chacha20_poly1305_old_tests.txt",
"crypto/cipher/test/chacha20_poly1305_tests.txt",
"crypto/cipher/test/cipher_test.txt",
"crypto/constant_time_test.c",
"crypto/cpu-aarch64-linux.c",
"crypto/cpu-arm-linux.c",
"crypto/cpu-arm.c",
"crypto/cpu-intel.c",
"crypto/crypto.c",
"crypto/curve25519/asm/x25519-asm-arm.S",
"crypto/curve25519/asm/x25519-asm-x86_64.S",
"crypto/curve25519/curve25519.c",
"crypto/curve25519/internal.h",
"crypto/curve25519/x25519-x86_64.c",
"crypto/ec/asm/ecp_nistz256-armv4.pl",
"crypto/ec/asm/ecp_nistz256-armv8.pl",
"crypto/ec/asm/ecp_nistz256-x86.pl",
"crypto/ec/asm/ecp_nistz256-x86_64.pl",
"crypto/ec/asm/p256-x86_64-asm.pl",
"crypto/ec/ecp_nistz.c",
"crypto/ec/ecp_nistz.h",
"crypto/ec/ecp_nistz256.c",
"crypto/ec/ecp_nistz256.h",
"crypto/ec/ecp_nistz256_table.inl",
"crypto/ec/ecp_nistz384.h",
"crypto/ec/ecp_nistz384.inl",
"crypto/ec/ecp_nistz384_mul.inl",
"crypto/ec/gfp_constant_time.c",
"crypto/ec/gfp_internal.h",
"crypto/ec/gfp_limbs.inl",
"crypto/ec/gfp_p256.c",
"crypto/ec/gfp_p384.c",
"crypto/ec/wnaf.c",
"crypto/internal.h",
"crypto/mem.c",
"crypto/modes/asm/aesni-gcm-x86_64.pl",
"crypto/modes/asm/ghash-armv4.pl",
"crypto/modes/asm/ghash-x86.pl",
"crypto/modes/asm/ghash-x86_64.pl",
"crypto/modes/asm/ghashv8-armx.pl",
"crypto/modes/gcm.c",
"crypto/modes/internal.h",
"crypto/perlasm/arm-xlate.pl",
"crypto/perlasm/readme",
"crypto/perlasm/x86asm.pl",
"crypto/perlasm/x86gas.pl",
"crypto/perlasm/x86masm.pl",
"crypto/perlasm/x86nasm.pl",
"crypto/perlasm/x86_64-xlate.pl",
"crypto/poly1305/asm/poly1305-armv4.pl",
"crypto/poly1305/asm/poly1305-armv8.pl",
"crypto/poly1305/asm/poly1305-x86.pl",
"crypto/poly1305/asm/poly1305-x86_64.pl",
"crypto/poly1305/internal.h",
"crypto/poly1305/poly1305.c",
"crypto/poly1305/poly1305_test.cc",
"crypto/poly1305/poly1305_test.txt",
"crypto/rand/sysrand.c",
"crypto/rsa/blinding.c",
"crypto/rsa/internal.h",
"crypto/rsa/rsa.c",
"crypto/rsa/rsa_impl.c",
"crypto/sha/asm/sha-armv8.pl",
"crypto/sha/asm/sha-x86_64.pl",
"crypto/sha/asm/sha256-586.pl",
"crypto/sha/asm/sha256-armv4.pl",
"crypto/sha/asm/sha256-armv8.pl",
"crypto/sha/asm/sha256-x86_64.pl",
"crypto/sha/asm/sha512-586.pl",
"crypto/sha/asm/sha512-armv4.pl",
"crypto/sha/asm/sha512-armv8.pl",
"crypto/sha/asm/sha512-x86_64.pl",
"crypto/test/bn_test_convert.c",
"crypto/test/bn_test_lib.h",
"crypto/test/bn_test_util.h",
"crypto/test/file_test.cc",
"crypto/test/file_test.h",
"crypto/test/scoped_types.h",
"include/openssl/aes.h",
"include/openssl/arm_arch.h",
"include/openssl/base.h",
"include/openssl/bn.h",
"include/openssl/cpu.h",
"include/openssl/err.h",
"include/openssl/mem.h",
"include/openssl/opensslconf.h",
"include/openssl/rand.h",
"include/openssl/rsa.h",
"include/openssl/type_check.h",
"examples/checkdigest.rs",
"third-party/NIST/README.md",
"third-party/NIST/sha256sums.txt",
"third-party/NIST/SHAVS/SHA1LongMsg.rsp",
"third-party/NIST/SHAVS/SHA1Monte.rsp",
"third-party/NIST/SHAVS/SHA1ShortMsg.rsp",
"third-party/NIST/SHAVS/SHA224LongMsg.rsp",
"third-party/NIST/SHAVS/SHA224Monte.rsp",
"third-party/NIST/SHAVS/SHA224ShortMsg.rsp",
"third-party/NIST/SHAVS/SHA256LongMsg.rsp",
"third-party/NIST/SHAVS/SHA256Monte.rsp",
"third-party/NIST/SHAVS/SHA256ShortMsg.rsp",
"third-party/NIST/SHAVS/SHA384LongMsg.rsp",
"third-party/NIST/SHAVS/SHA384Monte.rsp",
"third-party/NIST/SHAVS/SHA384ShortMsg.rsp",
"third-party/NIST/SHAVS/SHA512LongMsg.rsp",
"third-party/NIST/SHAVS/SHA512Monte.rsp",
"third-party/NIST/SHAVS/SHA512ShortMsg.rsp",
]

[lib]
name = "ring"

Expand Down
60 changes: 40 additions & 20 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,53 +99,62 @@ fn build_c_code(out_dir: &str) -> Result<(), std::env::VarError> {

// TODO: deal with link-time-optimization flag.

let command_name;
let args;
if !use_msbuild {
command_name = "make";
// Environment variables |CC|, |CXX|, etc. will be inherited from this
// process.
let cmake_build_type = if disable_opt {
"DEBUG"
} else {
"RELWITHDEBINFO"
};
args = vec![
let args = vec![
format!("-j{}", num_jobs),
format!("TARGET={}", target_str),
format!("CMAKE_BUILD_TYPE={}", cmake_build_type),
format!("BUILD_PREFIX={}/", out_dir),
];
run_command_with_args("make", &args);

} else {
// .gitignore isn't packaged, so if it exists then this is not a
// packaged build. Otherwise, assume it is a packaged build, and use
// the prepackaged libs so that we don't require Perl and Yasm being
// installed.
let use_prepackaged_asm = std::fs::metadata(".gitignore").is_err();

// TODO: This assumes that the package is being built under a
// {VS2013,VS2015} {x86,x64} Native Tools Command Prompt. It would be
// nice if we didn't require that to be the case. At least it should be
// documented.
command_name = "msbuild";
let platform = match target_triple[0] {
let arch = target_triple[0];
let platform = match arch {
"i686" => "Win32",
"x86_64" => "x64",
_ => panic!("unexpected ARCH: {}", target_triple[0])
_ => panic!("unexpected ARCH: {}", arch)
};
let configuration = if disable_opt { "Debug" } else { "Release" };
args = vec![
format!("{}.sln", LIB_NAME),
let args = vec![
format!("/m:{}", num_jobs),
format!("/p:Platform={}", platform),
format!("/p:Configuration={}", configuration),
format!("/p:OutRootDir={}/", out_dir),
];

println!("cargo:rustc-link-lib=static={}-asm", LIB_NAME);
}

if !std::process::Command::new(command_name)
.args(&args)
.status()
.unwrap_or_else(|e| { panic!("failed to execute {}: {}",
command_name, e); })
.success() {
panic!("{} execution failed", command_name);
if !use_prepackaged_asm {
run_command_with_args("msbuild", &args);
println!("cargo:rustc-link-lib=static={}-asm", LIB_NAME);
} else {
let mut core_args = args.clone();
core_args.push(String::from("crypto/libring.Windows.vcxproj"));
run_command_with_args("msbuild", &core_args);

let mut test_args = args.clone();
test_args.push(String::from("crypto/libring-test.Windows.vcxproj"));
run_command_with_args("msbuild", &test_args);

println!("cargo:rustc-link-search=native=pregenerated");
println!("cargo:rustc-link-lib=static=msvc-{}-asm-{}", LIB_NAME,
arch);
}
}

let lib_path = Path::new(out_dir).join("lib");
Expand All @@ -161,3 +170,14 @@ fn build_c_code(out_dir: &str) -> Result<(), std::env::VarError> {

Ok(())
}

fn run_command_with_args(command_name: &str, args: &Vec<String>) {
if !std::process::Command::new(command_name)
.args(&args)
.status()
.unwrap_or_else(|e| { panic!("failed to execute {}: {}",
command_name, e); })
.success() {
panic!("{} execution failed", command_name);
}
}
18 changes: 17 additions & 1 deletion crypto/libring-asm.Windows.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="GenerateAsm;Build" ToolsVersion="14.0"
<Project DefaultTargets="Everything" ToolsVersion="14.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>{5A09BA1C-748F-40A2-B7F0-8108A08FE6A8}</ProjectGuid>
Expand Down Expand Up @@ -57,4 +57,20 @@
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Import Project="..\mk\perlasm-msbuild.targets" />

<Target Name="CopyToPregenerated"
Condition="'$(RING_PREGENERATED)' == 'GENERATE'"
DependsOnTargets="GenerateAsm;Build">
<PropertyGroup>
<TargetNameSuffix
Condition="'$(ProcessorArchitecture)' == 'x86'">i686</TargetNameSuffix>
<TargetNameSuffix
Condition="'$(ProcessorArchitecture)' == 'amd64'">x86_64</TargetNameSuffix>
</PropertyGroup>
<Makedir Directories="../pregenerated"/>
<Copy SourceFiles="$(OutputPath)$(TargetName).lib"
DestinationFiles="../pregenerated/msvc-$(TargetName)-$(TargetNameSuffix).lib"/>
</Target>

<Target Name="Everything" DependsOnTargets="GenerateAsm;Build;CopyToPregenerated"/>
</Project>
9 changes: 9 additions & 0 deletions mk/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This only works on Windows, using MinGW.
set -eux -o pipefail
IFS=$'\n\t'

cargo clean
rm -Rf pregenerated/msvc*.lib
RING_PREGENERATED=GENERATE cargo build --target=x86_64-pc-windows-msvc
RING_PREGENERATED=GENERATE cargo build --target=i686-pc-windows-msvc
cargo package

0 comments on commit caa4df6

Please sign in to comment.