Mark ab/6881855 as merged

Bug: 172690556
Change-Id: I28cb9d1e2c90642d9fb5c0193ebdb24f1250ccb8
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index a289ae4..358bf1b 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
 {
   "git": {
-    "sha1": "21c7cdb08ffc38ceb0b0f9e7038f88548c2ade94"
+    "sha1": "4ad1af8ae9d577562e5dc1280f222713a17e8cf2"
   }
 }
diff --git a/.github/workflows/libloading.yml b/.github/workflows/libloading.yml
index d315445..aa9b3f6 100644
--- a/.github/workflows/libloading.yml
+++ b/.github/workflows/libloading.yml
@@ -71,13 +71,15 @@
     steps:
       - uses: actions/checkout@v2
       - name: Add MSYS2 to the PATH
-        run: echo "::add-path::c:/msys64/bin"
+        run: echo "c:/msys64/bin" | Out-File -FilePath $env:GITHUB_PATH -Append
       - name: Add 32-bit mingw-w64 to the PATH
-        run: echo "::add-path::c:/msys64/mingw32/bin"
+        run: echo "c:/msys64/mingw32/bin" | Out-File -FilePath $env:GITHUB_PATH -Append
         if: startsWith(matrix.rust_target, 'i686')
       - name: Add 64-bit mingw-w64 to the PATH
-        run: echo "::add-path::c:/msys64/mingw64/bin"
+        run: echo "c:/msys64/mingw64/bin" | Out-File -FilePath $env:GITHUB_PATH -Append
         if: startsWith(matrix.rust_target, 'x86_64')
+      - name: Set TARGET variable
+        run: echo "TARGET=${{ matrix.rust_target}}" | Out-File -FilePath $env:GITHUB_ENV -Append
       - name: Install Rust nightly
         uses: actions-rs/toolchain@v1
         with:
diff --git a/Android.bp b/Android.bp
index a40bc5a..65aa6bb 100644
--- a/Android.bp
+++ b/Android.bp
@@ -5,17 +5,10 @@
     crate_name: "libloading",
     srcs: ["src/lib.rs"],
     edition: "2015",
-    flags: [
-        "--cfg mtsafe_dlerror",
-    ],
     rustlibs: [
         "libcfg_if",
     ],
-    // TODO: Cannot use libdl on Android host?
-    // shared_libs: [
-    //     "libdl",
-    // ],
 }
 
 // dependent_library ["feature_list"]
-//   cfg-if-0.1.10
+//   cfg-if-1.0.0
diff --git a/Cargo.toml b/Cargo.toml
index 41ad4e7..8dbb4d3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,9 +12,8 @@
 
 [package]
 name = "libloading"
-version = "0.6.3"
+version = "0.6.5"
 authors = ["Simonas Kazlauskas <libloading@kazlauskas.me>"]
-build = "build.rs"
 description = "A safer binding to platform’s dynamic library loading utilities"
 documentation = "https://docs.rs/libloading/"
 readme = "README.mkd"
@@ -31,7 +30,7 @@
 [dev-dependencies.static_assertions]
 version = "1.1"
 [target."cfg(unix)".dependencies.cfg-if]
-version = "0.1"
+version = "1"
 [target."cfg(windows)".dependencies.winapi]
 version = "0.3"
 features = ["winerror", "errhandlingapi", "libloaderapi"]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 1dfd507..23324db 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -3,7 +3,7 @@
 # When bumping
 # * Don’t forget to add an entry to `src/changelog.rs`
 # * If bumping a incompatible version, adjust documentation in `src/lib.rs`
-version = "0.6.3"
+version = "0.6.5"
 authors = ["Simonas Kazlauskas <libloading@kazlauskas.me>"]
 license = "ISC"
 repository = "https://github.com/nagisa/rust_libloading/"
@@ -12,7 +12,6 @@
 description = "A safer binding to platform’s dynamic library loading utilities"
 keywords = ["dlopen", "load", "shared", "dylib"]
 categories = ["api-bindings"]
-build = "build.rs"
 
 [target.'cfg(windows)'.dependencies.winapi]
 version = "0.3"
@@ -23,7 +22,7 @@
 ]
 
 [target.'cfg(unix)'.dependencies.cfg-if]
-version = "0.1"
+version = "1"
 
 [dev-dependencies]
 libc = "0.2"
diff --git a/METADATA b/METADATA
index cc7e9e7..ba00fd2 100644
--- a/METADATA
+++ b/METADATA
@@ -1,5 +1,5 @@
 name: "libloading"
