Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dockerfile with Android SDK #50

Closed
oxr463 opened this issue Aug 8, 2021 · 8 comments · Fixed by #53
Closed

Update Dockerfile with Android SDK #50

oxr463 opened this issue Aug 8, 2021 · 8 comments · Fixed by #53
Assignees
Milestone

Comments

@oxr463
Copy link
Contributor

oxr463 commented Aug 8, 2021

See: https://github.com/mindrunner/docker-android-sdk

@oxr463 oxr463 added this to the v0.0.1 milestone Aug 8, 2021
@oxr463 oxr463 self-assigned this Aug 8, 2021
@oxr463
Copy link
Contributor Author

oxr463 commented Aug 8, 2021

See also: #48 (comment)

@oxr463

This comment has been minimized.

@imlk0
Copy link
Collaborator

imlk0 commented Aug 9, 2021

@oxr463

Now we should be able to compile directly to the arm-linux-androideabi target.

Since we have already specified the linker name in .cargo/config.toml:

[target.arm-linux-androideabi]
linker = "armv7a-linux-androideabi21-clang"

[target.aarch64-linux-android]
linker = "aarch64-linux-android21-clang"

Just add <path-to-ndk-dir>/toolchains/llvm/prebuilt/linux-x86_64/bin/ into PATH, before you start compiling.

Then, install new rust target:

rustup target add arm-linux-androideabi

Start building with:

CARGO_BUILD_TARGET=arm-linux-androideabi cargo make build

It should work

@oxr463
Copy link
Contributor Author

oxr463 commented Aug 15, 2021

Maybe you can verify why this is happening, but I ran into this issue:

