rust plugin: make libc configurable #1382

Closed
wants to merge 11 commits into
from

Conversation

4 participants
Collaborator

kalikiana commented Jun 27, 2017

rust supports musl as a libc alternative to glibc and it's especially interesting for static linking.

snapcraft/tests/matchers.py
-
- def __init__(self, expected_arch):
- self._expected_arch = expected_arch
+class HasMagic:
@elopio

elopio Jul 4, 2017

Member

Can you please explain this in a comment in the source code?
I'm totally confused because it's called magic.

Ideally, you could find a better name for this that's not the name of the module, which is pretty bad. Something like HasType? HasMIMEType?

@@ -101,6 +101,18 @@ def test_cross_compiling(self):
binary = os.path.join(self.parts_dir, 'rust-hello', 'install', 'bin',
'rust-hello')
self.assertThat(binary, HasArchitecture('aarch64'))
+ self.assertThat(binary, HasLinkage('dynamically linked'))
+
+ def test_cross_compiling_musl(self):
@elopio

elopio Jul 4, 2017

Member

Why no integration test for normal compillation?

@kalikiana

kalikiana Sep 11, 2017

Collaborator

I figured the existing ones are enough... I added the linkage assertion to the existing first test now.

@kalikiana

kalikiana Sep 21, 2017

Collaborator

Done

@@ -0,0 +1,14 @@
+name: rust-musl
@elopio

elopio Jul 4, 2017

Member

what would you think of using the basic rust yaml, and in the test setup append libc: musl, instead of adding a new snap?

@kalikiana

kalikiana Sep 11, 2017

Collaborator

I guess now that you've also proposed new fixtures, this can be refactored once this lands.

snapcraft/tests/matchers.py
+
+
+class HasLinkage(HasMagic):
+ """Match if the file was built for the expected architecture"""
@elopio

elopio Jul 4, 2017

Member

This comment has to be updated.

@kalikiana kalikiana self-assigned this Jul 19, 2017

@kalikiana kalikiana changed the title from rust: Make libc configurable to rust: make libc configurable Aug 8, 2017

@kalikiana kalikiana changed the title from rust: make libc configurable to rust plugin: make libc configurable Aug 8, 2017

@sergiusens sergiusens added this to In Progress (Implementation) in 17.10 Aug 8, 2017

@sergiusens sergiusens moved this from In Progress (Implementation) to Container builds in 17.10 Aug 9, 2017

@kalikiana kalikiana moved this from Container builds to Cross compilation in 17.10 Sep 8, 2017

This is looking pretty good, but in addition to Leo's suggestions, I have a few more.

-
- def __init__(self, expected_arch):
- self._expected_arch = expected_arch
+class HasBinaryFileHeader:
@kyrofa

kyrofa Sep 8, 2017

Member

This should probably start with an underscore seeing that it can't be used standalone.

@kalikiana

kalikiana Sep 11, 2017

Collaborator

I changed it so it can be used on its own instead. Also made the subclasses smaller.

snapcraft/tests/plugins/test_rust.py
@@ -46,6 +48,7 @@ class Options:
rust_features = []
rust_revision = ''
rust_channel = ''
+ libc = self.libc if hasattr(self, 'libc') else 'gnu'
@kyrofa

kyrofa Sep 8, 2017

Member

Perhaps libc = getattr(self, 'libc', 'gnu') would be better.

kyrofa approved these changes Sep 19, 2017

This now looks good to me, thanks @kalikiana!

Collaborator

kalikiana commented Sep 21, 2017

Apologies for making a mess... I rebased, which locally got me a clean diff and commits on top of master. Can't see how to fix it for GitHub, though.

@kalikiana kalikiana changed the base branch from rust-musl to master Sep 21, 2017

@@ -103,6 +107,24 @@ def test_cross_compiling(self):
binary = os.path.join(self.parts_dir, 'rust-hello', 'install', 'bin',
'rust-hello')
self.assertThat(binary, HasArchitecture('aarch64'))
+ self.assertThat(binary, HasLinkage('dynamically linked'))
@elopio

elopio Sep 22, 2017

Member

It seems to me that the matchers would be clearer called like IsDynamicallyLinked() and IsStaticallyLinked()

@kalikiana

kalikiana Sep 22, 2017

Collaborator

To my mind HasLinkage is consistent with HasArchitecture in that it's not hiding the basic string-parsing nature of the matcher... but yeah, I added subclasses as per your suggestion now.

@@ -31,6 +31,9 @@
- rust-features
(list of strings)
Features used to build optional dependencies
+ - libc:
+ (string; default: gnu)
+ Libc to link against. Valid options are: gnu (glibc) and musl
@elopio

elopio Sep 22, 2017

Member

I don't have much clue about this, but why call it gnu instead of glibc?

@kalikiana

kalikiana Sep 22, 2017

Collaborator

gnu and musl are the names of the toolchains. I mention glibc there to clarify what it means.

Member

elopio commented Sep 22, 2017

I have a few comments, but no complaints here.
Ideally, this would be reviewed also by somebody who knows rust and musl.

What do you think of my suggestions for the matchers without args? I'll give you a +1 now, but I think it would be clearer that way.

Collaborator

sergiusens commented Oct 9, 2017

stale

@sergiusens sergiusens closed this Oct 9, 2017

Collaborator

kalikiana commented Oct 10, 2017

Why did you close this? I merged master on Thursday to try and get past the false negatives and it had positive reviews.

@kalikiana kalikiana reopened this Oct 11, 2017

Collaborator

kalikiana commented Oct 11, 2017

False negative... TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

Member

kyrofa commented Oct 11, 2017

@kalikiana we can't merge something with false negatives, because it prevents the following tests from running. I know it's annoying, but keep retrying.

Collaborator

kalikiana commented Oct 12, 2017

test_rust_plugin.RustPluginTestCase.test_cross_compiling_musl ... The job exceeded the maximum time limit for jobs, and has been terminated.

Closing for now, need to investigate how to make this more reliable on Travis.

@kalikiana kalikiana closed this Oct 12, 2017

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