-description: "A safer binding to platform\'s dynamic library loading utilities."
+description: "A safer binding to platform\'s dynamic library loading utilities"
 third_party {
   url {
     type: HOMEPAGE
@@ -7,13 +7,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/libloading/libloading-0.6.3.crate"
+    value: "https://static.crates.io/crates/libloading/libloading-0.6.5.crate"
   }
-  version: "0.6.3"
+  version: "0.6.5"
   license_type: NOTICE
   last_upgrade_date {
     year: 2020
-    month: 8
-    day: 24
+    month: 10
+    day: 26
   }
 }
diff --git a/MODULE_LICENSE_BSD_LIKE b/MODULE_LICENSE_ISC
similarity index 100%
rename from MODULE_LICENSE_BSD_LIKE
rename to MODULE_LICENSE_ISC
diff --git a/TEST_MAPPING b/TEST_MAPPING
new file mode 100644
index 0000000..7bc6ed2
--- /dev/null
+++ b/TEST_MAPPING
@@ -0,0 +1,12 @@
+// Generated by cargo2android.py for tests in Android.bp
+{
+  "presubmit": [
+    {
+      "host": true,
+      "name": "libsqlite3-sys_host_test_src_lib"
+    },
+    {
+      "name": "libsqlite3-sys_device_test_src_lib"
+    }
+  ]
+}
diff --git a/build.rs b/build.rs
deleted file mode 100644
index e217f80..0000000
--- a/build.rs
+++ /dev/null
@@ -1,70 +0,0 @@
-use std::io::Write;
-use std::env;
-
-fn dlerror_is_mtsafe(target_os: &str) {
-    match target_os {
-        // Confirmed MT-safe:
-        "linux"
-        | "android"
-        | "openbsd"
-        | "macos"
-        | "ios"
-        | "solaris"
-        | "illumos"
-        | "redox"
-        | "fuchsia" => {
-            println!("cargo:rustc-cfg=mtsafe_dlerror");
-        }
-        // Confirmed not MT-safe:
-        "freebsd"
-        | "dragonfly"
-        | "netbsd"
-        | "bitrig"
-        | "haiku" => {}
-        // Unknown:
-        _ => {}
-    }
-}
-
-fn link_libraries(target_os: &str) {
-    match target_os {
-        "linux" | "android" => println!("cargo:rustc-link-lib=dl"),
-        "freebsd" | "dragonfly" => println!("cargo:rustc-link-lib=c"),
-        // netbsd claims dl* will be available to any dynamically linked binary, but I haven’t
-        // found any libraries that have to be linked to on other platforms.
-        // What happens if the executable is not linked up dynamically?
-        "openbsd" | "bitrig" | "netbsd" | "macos" | "ios" => {}
-        "solaris" | "illumos" => {}
-        "haiku" => {}
-        "redox" => {}
-        "fuchsia" => {}
-        // dependencies come with winapi
-        "windows" => {}
-        tos => {
-            writeln!(::std::io::stderr(),
-                     "Building for an unknown target_os=`{:?}`!\nPlease report an issue ",
-                     tos).expect("could not report the error");
-            ::std::process::exit(0xfc);
-        }
-    }
-}
-
-fn main() {
-    match env::var("CARGO_CFG_TARGET_OS") {
-        Ok(target_os) => {
-            dlerror_is_mtsafe(&target_os);
-            link_libraries(&target_os);
-        }
-        Err(e) => {
-            writeln!(::std::io::stderr(),
-                     "Unable to get target_os=`{}`!", e).expect("could not report the error");
-            ::std::process::exit(0xfd);
-        }
-    }
-
-    // For tests
-    println!(
-        "cargo:rustc-env=LIBLOADING_TEST_TARGET={}",
-        std::env::var("TARGET").expect("$TARGET is not set")
-    );
-}
diff --git a/src/changelog.rs b/src/changelog.rs
index 01c25ec..7d058b8 100644
--- a/src/changelog.rs
+++ b/src/changelog.rs
@@ -3,6 +3,17 @@
 // TODO: for the next breaking release rename `Error::LoadLibraryW` to `Error::LoadLibraryExW`.
 // TODO: for the next breaking release use `RTLD_LAZY | RTLD_LOCAL` by default  on unix.
 
+/// Release 0.6.5 (2020-10-23)
+///
+/// * Upgrade cfg-if 0.1 to 1.0
+pub mod r0_6_5 {}
+
+/// Release 0.6.4 (2020-10-10)
+///
+/// * Remove use of `build.rs` making it easier to build `libloading` without cargo. It also
+/// almost halves the build time of this crate.
+pub mod r0_6_4 {}
+
 /// Release 0.6.3 (2020-08-22)
 ///
 /// * Improve documentation, allowing to view all of the os-specific functionality from
@@ -13,6 +24,7 @@
 ///
 /// [`os::windows::Library::this`]: crate::os::windows::Library::this
 /// [`library_filename`]: crate::library_filename
+pub mod r0_6_3 {}
 
 /// Release 0.6.2 (2020-05-06)
 ///
