Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 30, 2024
1 parent 77a7e01 commit 8ce3998
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 73 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,18 @@ jobs:
- uses: taiki-e/checkout-action@v1
- uses: taiki-e/github-actions/install-rust@nightly
- run: |
sudo apt-get -o Acquire::Retries=10 -qq update && sudo apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends \
retry() {
for i in {1..10}; do
if "$@"; then
return 0
else
sleep "${i}"
fi
done
"$@"
}
retry sudo apt-get -o Acquire::Retries=10 -qq update
retry sudo apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends \
gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabi \
gcc-i686-linux-gnu \
Expand All @@ -736,6 +747,14 @@ jobs:
gcc-sparc64-linux-gnu \
gcc-x86-64-linux-gnux32 \
gettext
retry docker create --name gcc-csky-linux-gnuabiv2 "ghcr.io/taiki-e/rust-cross-toolchain:csky-unknown-linux-gnuabiv2-dev-amd64"
docker cp -- "gcc-csky-linux-gnuabiv2:/csky-unknown-linux-gnuabiv2" gcc-csky-linux-gnuabiv2
docker rm -f -- gcc-csky-linux-gnuabiv2 >/dev/null
printf '%s\n' "$(pwd)/gcc-csky-linux-gnuabiv2/bin" >>"${GITHUB_PATH}"
retry docker create --name gcc-loongarch64-linux-gnu "ghcr.io/taiki-e/rust-cross-toolchain:loongarch64-unknown-linux-gnu-dev-amd64"
docker cp -- "gcc-loongarch64-linux-gnu:/loongarch64-unknown-linux-gnu" gcc-loongarch64-linux-gnu
docker rm -f -- gcc-loongarch64-linux-gnu >/dev/null
printf '%s\n' "$(pwd)/gcc-loongarch64-linux-gnu/bin" >>"${GITHUB_PATH}"
- run: tools/no_atomic.sh
- run: tools/gen.sh
- id: diff
Expand Down
14 changes: 14 additions & 0 deletions tests/helper/src/gen/sys/csky_linux_gnuabiv2/dlfcn.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/helper/src/gen/sys/csky_linux_gnuabiv2/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/helper/src/gen/sys/csky_linux_gnuabiv2/sched.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/helper/src/gen/sys/csky_linux_gnuabiv2/sys_prctl.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/helper/src/gen/sys/csky_linux_gnuabiv2/sys_rseq.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions tests/helper/src/gen/sys/loongarch64_linux_gnu/dlfcn.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/helper/src/gen/sys/loongarch64_linux_gnu/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/helper/src/gen/sys/loongarch64_linux_gnu/sched.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/helper/src/gen/sys/loongarch64_linux_gnu/sys_prctl.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/helper/src/gen/sys/loongarch64_linux_gnu/sys_rseq.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

148 changes: 76 additions & 72 deletions tools/codegen/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
// See also https://github.com/rust-lang/libc/issues/570.

use std::{ffi::OsStr, process::Command};
use std::process::Command;

use camino::{Utf8Path, Utf8PathBuf};
use duct::cmd;
Expand Down Expand Up @@ -653,8 +653,8 @@ struct Header {
}

