Skip to content

Commit caa4df6

Browse files
committed
Prepare for publishing on crates.io.
1 parent f8bb867 commit caa4df6

File tree

5 files changed

+312
-21
lines changed

5 files changed

+312
-21
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build/
2+
pregenerated/
23
ssl/test/runner/runner
34
*.swp
45
*.swo

Cargo.toml

+245
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,251 @@ readme = "README.md"
99
repository = "https://github.com/briansmith/ring"
1010
version = "0.2.0"
1111

12+
exclude = [
13+
# The presence of .gitignore is used to differentiate non-packaged builds
14+
# from packaged builds in build.rs.
15+
".gitignore"
16+
]
17+
include = [
18+
"LICENSE",
19+
"Cargo.toml",
20+
21+
"Makefile",
22+
"mk/ring.mk",
23+
"mk/bottom_of_makefile.mk",
24+
"mk/top_of_makefile.mk",
25+
26+
"pregenerated/msvc-ring-asm-i686.lib",
27+
"pregenerated/msvc-ring-asm-x86_64.lib",
28+
29+
"ring.sln",
30+
"crypto/libring-asm.Windows.vcxproj",
31+
"crypto/libring-test.Windows.vcxproj",
32+
"crypto/libring.Windows.vcxproj",
33+
"mk/Common.props",
34+
"mk/Windows.props",
35+
"mk/WindowsTest.props",
36+
"mk/perlasm-msbuild.targets",
37+
"mk/perlasm-msbuild.xml",
38+
39+
"build.rs",
40+
41+
"src/aead/aead.rs",
42+
"src/aead/aes_gcm.rs",
43+
"src/aead/chacha20_poly1305.rs",
44+
"src/agreement.rs",
45+
"src/bssl.rs",
46+
"src/c.rs",
47+
"src/constant_time.rs",
48+
"src/der.rs",
49+
"src/digest/digest.rs",
50+
"src/digest/digest_tests.txt",
51+
"src/digest/sha1.rs",
52+
"src/ec/ec.rs",
53+
"src/ec/ecdh_tests.txt",
54+
"src/ec/ed25519_tests.txt",
55+
"src/ec/eddsa.rs",
56+
"src/ec/suite_b/ecdh.rs",
57+
"src/ec/suite_b/ecdsa.rs",
58+
"src/ec/suite_b/ecdsa_digest_scalar_tests.txt",
59+
"src/ec/suite_b/ecdsa_verify_tests.txt",
60+
"src/ec/suite_b/ops/ops.rs",
61+
"src/ec/suite_b/ops/p256.rs",
62+
"src/ec/suite_b/ops/p256_neg_tests.txt",
63+
"src/ec/suite_b/ops/p256_point_mul_base_tests.txt",
64+
"src/ec/suite_b/ops/p256_point_mul_tests.txt",
65+
"src/ec/suite_b/ops/p256_point_sum_tests.txt",
66+
"src/ec/suite_b/ops/p256_sum_tests.txt",
67+
"src/ec/suite_b/ops/p384.rs",
68+
"src/ec/suite_b/ops/p384_div_by_2_tests.txt",
69+
"src/ec/suite_b/ops/p384_neg_tests.txt",
70+
"src/ec/suite_b/ops/p384_point_mul_base_tests.txt",
71+
"src/ec/suite_b/ops/p384_point_mul_tests.txt",
72+
"src/ec/suite_b/ops/p384_point_sum_tests.txt",
73+
"src/ec/suite_b/ops/p384_sum_tests.txt",
74+
"src/ec/suite_b/private_key.rs",
75+
"src/ec/suite_b/public_key.rs",
76+
"src/ec/suite_b/suite_b.rs",
77+
"src/ec/suite_b/suite_b_public_key_tests.txt",
78+
"src/ec/x25519.rs",
79+
"src/error.rs",
80+
"src/hkdf.rs",
81+
"src/hkdf_tests.txt",
82+
"src/hmac.rs",
83+
"src/hmac_tests.txt",
84+
"src/init.rs",
85+
"src/lib.rs",
86+
"src/pbkdf2.rs",
87+
"src/pbkdf2_tests.txt",
88+
"src/polyfill.rs",
89+
"src/rand.rs",
90+
"src/rsa/rsa.rs",
91+
"src/rsa/rsa_pkcs1_sign_tests.txt",
92+
"src/rsa/rsa_pkcs1_verify_tests.txt",
93+
"src/rsa/signature_rsa_example_private_key.der",
94+
"src/rsa/signature_rsa_example_public_key.der",
95+
"src/signature.rs",
96+
"src/test.rs",
97+
"src/test_1_syntax_error_tests.txt",
98+
"src/test_1_tests.txt",
99+
"src/test_3_tests.txt",
100+
"crypto/aes/aes.c",
101+
"crypto/aes/aes_test.cc",
102+
"crypto/aes/asm/aes-586.pl",
103+
"crypto/aes/asm/aes-armv4.pl",
104+
"crypto/aes/asm/aes-x86_64.pl",
105+
"crypto/aes/asm/aesni-x86.pl",
106+
"crypto/aes/asm/aesni-x86_64.pl",
107+
"crypto/aes/asm/aesv8-armx.pl",
108+
"crypto/aes/asm/bsaes-armv7.pl",
109+
"crypto/aes/asm/bsaes-x86_64.pl",
110+
"crypto/aes/asm/vpaes-x86.pl",
111+
"crypto/aes/asm/vpaes-x86_64.pl",
112+
"crypto/bn/add.c",
113+
"crypto/bn/asm/armv4-mont.pl",
114+
"crypto/bn/asm/armv8-mont.pl",
115+
"crypto/bn/asm/rsaz-avx2.pl",
116+
"crypto/bn/asm/x86-mont.pl",
117+
"crypto/bn/asm/x86_64-mont.pl",
118+
"crypto/bn/asm/x86_64-mont5.pl",
119+
"crypto/bn/bn.c",
120+
"crypto/bn/bn_test.cc",
121+
"crypto/bn/bn_tests.txt",
122+
"crypto/bn/cmp.c",
123+
"crypto/bn/convert.c",
124+
"crypto/bn/ctx.c",
125+
"crypto/bn/div.c",
126+
"crypto/bn/exponentiation.c",
127+
"crypto/bn/gcd.c",
128+
"crypto/bn/generic.c",
129+
"crypto/bn/internal.h",
130+
"crypto/bn/montgomery.c",
131+
"crypto/bn/montgomery_inv.c",
132+
"crypto/bn/mul.c",
133+
"crypto/bn/random.c",
134+
"crypto/bn/rsaz_exp.c",
135+
"crypto/bn/rsaz_exp.h",
136+
"crypto/bn/shift.c",
137+
"crypto/chacha/asm/chacha-armv4.pl",
138+
"crypto/chacha/asm/chacha-armv8.pl",
139+
"crypto/chacha/asm/chacha-x86.pl",
140+
"crypto/chacha/asm/chacha-x86_64.pl",
141+
"crypto/chacha/chacha_test.cc",
142+
"crypto/cipher/e_aes.c",
143+
"crypto/cipher/internal.h",
144+
"crypto/cipher/test/aes_128_gcm_tests.txt",
145+
"crypto/cipher/test/aes_128_key_wrap_tests.txt",
146+
"crypto/cipher/test/aes_256_gcm_tests.txt",
147+
"crypto/cipher/test/aes_256_key_wrap_tests.txt",
148+
"crypto/cipher/test/chacha20_poly1305_old_tests.txt",
149+
"crypto/cipher/test/chacha20_poly1305_tests.txt",
150+
"crypto/cipher/test/cipher_test.txt",
151+
"crypto/constant_time_test.c",
152+
"crypto/cpu-aarch64-linux.c",
153+
"crypto/cpu-arm-linux.c",
154+
"crypto/cpu-arm.c",
155+
"crypto/cpu-intel.c",
156+
"crypto/crypto.c",
157+
"crypto/curve25519/asm/x25519-asm-arm.S",
158+
"crypto/curve25519/asm/x25519-asm-x86_64.S",
159+
"crypto/curve25519/curve25519.c",
160+
"crypto/curve25519/internal.h",
161+
"crypto/curve25519/x25519-x86_64.c",
162+
"crypto/ec/asm/ecp_nistz256-armv4.pl",
163+
"crypto/ec/asm/ecp_nistz256-armv8.pl",
164+
"crypto/ec/asm/ecp_nistz256-x86.pl",
165+
"crypto/ec/asm/ecp_nistz256-x86_64.pl",
166+
"crypto/ec/asm/p256-x86_64-asm.pl",
167+
"crypto/ec/ecp_nistz.c",
168+
"crypto/ec/ecp_nistz.h",
169+
"crypto/ec/ecp_nistz256.c",
170+
"crypto/ec/ecp_nistz256.h",
171+
"crypto/ec/ecp_nistz256_table.inl",
172+
"crypto/ec/ecp_nistz384.h",
173+
"crypto/ec/ecp_nistz384.inl",
174+
"crypto/ec/ecp_nistz384_mul.inl",
175+
"crypto/ec/gfp_constant_time.c",
176+
"crypto/ec/gfp_internal.h",
177+
"crypto/ec/gfp_limbs.inl",
178+
"crypto/ec/gfp_p256.c",
179+
"crypto/ec/gfp_p384.c",
180+
"crypto/ec/wnaf.c",
181+
"crypto/internal.h",
182+
"crypto/mem.c",
183+
"crypto/modes/asm/aesni-gcm-x86_64.pl",
184+
"crypto/modes/asm/ghash-armv4.pl",
185+
"crypto/modes/asm/ghash-x86.pl",
186+
"crypto/modes/asm/ghash-x86_64.pl",
187+
"crypto/modes/asm/ghashv8-armx.pl",
188+
"crypto/modes/gcm.c",
189+
"crypto/modes/internal.h",
190+
"crypto/perlasm/arm-xlate.pl",
191+
"crypto/perlasm/readme",
192+
"crypto/perlasm/x86asm.pl",
193+
"crypto/perlasm/x86gas.pl",
194+
"crypto/perlasm/x86masm.pl",
195+
"crypto/perlasm/x86nasm.pl",
196+
"crypto/perlasm/x86_64-xlate.pl",
197+
"crypto/poly1305/asm/poly1305-armv4.pl",
198+
"crypto/poly1305/asm/poly1305-armv8.pl",
199+
"crypto/poly1305/asm/poly1305-x86.pl",
200+
"crypto/poly1305/asm/poly1305-x86_64.pl",
201+
"crypto/poly1305/internal.h",
202+
"crypto/poly1305/poly1305.c",
203+
"crypto/poly1305/poly1305_test.cc",
204+
"crypto/poly1305/poly1305_test.txt",
205+
"crypto/rand/sysrand.c",
206+
"crypto/rsa/blinding.c",
207+
"crypto/rsa/internal.h",
208+
"crypto/rsa/rsa.c",
209+
"crypto/rsa/rsa_impl.c",
210+
"crypto/sha/asm/sha-armv8.pl",
211+
"crypto/sha/asm/sha-x86_64.pl",
212+
"crypto/sha/asm/sha256-586.pl",
213+
"crypto/sha/asm/sha256-armv4.pl",
214+
"crypto/sha/asm/sha256-armv8.pl",
215+
"crypto/sha/asm/sha256-x86_64.pl",
216+
"crypto/sha/asm/sha512-586.pl",
217+
"crypto/sha/asm/sha512-armv4.pl",
218+
"crypto/sha/asm/sha512-armv8.pl",
219+
"crypto/sha/asm/sha512-x86_64.pl",
220+
"crypto/test/bn_test_convert.c",
221+
"crypto/test/bn_test_lib.h",
222+
"crypto/test/bn_test_util.h",
223+
"crypto/test/file_test.cc",
224+
"crypto/test/file_test.h",
225+
"crypto/test/scoped_types.h",
226+
"include/openssl/aes.h",
227+
"include/openssl/arm_arch.h",
228+
"include/openssl/base.h",
229+
"include/openssl/bn.h",
230+
"include/openssl/cpu.h",
231+
"include/openssl/err.h",
232+
"include/openssl/mem.h",
233+
"include/openssl/opensslconf.h",
234+
"include/openssl/rand.h",
235+
"include/openssl/rsa.h",
236+
"include/openssl/type_check.h",
237+
"examples/checkdigest.rs",
238+
"third-party/NIST/README.md",
239+
"third-party/NIST/sha256sums.txt",
240+
"third-party/NIST/SHAVS/SHA1LongMsg.rsp",
241+
"third-party/NIST/SHAVS/SHA1Monte.rsp",
242+
"third-party/NIST/SHAVS/SHA1ShortMsg.rsp",
243+
"third-party/NIST/SHAVS/SHA224LongMsg.rsp",
244+
"third-party/NIST/SHAVS/SHA224Monte.rsp",
245+
"third-party/NIST/SHAVS/SHA224ShortMsg.rsp",
246+
"third-party/NIST/SHAVS/SHA256LongMsg.rsp",
247+
"third-party/NIST/SHAVS/SHA256Monte.rsp",
248+
"third-party/NIST/SHAVS/SHA256ShortMsg.rsp",
249+
"third-party/NIST/SHAVS/SHA384LongMsg.rsp",
250+
"third-party/NIST/SHAVS/SHA384Monte.rsp",
251+
"third-party/NIST/SHAVS/SHA384ShortMsg.rsp",
252+
"third-party/NIST/SHAVS/SHA512LongMsg.rsp",
253+
"third-party/NIST/SHAVS/SHA512Monte.rsp",
254+
"third-party/NIST/SHAVS/SHA512ShortMsg.rsp",
255+
]
256+
12257
[lib]
13258
name = "ring"
14259