diff --git a/src/os/unix/consts.rs b/src/os/unix/consts.rs
index 823155e..2c18f95 100644
--- a/src/os/unix/consts.rs
+++ b/src/os/unix/consts.rs
@@ -43,7 +43,7 @@
 /// any other executable object file. This mode of operation is most appropriate for e.g. plugins.
 pub const RTLD_LOCAL: c_int = posix::RTLD_LOCAL;
 
-#[cfg(docsrs)]
+#[cfg(all(docsrs, not(unix)))]
 mod posix {
     use super::c_int;
     pub(super) const RTLD_LAZY: c_int = !0;
@@ -52,7 +52,7 @@
     pub(super) const RTLD_LOCAL: c_int = !0;
 }
 
-#[cfg(not(docsrs))]
+#[cfg(any(not(docsrs), unix))]
 mod posix {
     extern crate cfg_if;
     use self::cfg_if::cfg_if;
diff --git a/src/os/unix/mod.rs b/src/os/unix/mod.rs
index 785c58f..71d2c5f 100644
--- a/src/os/unix/mod.rs
+++ b/src/os/unix/mod.rs
@@ -220,10 +220,25 @@
     /// care about, consider using the [`Library::get_singlethreaded`] call.
     #[inline(always)]
     pub unsafe fn get<T>(&self, symbol: &[u8]) -> Result<Symbol<T>, crate::Error> {
-        #[cfg(mtsafe_dlerror)]
-        { self.get_singlethreaded(symbol) }
-        #[cfg(not(mtsafe_dlerror))]
-        { self.get_impl(symbol, || Err(crate::Error::DlSymUnknown)) }
+        extern crate cfg_if;
+        cfg_if::cfg_if! {
+            // These targets are known to have MT-safe `dlerror`.
+            if #[cfg(any(
+                target_os = "linux",
+                target_os = "android",
+                target_os = "openbsd",
+                target_os = "macos",
+                target_os = "ios",
+                target_os = "solaris",
+                target_os = "illumos",
+                target_os = "redox",
+                target_os = "fuchsia"
+            ))] {
+                self.get_singlethreaded(symbol)
+            } else {
+                self.get_impl(symbol, || Err(crate::Error::DlSymUnknown))
+            }
+        }
     }
 
     /// Get a pointer to function or static variable by symbol name.
@@ -387,6 +402,8 @@
 }
 
 // Platform specific things
+#[cfg_attr(any(target_os = "linux", target_os = "android"), link(name="dl"))]
+#[cfg_attr(any(target_os = "freebsd", target_os = "dragonfly"), link(name="c"))]
 extern {
     fn dlopen(filename: *const raw::c_char, flags: raw::c_int) -> *mut raw::c_void;
     fn dlclose(handle: *mut raw::c_void) -> raw::c_int;
diff --git a/tests/functions.rs b/tests/functions.rs
index b642478..20ac3c1 100644
--- a/tests/functions.rs
+++ b/tests/functions.rs
@@ -4,24 +4,27 @@
 extern crate libloading;
 use libloading::{Symbol, Library};
 
-const LIBPATH: &'static str = concat!(env!("OUT_DIR"), "/libtest_helpers.module");
+const LIBPATH: &'static str = "target/libtest_helpers.module";
 
 fn make_helpers() {
     static ONCE: ::std::sync::Once = ::std::sync::Once::new();
     ONCE.call_once(|| {
-        let rustc = option_env!("RUSTC").unwrap_or_else(|| { "rustc".into() });
+        let rustc = std::env::var_os("RUSTC").unwrap_or_else(|| { "rustc".into() });
         let mut cmd = ::std::process::Command::new(rustc);
         cmd
             .arg("src/test_helpers.rs")
             .arg("-o")
-            .arg(LIBPATH)
-            .arg("--target")
-            .arg(env!("LIBLOADING_TEST_TARGET"))
-            .arg("-O");
-
-        cmd
-            .output()
-            .expect("could not compile the test helpers!");
+            .arg(LIBPATH);
+        if let Some(target) = std::env::var_os("TARGET") {
+            cmd.arg("--target").arg(target);
+        } else {
+            eprintln!("WARNING: $TARGET NOT SPECIFIED! BUILDING HELPER MODULE FOR NATIVE TARGET.");
+        }
+        assert!(cmd
+            .status()
+            .expect("could not compile the test helpers!")
+            .success()
+        );
     });
 }
 
@@ -67,7 +70,7 @@
 
 #[test]
 fn wrong_name_fails() {
-    Library::new(concat!(env!("OUT_DIR"), "/libtest_help")).err().unwrap();
+    Library::new("target/this_location_is_definitely_non existent:^~").err().unwrap();
 }
 
 #[test]