pub(crate) fn gen() {
if !cfg!(target_os = "linux") {
eprintln!("warning: codegen is only fully supported on Linux");
if !cfg!(all(target_os = "linux", target_arch = "x86_64")) {
eprintln!("warning: codegen is only fully supported on x86_64 Linux");
// TODO
return;
}
Expand Down Expand Up @@ -711,14 +711,14 @@ pub(crate) fn gen() {
if !header.env.is_empty() && !header.env.contains(&target.env) {
continue;
}
if target.os == linux
&& target.env == gnu
&& matches!(target.arch, csky | loongarch64)
&& matches!(header.path, "dlfcn.h" | "sched.h" | "sys/prctl.h" | "sys/rseq.h")
{
// TODO: glibc
continue;
}
// if target.os == linux
// && target.env == gnu
// && matches!(target.arch, csky | loongarch64)
// && matches!(header.path, "dlfcn.h" | "sched.h" | "sys/prctl.h" | "sys/rseq.h")
// {
// // TODO: glibc
// continue;
// }
if target.os == linux
&& target.env == gnu
&& target.arch == aarch64
Expand Down Expand Up @@ -1138,7 +1138,7 @@ fn download_headers(target: &TargetSpec, download_dir: &Utf8Path) -> Utf8PathBuf
clone(download_dir, GLIBC_REPO, None, &[]);
}
let glibc_src_dir = &glibc_dir(target, &src_dir);
let mut headers_dir = &libc_headers_dir(target, &src_dir);
let headers_dir = &libc_headers_dir(target, &src_dir);
if !headers_dir.exists() {
let (cc, cflags) = &match &*target.llvm_target {
"aarch64_be-unknown-linux-gnu" => {
Expand Down Expand Up @@ -1166,6 +1166,9 @@ fn download_headers(target: &TargetSpec, download_dir: &Utf8Path) -> Utf8PathBuf
"sparc-unknown-linux-gnu" => {
("sparc64-linux-gnu-gcc".to_owned(), " -m32 -mv8plus")
}
_ if target.arch == loongarch64 => {
(format!("{}-gcc", target.llvm_target), "")
}
_ => (format!("{}-gcc", target.llvm_target.replace("-unknown", "")), ""),
};
if cmd!(cc, "--version").stdout_capture().stderr_capture().run().is_ok() {
Expand Down Expand Up @@ -1194,66 +1197,67 @@ fn download_headers(target: &TargetSpec, download_dir: &Utf8Path) -> Utf8PathBuf
.unwrap();
fs::write(headers_dir.join("include/gnu/stubs.h"), "").unwrap();
} else {
eprintln!("warning: {cc} not found");
let glibc_arch = glibc_arch(target);
let sysdeps_dir = &glibc_src_dir.join("sysdeps");
let sysdeps_arch_dir = &sysdeps_dir.join(glibc_arch);
match target.arch {
s390x => {
let file = "bits/hwcap.h";
let src = sysdeps_dir.join("unix/sysv/linux/s390").join(file);
let dst = sysdeps_arch_dir.join(file);
symlink(src, dst).unwrap();
}
_ => {}
}
let mut parent_arch = glibc_arch;
let mut sources = vec![];
while let Some((p, _)) = parent_arch.rsplit_once('/') {
parent_arch = p;
sources.push(sysdeps_dir.join(parent_arch));
}
match &*target.target_pointer_width {
// TODO: check
"64" => sources.push(sysdeps_dir.join("wordsize-64")),
"32" => sources.push(sysdeps_dir.join("wordsize-32")),
_ => todo!("{target:?}"),
}
sources.push(sysdeps_dir.join("generic"));
for src in &sources {
for e in fs::read_dir(src).unwrap().filter_map(Result::ok) {
let src = &e.path();
if src.is_dir() {
let dir = src.file_name().unwrap().to_str().unwrap();
let dst_dir = &sysdeps_arch_dir.join(dir);
for e in fs::read_dir(src).unwrap().filter_map(Result::ok) {
let src = &e.path();
if src.extension() != Some(OsStr::new("h")) {
continue;
}
let file = src.file_name().unwrap().to_str().unwrap();
if !dst_dir.exists() {
fs::create_dir_all(dst_dir).unwrap();
}
let dst = dst_dir.join(file);
if !dst.exists() {
symlink(src, dst).unwrap();
}
}
continue;
}
if src.extension() != Some(OsStr::new("h")) {
continue;
}
let file = src.file_name().unwrap().to_str().unwrap();
let dst = sysdeps_arch_dir.join(file);
if !dst.exists() {
symlink(src, dst).unwrap();
}
}
}
patch(target, &src_dir);
headers_dir = glibc_src_dir;
panic!("{} not found", cc);
// eprintln!("warning: {cc} not found");
// let glibc_arch = glibc_arch(target);
// let sysdeps_dir = &glibc_src_dir.join("sysdeps");
// let sysdeps_arch_dir = &sysdeps_dir.join(glibc_arch);
// match target.arch {
// s390x => {
// let file = "bits/hwcap.h";
// let src = sysdeps_dir.join("unix/sysv/linux/s390").join(file);
// let dst = sysdeps_arch_dir.join(file);
// symlink(src, dst).unwrap();
// }
// _ => {}
// }
// let mut parent_arch = glibc_arch;
// let mut sources = vec![];
// while let Some((p, _)) = parent_arch.rsplit_once('/') {
// parent_arch = p;
// sources.push(sysdeps_dir.join(parent_arch));
// }
// match &*target.target_pointer_width {
// // TODO: check
// "64" => sources.push(sysdeps_dir.join("wordsize-64")),
// "32" => sources.push(sysdeps_dir.join("wordsize-32")),
// _ => todo!("{target:?}"),
// }
// sources.push(sysdeps_dir.join("generic"));
// for src in &sources {
// for e in fs::read_dir(src).unwrap().filter_map(Result::ok) {
// let src = &e.path();
// if src.is_dir() {
// let dir = src.file_name().unwrap().to_str().unwrap();
// let dst_dir = &sysdeps_arch_dir.join(dir);
// for e in fs::read_dir(src).unwrap().filter_map(Result::ok) {
// let src = &e.path();
// if src.extension() != Some(OsStr::new("h")) {
// continue;
// }
// let file = src.file_name().unwrap().to_str().unwrap();
// if !dst_dir.exists() {
// fs::create_dir_all(dst_dir).unwrap();
// }
// let dst = dst_dir.join(file);
// if !dst.exists() {
// symlink(src, dst).unwrap();
// }
// }
// continue;
// }
// if src.extension() != Some(OsStr::new("h")) {
// continue;
// }
// let file = src.file_name().unwrap().to_str().unwrap();
// let dst = sysdeps_arch_dir.join(file);
// if !dst.exists() {
// symlink(src, dst).unwrap();
// }
// }
// }
// patch(target, &src_dir);
// headers_dir = glibc_src_dir;
}
}
fs::write(
Expand Down

0 comments on commit 8ce3998

Please sign in to comment.