build.rs

+40-20
Original file line numberDiff line numberDiff line change
@@ -99,53 +99,62 @@ fn build_c_code(out_dir: &str) -> Result<(), std::env::VarError> {
9999

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

102-
let command_name;
103-
let args;
104102
if !use_msbuild {
105-
command_name = "make";
106103
// Environment variables |CC|, |CXX|, etc. will be inherited from this
107104
// process.
108105
let cmake_build_type = if disable_opt {
109106
"DEBUG"
110107
} else {
111108
"RELWITHDEBINFO"
112109
};
113-
args = vec![
110+
let args = vec![
114111
format!("-j{}", num_jobs),
115112
format!("TARGET={}", target_str),
116113
format!("CMAKE_BUILD_TYPE={}", cmake_build_type),
117114
format!("BUILD_PREFIX={}/", out_dir),
118115
];
116+
run_command_with_args("make", &args);
117+
119118
} else {
119+
// .gitignore isn't packaged, so if it exists then this is not a
120+
// packaged build. Otherwise, assume it is a packaged build, and use
121+
// the prepackaged libs so that we don't require Perl and Yasm being
122+
// installed.
123+
let use_prepackaged_asm = std::fs::metadata(".gitignore").is_err();
124+
120125
// TODO: This assumes that the package is being built under a
121126
// {VS2013,VS2015} {x86,x64} Native Tools Command Prompt. It would be
122127
// nice if we didn't require that to be the case. At least it should be
123128
// documented.
124-
command_name = "msbuild";
125-
let platform = match target_triple[0] {
129+
let arch = target_triple[0];
130+
let platform = match arch {
126131
"i686" => "Win32",
127132
"x86_64" => "x64",
128-
_ => panic!("unexpected ARCH: {}", target_triple[0])
133+
_ => panic!("unexpected ARCH: {}", arch)
129134
};
130135
let configuration = if disable_opt { "Debug" } else { "Release" };
131-
args = vec![
132-
format!("{}.sln", LIB_NAME),
136+
let args = vec![
133137
format!("/m:{}", num_jobs),
134138
format!("/p:Platform={}", platform),
135139
format!("/p:Configuration={}", configuration),
136140
format!("/p:OutRootDir={}/", out_dir),
137141
];
138-
139-
println!("cargo:rustc-link-lib=static={}-asm", LIB_NAME);
140-
}
141-
142-
if !std::process::Command::new(command_name)
143-
.args(&args)
144-
.status()
145-
.unwrap_or_else(|e| { panic!("failed to execute {}: {}",
146-
command_name, e); })
147-
.success() {
148-
panic!("{} execution failed", command_name);
142+
if !use_prepackaged_asm {
143+
run_command_with_args("msbuild", &args);
144+
println!("cargo:rustc-link-lib=static={}-asm", LIB_NAME);
145+
} else {
146+
let mut core_args = args.clone();
147+
core_args.push(String::from("crypto/libring.Windows.vcxproj"));
148+
run_command_with_args("msbuild", &core_args);
149+
150+
let mut test_args = args.clone();
151+
test_args.push(String::from("crypto/libring-test.Windows.vcxproj"));
152+
run_command_with_args("msbuild", &test_args);
153+
154+
println!("cargo:rustc-link-search=native=pregenerated");
155+
println!("cargo:rustc-link-lib=static=msvc-{}-asm-{}", LIB_NAME,
156+
arch);
157+
}
149158
}
150159

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

162171
Ok(())
163172
}
173+
174+
fn run_command_with_args(command_name: &str, args: &Vec<String>) {
175+
if !std::process::Command::new(command_name)
176+
.args(&args)
177+
.status()
178+
.unwrap_or_else(|e| { panic!("failed to execute {}: {}",
179+
command_name, e); })
180+
.success() {
181+
panic!("{} execution failed", command_name);
182+
}
183+
}

crypto/libring-asm.Windows.vcxproj

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="GenerateAsm;Build" ToolsVersion="14.0"
2+
<Project DefaultTargets="Everything" ToolsVersion="14.0"
33
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
44
<PropertyGroup Label="Globals">
55
<ProjectGuid>{5A09BA1C-748F-40A2-B7F0-8108A08FE6A8}</ProjectGuid>
@@ -57,4 +57,20 @@
5757
</ItemDefinitionGroup>
5858
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
5959
<Import Project="..\mk\perlasm-msbuild.targets" />
60+
61+
<Target Name="CopyToPregenerated"
62+
Condition="'$(RING_PREGENERATED)' == 'GENERATE'"
63+
DependsOnTargets="GenerateAsm;Build">
64+
<PropertyGroup>
65+
<TargetNameSuffix
66+
Condition="'$(ProcessorArchitecture)' == 'x86'">i686</TargetNameSuffix>
67+
<TargetNameSuffix
68+
Condition="'$(ProcessorArchitecture)' == 'amd64'">x86_64</TargetNameSuffix>
69+
</PropertyGroup>
70+
<Makedir Directories="../pregenerated"/>
71+
<Copy SourceFiles="$(OutputPath)$(TargetName).lib"
72+
DestinationFiles="../pregenerated/msvc-$(TargetName)-$(TargetNameSuffix).lib"/>
73+
</Target>
74+
75+
<Target Name="Everything" DependsOnTargets="GenerateAsm;Build;CopyToPregenerated"/>
6076
</Project>

mk/package.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This only works on Windows, using MinGW.
2+
set -eux -o pipefail
3+
IFS=$'\n\t'
4+
5+
cargo clean
6+
rm -Rf pregenerated/msvc*.lib
7+
RING_PREGENERATED=GENERATE cargo build --target=x86_64-pc-windows-msvc
8+
RING_PREGENERATED=GENERATE cargo build --target=i686-pc-windows-msvc
9+
cargo package

0 commit comments

Comments
 (0)