0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

Add rust url crate. (#355)

This commit is contained in:
Ryan Dahl 2018-07-10 14:56:12 -04:00 committed by GitHub
parent e269d972d2
commit d160de7f44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 109 additions and 18 deletions

View file

@ -20,14 +20,20 @@ rust_executable("deno") {
]
}
rust_component("handlers") {
rust_staticlib("handlers") {
source_root = "src/handlers.rs"
extern = [ "$rust_build:libc" ]
extern = [
"$rust_build:libc",
"$rust_build:url",
]
}
rust_test("handlers_test") {
source_root = "src/handlers.rs"
extern = [ "$rust_build:libc" ]
extern = [
"$rust_build:libc",
"$rust_build:url",
]
}
executable("deno_cc") {
@ -39,7 +45,6 @@ executable("deno_cc") {
":handlers",
":libdeno",
":msg_cpp",
"//build_extra/rust:stdlib",
]
configs += [ ":deno_config" ]
}

View file

@ -1,23 +1,57 @@
import("rust.gni")
# Dependencies between third party crates is mapped out here manually. This is
# not so difficult and having it be tedious to add dependencies might help us
# avoid dependency hell later on.
# Versioning for third party rust crates is controlled in //gclient_config.py
# TODO(ry) Use Cargo for versioning?
# By compiling an empty file as crate-type=staticlib we get all the code
# for the rust stdlib, which are not included in the object file outputs
# of other libs.
rust_component("stdlib") {
crate_type = "staticlib"
# TODO(ry) This is not used and maybe should be removed along with empty.rs.
rust_staticlib("stdlib") {
source_root = "empty.rs"
if (current_os == "mac") {
libs = [ "resolv" ]
}
if (current_os == "win") {
libs = [ "userenv.lib" ]
}
}
crates = "//third_party/rust_crates"
rust_component("libc") {
source_root = "//third_party/rust_crates/libc/src/lib.rs"
cfg = [
"feature=\"default\"",
"feature=\"use_std\"",
source_root = "$crates/libc/src/lib.rs"
cfg = [ "feature=\"use_std\"" ]
}
rust_component("url") {
source_root = "$crates/url/src/lib.rs"
extern = [
":matches",
":idna",
":percent_encoding",
]
}
rust_component("percent_encoding") {
source_root = "$crates/url/percent_encoding/lib.rs"
}
rust_component("matches") {
source_root = "$crates/rust-std-candidates/matches/lib.rs"
}
rust_component("idna") {
source_root = "$crates/url/idna/src/lib.rs"
extern = [
":matches",
":unicode_bidi",
":unicode_normalization",
]
}
rust_component("unicode_bidi") {
source_root = "$crates/unicode-bidi/src/lib.rs"
extern = [ ":matches" ]
}
rust_component("unicode_normalization") {
source_root = "$crates/unicode-normalization/src/lib.rs"
}

View file

@ -107,6 +107,12 @@ template("run_rustc") {
"--extern",
"$name=" + rebase_path(rlib, root_build_dir),
]
# This is needed for transitive dependencies.
args += [
"-L",
"dependency=" + rebase_path(dir, root_build_dir),
]
}
}
}
@ -152,6 +158,26 @@ template("rust_component") {
}
}
template("rust_staticlib") {
rust_component(target_name) {
crate_type = "staticlib"
forward_variables_from(invoker,
[
"crate_name",
"extern",
"cfg",
"source_root",
"testonly",
])
if (current_os == "mac") {
libs = [ "resolv" ]
}
if (current_os == "win") {
libs = [ "userenv.lib" ]
}
}
}
template("rust_executable") {
bin_name = target_name + "_bin"
bin_label = ":" + bin_name

View file

@ -39,4 +39,27 @@ solutions = [{
'https://github.com/rust-lang/libc.git@8a85d662b90c14d458bc4ae9521a05564e20d7ae',
'name':
'rust_crates/libc'
}, {
'url':
'https://github.com/servo/rust-url.git@fbe5e50316105482dcd53d2dabb148c445a5f4cd',
'name':
'rust_crates/url'
}, {
# Needed for url.
'url':
'https://github.com/SimonSapin/rust-std-candidates.git@88a017b79ea146d6fde389c96982fc7518ba98bf',
'name':
'rust_crates/rust-std-candidates'
}, {
# Needed for url.
'url':
'https://github.com/servo/unicode-bidi.git@32c81729db0ac90289ebeca9e0d4886f264e724d',
'name':
'rust_crates/unicode-bidi'
}, {
# Needed for url.
'url':
'https://github.com/behnam/rust-unicode-normalization.git@3898e77b110246cb7243bf29b896c58d8975304a',
'name':
'rust_crates/unicode-normalization'
}]

View file

@ -1,9 +1,11 @@
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
// All rights reserved. MIT License.
extern crate libc;
extern crate url;
use libc::c_char;
use std::ffi::CStr;
use url::Url;
fn string_from_ptr(ptr: *const c_char) -> String {
let cstr = unsafe { CStr::from_ptr(ptr as *const i8) };
@ -11,8 +13,9 @@ fn string_from_ptr(ptr: *const c_char) -> String {
}
#[test]
fn test_example() {
assert_eq!(2 + 2, 4);
fn test_url() {
let issue_list_url = Url::parse("https://github.com/rust-lang").unwrap();
assert!(issue_list_url.scheme() == "https");
}
#[no_mangle]