docker-compose run proot-rs-sdk /bin/sh
/usr/src/proot-rs # CARGO_BUILD_TARGET=arm-linux-androideabi cargo make build
info: syncing channel updates for 'nightly-2021-03-24-x86_64-unknown-linux-musl'
info: latest update on 2021-03-24, rust version 1.53.0-nightly (673d0db5e 2021-03-23)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: using up to 500.0 MiB of RAM to unpack components
info: installing component 'clippy'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustfmt'
[cargo-make] INFO - cargo make 0.35.0
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: build
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Running Task: build-loader
  Downloaded rlibc v1.0.0
  Downloaded 1 crate (7.0 KB) in 0.20s
   Compiling rlibc v1.0.0
   Compiling sc v0.2.4 (https://github.com/KB5201314/syscall.rs.git?rev=cf49872#cf498721)
error[E0463]: can't find crate for `core`
  |
  = note: the `arm-linux-androideabi` target may not be installed

error[E0463]: can't find crate for `core`
  |
  = note: the `arm-linux-androideabi` target may not be installed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: could not compile `rlibc`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
[cargo-make] ERROR - Error while executing command, exit code: 101
[cargo-make] WARN - Build Failed.

The weird part is that I re-ran this command:

rustup target add arm-linux-androideabi
info: downloading component 'rust-std' for 'arm-linux-androideabi'
info: installing component 'rust-std' for 'arm-linux-androideabi'
info: using up to 500.0 MiB of RAM to unpack components

And then it successfully built for me:

CARGO_BUILD_TARGET=arm-linux-androideabi cargo make build
[cargo-make] INFO - cargo make 0.35.0
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: build
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Running Task: build-loader
   Compiling sc v0.2.4 (https://github.com/KB5201314/syscall.rs.git?rev=cf49872#cf498721)
   Compiling rlibc v1.0.0
   Compiling loader-shim v0.1.0 (/usr/src/proot-rs/loader-shim)
    Finished dev [unoptimized + debuginfo] target(s) in 0.84s
[cargo-make] INFO - Running Task: copy-loader
[cargo-make] INFO - Running Task: build
   Compiling libc v0.2.90
   Compiling memchr v2.3.4
   Compiling bitflags v1.2.1
   Compiling log v0.4.14
   Compiling cfg-if v1.0.0
   Compiling unicode-width v0.1.8
   Compiling regex-syntax v0.6.23
   Compiling vec_map v0.8.2
   Compiling sc v0.2.4 (https://github.com/KB5201314/syscall.rs.git?rev=cf49872#cf498721)
   Compiling strsim v0.8.0
   Compiling ansi_term v0.11.0
   Compiling humantime v2.1.0
   Compiling termcolor v1.1.2
   Compiling byteorder v1.4.3
   Compiling lazy_static v1.4.0
   Compiling textwrap v0.11.0
   Compiling loader-shim v0.1.0 (/usr/src/proot-rs/loader-shim)
   Compiling aho-corasick v0.7.15
   Compiling regex v1.4.5
   Compiling atty v0.2.14
   Compiling nix v0.20.0
   Compiling clap v2.33.3
   Compiling env_logger v0.8.3
   Compiling proot-rs v0.1.0 (/usr/src/proot-rs/proot-rs)
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
 --> proot-rs/src/main.rs:3:12
  |
3 | #![feature(specialization)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
  = help: consider using `min_specialization` instead, which is more stable and complete

warning: unused import: `crate::errors::*`
 --> proot-rs/src/kernel/standard/uname.rs:1:5
  |
1 | use crate::errors::*;
  |     ^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: associated function is never used: `set_glue_type`
   --> proot-rs/src/filesystem/fs.rs:200:12
    |
200 |     pub fn set_glue_type(&mut self, mode: Mode) {
    |            ^^^^^^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: constant is never used: `ET_REL`
  --> proot-rs/src/kernel/execve/binfmt/elf.rs:14:1
   |
14 | const ET_REL: u16 = 1;
   | ^^^^^^^^^^^^^^^^^^^^^^

warning: constant is never used: `ET_CORE`
  --> proot-rs/src/kernel/execve/binfmt/elf.rs:17:1
   |
17 | const ET_CORE: u16 = 4;
   | ^^^^^^^^^^^^^^^^^^^^^^^

warning: constant is never used: `PT_DYNAMIC`
  --> proot-rs/src/kernel/execve/binfmt/elf.rs:19:1
   |
19 | pub const PT_DYNAMIC: u32 = 2;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: struct is never constructed: `DynamicEntry`
  --> proot-rs/src/kernel/execve/binfmt/elf.rs:28:12
   |
28 | pub struct DynamicEntry<TSigned, TUnsigned> {
   |            ^^^^^^^^^^^^

warning: enum is never used: `DynamicType`
  --> proot-rs/src/kernel/execve/binfmt/elf.rs:33:10
   |
33 | pub enum DynamicType {
   |          ^^^^^^^^^^^

warning: 8 warnings emitted

    Finished dev [unoptimized + debuginfo] target(s) in 9.14s
proot-rs:       /usr/src/proot-rs/target/arm-linux-androideabi/debug/proot-rs
loader-shim:    /usr/src/proot-rs/target/arm-linux-androideabi/debug/loader-shim
[cargo-make] INFO - Build Done in 10.18 seconds.

oxr463 added a commit that referenced this issue Aug 15, 2021
@oxr463 oxr463 changed the title Add Dockerfile for Android SDK Update Dockerfile with Android SDK Aug 15, 2021
@imlk0
Copy link
Collaborator

imlk0 commented Aug 15, 2021

I don't see any problem with this.

On your first build, the error message reported is:

error[E0463]: can't find crate for `core`
  |
  = note: the `arm-linux-androideabi` target may not be installed

error[E0463]: can't find crate for `core`
  |
  = note: the `arm-linux-androideabi` target may not be installed

This means that you may not have the arm-linux-androideabi target installed. By running "rustup target add arm-linux-androideabi", it is installed in your environment. So when you build again it will succeed

@oxr463
Copy link
Contributor Author

oxr463 commented Aug 15, 2021

I don't see any problem with this.

On your first build, the error message reported is:

error[E0463]: can't find crate for `core`
  |
  = note: the `arm-linux-androideabi` ta需要rget may not be installed

error[E0463]: can't find crate for `core`
  |
  = note: the `arm-linux-androideabi` target may not be installed

This means that you may not have the arm-linux-androideabi target installed. By running "rustup target add arm-linux-androideabi", it is installed in your environment. So when you build again it will succeed

But the Dockerfile already added it? So I basically need to do it twice.

@imlk0
Copy link
Collaborator

imlk0 commented Aug 16, 2021

Oh, I see, I know the reasons.

To explain this, I would like to first introduce that rust allows multiple toolchains to exist in the system. and this can be checked with rustup show:

/usr/src/proot-rs # rustup show
Default host: x86_64-unknown-linux-musl
rustup home:  /root/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-musl (default)
nightly-2021-03-24-x86_64-unknown-linux-musl

active toolchain
----------------

nightly-2021-03-24-x86_64-unknown-linux-musl (overridden by '/usr/src/proot-rs/rust-toolchain')
rustc 1.53.0-nightly (673d0db5e 2021-03-23)

By default the toolchain to be used is the stable version. But if there is a file named rust-toolchain in the current directory, it will be overridden to use the specified toolchain version. In our project, it's version is nightly-2021-03-24.

Here is a part of the Dockerfile:

RUN rustup-init -y && \
    rustup toolchain install stable && \
    rustup target add arm-linux-androideabi && \
    cargo +stable install --force cargo-make

WORKDIR /usr/src/proot-rs
COPY . /usr/src/proot-rs

CMD ["cargo", "make", "build"]

Here, the line

rustup target add arm-linux-androideabi

comes before

COPY . /usr/src/proot-rs

This means that we are installing a new target arm-linux-androideabi for the default toolchain (stable version).

But our project is actually using the nightly-2021-03-24 toolchain, for which we have not yet installed the target arm-linux-androideabi.

@imlk0
Copy link
Collaborator

imlk0 commented Aug 16, 2021

I have added a patch ffdec87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants